diff --git a/contrib/dependencies.json b/contrib/dependencies.json index 0a9827f4c..9a10d8e84 100644 --- a/contrib/dependencies.json +++ b/contrib/dependencies.json @@ -86,11 +86,11 @@ }, { "name": "herokuish", - "version": "0.11.3", + "version": "0.11.5", "urls": { - "amd64": "https://github.com/gliderlabs/herokuish/releases/download/v0.11.3/herokuish_0.11.3_linux_x86_64.tgz", - "arm64": "https://github.com/gliderlabs/herokuish/releases/download/v0.11.3/herokuish_0.11.3_linux_x86_64.tgz" + "amd64": "https://github.com/gliderlabs/herokuish/releases/download/v0.11.5/herokuish_0.11.5_linux_x86_64.tgz", + "arm64": "https://github.com/gliderlabs/herokuish/releases/download/v0.11.5/herokuish_0.11.5_linux_x86_64.tgz" } } ] -} \ No newline at end of file +} diff --git a/plugins/buildpacks/Makefile b/plugins/buildpacks/Makefile index aff09a27a..70ed37a5f 100644 --- a/plugins/buildpacks/Makefile +++ b/plugins/buildpacks/Makefile @@ -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 diff --git a/plugins/buildpacks/functions.go b/plugins/buildpacks/functions.go index f3545233e..47acbbc78 100644 --- a/plugins/buildpacks/functions.go +++ b/plugins/buildpacks/functions.go @@ -63,3 +63,32 @@ func validBuildpackURL(buildpack string) (string, error) { return buildpack, fmt.Errorf("Invalid buildpack specified: %v", buildpack) } + +func checkoutBareGitRepo(sourceWorkDir string, branch string) (string, error) { + tmpdir, err := os.MkdirTemp("", "bare-git-checkout") + if err != nil { + return "", fmt.Errorf("Unable to create temporary directory: %s", err.Error()) + } + + args := []string{ + "--git-dir=" + sourceWorkDir, + "--work-tree=" + tmpdir, + "checkout", "-f", + } + + if branch != "" { + args = append(args, branch) + } + + result, err := common.CallExecCommand(common.ExecCommandInput{ + Command: "git", + Args: args, + }) + + if err != nil { + os.RemoveAll(tmpdir) + return "", fmt.Errorf("Unable to checkout bare git repository: %s", result.StderrContents()) + } + + return tmpdir, nil +} diff --git a/plugins/buildpacks/src/commands/commands.go b/plugins/buildpacks/src/commands/commands.go index ecbacbc38..51eb30a15 100644 --- a/plugins/buildpacks/src/commands/commands.go +++ b/plugins/buildpacks/src/commands/commands.go @@ -20,6 +20,7 @@ Additional commands:` helpContent = ` buildpacks:add [--index 1] , Add new app buildpack while inserting into list of buildpacks if necessary buildpacks:clear , Clear all buildpacks set on the app + buildpacks:detect [--branch ], Detect the buildpack for an app (if not specified, the branch flag defaults to the deploy branch) buildpacks:list , List all buildpacks for an app buildpacks:remove , Remove a buildpack set on the app buildpacks:report [] [], Displays a buildpack report for one or more apps diff --git a/plugins/buildpacks/src/subcommands/subcommands.go b/plugins/buildpacks/src/subcommands/subcommands.go index f245238f7..9062e80fa 100644 --- a/plugins/buildpacks/src/subcommands/subcommands.go +++ b/plugins/buildpacks/src/subcommands/subcommands.go @@ -30,6 +30,15 @@ func main() { args.Parse(os.Args[2:]) appName := args.Arg(0) err = buildpacks.CommandClear(appName) + case "detect": + args := flag.NewFlagSet("buildpacks:detect", flag.ExitOnError) + branch := args.String("branch", "", "--branch: the branch to detect against (defaults to the deploy branch)") + args.Parse(os.Args[2:]) + appName := args.Arg(0) + if *branch == "" { + *branch = common.PropertyGet("git", appName, "deploy-branch") + } + err = buildpacks.CommandDetect(appName, *branch) case "list": args := flag.NewFlagSet("buildpacks:list", flag.ExitOnError) args.Parse(os.Args[2:]) diff --git a/plugins/buildpacks/subcommands.go b/plugins/buildpacks/subcommands.go index 329ed6b9f..ffabb5eaa 100644 --- a/plugins/buildpacks/subcommands.go +++ b/plugins/buildpacks/subcommands.go @@ -3,6 +3,7 @@ package buildpacks import ( "errors" "fmt" + "os" "github.com/dokku/dokku/plugins/common" ) @@ -30,6 +31,41 @@ func CommandClear(appName string) error { return common.PropertyDelete("buildpacks", appName, "buildpacks") } +// CommandDetect implements buildpacks:detect +func CommandDetect(appName string, branch string) (err error) { + if err := common.VerifyAppName(appName); err != nil { + return err + } + + workDir := common.AppRoot(appName) + checkedOutDir, err := checkoutBareGitRepo(workDir, branch) + if err != nil { + return err + } + defer func() { + if err := os.RemoveAll(checkedOutDir); err != nil { + common.LogWarn(fmt.Sprintf("Failed to remove temporary directory %s: %v", checkedOutDir, err)) + } + }() + + dockerArgs := []string{ + "run", "--rm", + "-v", fmt.Sprintf("%s:/tmp/app", checkedOutDir), + "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(result.StdoutContents()) + return nil +} + // CommandList implements buildpacks:list func CommandList(appName string) (err error) { if err := common.VerifyAppName(appName); err != nil {