Define and register 'detect' subcommand
This commit is contained in:
committed by
Tasos Maschalidis
parent
929b8444e4
commit
d440b4614d
@@ -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
|
||||
BUILD = commands subcommands triggers
|
||||
PLUGIN_NAME = buildpacks
|
||||
|
||||
@@ -30,6 +30,11 @@ func main() {
|
||||
args.Parse(os.Args[2:])
|
||||
appName := args.Arg(0)
|
||||
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":
|
||||
args := flag.NewFlagSet("buildpacks:list", flag.ExitOnError)
|
||||
args.Parse(os.Args[2:])
|
||||
|
||||
@@ -3,6 +3,7 @@ package buildpacks
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/dokku/dokku/plugins/common"
|
||||
)
|
||||
@@ -30,6 +31,51 @@ func CommandClear(appName string) error {
|
||||
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
|
||||
func CommandList(appName string) (err error) {
|
||||
if err := common.VerifyAppName(appName); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user