Define and register 'detect' subcommand
This commit is contained in:
1 parent
929b8444e4
commit
d440b4614d
3 files changed
+52
-1
No files matched your search
@@ -1,4 +1,4 @@
|
|||||||
SUBCOMMANDS = subcommands/add subcommands/clear subcommands/list subcommands/remove subcommands/report subcommands/set subcommands/set-property
|
SUBCOMMANDS = subcommands/add subcommands/clear subcommands/detect subcommands/list subcommands/remove subcommands/report subcommands/set subcommands/set-property
|
||||||
TRIGGERS = triggers/buildpack-stack-name triggers/install triggers/post-app-clone-setup triggers/post-app-rename-setup triggers/post-delete triggers/post-extract triggers/report
|
TRIGGERS = triggers/buildpack-stack-name triggers/install triggers/post-app-clone-setup triggers/post-app-rename-setup triggers/post-delete triggers/post-extract triggers/report
|
||||||
BUILD = commands subcommands triggers
|
BUILD = commands subcommands triggers
|
||||||
PLUGIN_NAME = buildpacks
|
PLUGIN_NAME = buildpacks
|
||||||
|
|||||||
@@ -30,6 +30,11 @@ func main() {
|
|||||||
args.Parse(os.Args[2:])
|
args.Parse(os.Args[2:])
|
||||||
appName := args.Arg(0)
|
appName := args.Arg(0)
|
||||||
err = buildpacks.CommandClear(appName)
|
err = buildpacks.CommandClear(appName)
|
||||||
|
case "detect":
|
||||||
|
args := flag.NewFlagSet("buildpacks:detect", flag.ExitOnError)
|
||||||
|
args.Parse(os.Args[2:])
|
||||||
|
appName := args.Arg(0)
|
||||||
|
err = buildpacks.CommandDetect(appName)
|
||||||
case "list":
|
case "list":
|
||||||
args := flag.NewFlagSet("buildpacks:list", flag.ExitOnError)
|
args := flag.NewFlagSet("buildpacks:list", flag.ExitOnError)
|
||||||
args.Parse(os.Args[2:])
|
args.Parse(os.Args[2:])
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package buildpacks
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/dokku/dokku/plugins/common"
|
"github.com/dokku/dokku/plugins/common"
|
||||||
)
|
)
|
||||||
@@ -30,6 +31,51 @@ func CommandClear(appName string) error {
|
|||||||
return common.PropertyDelete("buildpacks", appName, "buildpacks")
|
return common.PropertyDelete("buildpacks", appName, "buildpacks")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CommandDetect implements buildpacks:detect
|
||||||
|
func CommandDetect(appName string) error {
|
||||||
|
if err := common.VerifyAppName(appName); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
buildPath := common.AppRoot(appName)
|
||||||
|
if !common.DirectoryExists(buildPath) {
|
||||||
|
return fmt.Errorf("App %s does not exist", appName)
|
||||||
|
}
|
||||||
|
|
||||||
|
workDir := buildPath
|
||||||
|
if isBareGitRepo(buildPath) {
|
||||||
|
checkedOutPath, err := checkoutBareGitRepo(buildPath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
workDir = checkedOutPath
|
||||||
|
defer func() {
|
||||||
|
if err := os.RemoveAll(checkedOutPath); err != nil {
|
||||||
|
common.LogWarn(fmt.Sprintf("Failed to remove temporary directory %s: %v", checkedOutPath, err))
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
|
appRoot := workDir
|
||||||
|
|
||||||
|
dockerArgs := []string{
|
||||||
|
"run", "--rm",
|
||||||
|
"-v", fmt.Sprintf("%s:/tmp/app", appRoot),
|
||||||
|
"gliderlabs/herokuish", "/bin/herokuish", "buildpack", "detect", "/tmp/app",
|
||||||
|
}
|
||||||
|
|
||||||
|
result, err := common.CallExecCommand(common.ExecCommandInput{
|
||||||
|
Command: common.DockerBin(),
|
||||||
|
Args: dockerArgs,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Buildpack detection failed: %s", result.StderrContents())
|
||||||
|
}
|
||||||
|
|
||||||
|
common.LogVerbose(fmt.Sprintf("%s", result.StdoutContents()))
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// CommandList implements buildpacks:list
|
// CommandList implements buildpacks:list
|
||||||
func CommandList(appName string) (err error) {
|
func CommandList(appName string) (err error) {
|
||||||
if err := common.VerifyAppName(appName); err != nil {
|
if err := common.VerifyAppName(appName); err != nil {
|
||||||
|
|||||||
Reference in new issue
Block a user