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
@@ -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