From 46933051b93c8c036427c4318442e0859352c7ce Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sun, 17 Jan 2021 23:10:21 -0500 Subject: [PATCH 01/10] refactor: always return an error from the buildpacks triggers --- plugins/buildpacks/src/triggers/triggers.go | 6 ++--- plugins/buildpacks/triggers.go | 27 ++++++++++----------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/plugins/buildpacks/src/triggers/triggers.go b/plugins/buildpacks/src/triggers/triggers.go index 69da1f213..63534684e 100644 --- a/plugins/buildpacks/src/triggers/triggers.go +++ b/plugins/buildpacks/src/triggers/triggers.go @@ -19,7 +19,7 @@ func main() { var err error switch trigger { case "install": - buildpacks.TriggerInstall() + err = buildpacks.TriggerInstall() case "post-app-clone-setup": oldAppName := flag.Arg(0) newAppName := flag.Arg(1) @@ -30,11 +30,11 @@ func main() { err = buildpacks.TriggerPostAppRenameSetup(oldAppName, newAppName) case "post-delete": appName := flag.Arg(0) - buildpacks.TriggerPostDelete(appName) + err = buildpacks.TriggerPostDelete(appName) case "post-extract": appName := flag.Arg(0) sourceWorkDir := flag.Arg(1) - buildpacks.TriggerPostExtract(appName, sourceWorkDir) + err = buildpacks.TriggerPostExtract(appName, sourceWorkDir) case "report": appName := flag.Arg(0) err = buildpacks.ReportSingleApp(appName, "") diff --git a/plugins/buildpacks/triggers.go b/plugins/buildpacks/triggers.go index 3f0c0f528..293c74dd6 100644 --- a/plugins/buildpacks/triggers.go +++ b/plugins/buildpacks/triggers.go @@ -10,10 +10,12 @@ import ( ) // TriggerInstall runs the install step for the buildpacks plugin -func TriggerInstall() { +func TriggerInstall() error { if err := common.PropertySetup("buildpacks"); err != nil { - common.LogFail(fmt.Sprintf("Unable to install the buildpacks plugin: %s", err.Error())) + return fmt.Errorf("Unable to install the buildpacks plugin: %s", err.Error()) } + + return nil } // TriggerPostAppCloneSetup creates new buildpacks files @@ -40,29 +42,25 @@ func TriggerPostAppRenameSetup(oldAppName string, newAppName string) error { } // TriggerPostDelete destroys the buildpacks property for a given app container -func TriggerPostDelete(appName string) { - err := common.PropertyDestroy("buildpacks", appName) - if err != nil { - common.LogFail(err.Error()) - } +func TriggerPostDelete(appName string) error { + return common.PropertyDestroy("buildpacks", appName) } // TriggerPostExtract writes a .buildpacks file into the app -func TriggerPostExtract(appName string, sourceWorkDir string) { +func TriggerPostExtract(appName string, sourceWorkDir string) error { buildpacks, err := common.PropertyListGet("buildpacks", appName, "buildpacks") if err != nil { - return + return nil } if len(buildpacks) == 0 { - return + return nil } buildpacksPath := filepath.Join(sourceWorkDir, ".buildpacks") file, err := os.OpenFile(buildpacksPath, os.O_RDWR|os.O_TRUNC|os.O_CREATE, 0600) if err != nil { - common.LogFail(fmt.Sprintf("Error writing .buildpacks file: %s", err.Error())) - return + return fmt.Errorf("Error writing .buildpacks file: %s", err.Error()) } w := bufio.NewWriter(file) @@ -71,8 +69,9 @@ func TriggerPostExtract(appName string, sourceWorkDir string) { } if err = w.Flush(); err != nil { - common.LogFail(fmt.Sprintf("Error writing .buildpacks file: %s", err.Error())) - return + return fmt.Errorf("Error writing .buildpacks file: %s", err.Error()) } file.Chmod(0600) + + return nil } From 4c74e0dfbaa593580290d53b26cfb6a5fd5667c0 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sun, 17 Jan 2021 23:11:51 -0500 Subject: [PATCH 02/10] fix: correct docblock --- plugins/logs/logs.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/logs/logs.go b/plugins/logs/logs.go index 780802f47..cf99a32f0 100644 --- a/plugins/logs/logs.go +++ b/plugins/logs/logs.go @@ -10,7 +10,7 @@ import ( const MaxSize = "10m" var ( - // DefaultProperties is a map of all valid ps properties with corresponding default property values + // DefaultProperties is a map of all valid logs properties with corresponding default property values DefaultProperties = map[string]string{ "max-size": "", "vector-sink": "", From bad90b2b1d0f251c7695883364078948fcae3440 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sun, 17 Jan 2021 23:20:16 -0500 Subject: [PATCH 03/10] feat: add ability to manage stacks on an app or global level The previous lever for manipulating this was the DOKKU_IMAGE environment variable. While this is all well and good, it only works for CNB and is yet another `DOKKU_*` environment variable that need not exist. While this does not add support for manipulating the CNB stack just yet, the groundwork is set for the future. Closes #4306 --- docs/configuration/environment-variables.md | 2 +- .../methods/herokuish-buildpacks.md | 40 ++++++++++++++++++- plugins/builder-herokuish/builder-build | 4 +- plugins/buildpacks/Makefile | 4 +- plugins/buildpacks/buildpacks.go | 13 ++++++ plugins/buildpacks/report.go | 32 ++++++++++++++- plugins/buildpacks/src/commands/commands.go | 1 + .../buildpacks/src/subcommands/subcommands.go | 11 +++++ plugins/buildpacks/src/triggers/triggers.go | 3 ++ plugins/buildpacks/subcommands.go | 6 +++ plugins/buildpacks/triggers.go | 26 ++++++++++++ 11 files changed, 134 insertions(+), 8 deletions(-) create mode 100644 plugins/buildpacks/buildpacks.go diff --git a/docs/configuration/environment-variables.md b/docs/configuration/environment-variables.md index b3e9e9030..ab46dece2 100644 --- a/docs/configuration/environment-variables.md +++ b/docs/configuration/environment-variables.md @@ -78,7 +78,7 @@ The following config variables have special meanings and can be set in a variety | Name | Default | How to modify | Description | | ------------------------------ | ------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------- | | `DOKKU_ROOT` | `~dokku` | `/etc/environment` | The root directory where dokku will store application repositories, as well as certain configuration files. | -| `DOKKU_IMAGE` | `gliderlabs/herokuish` | `/etc/environment`
`~dokku/.dokkurc`
`~dokku/.dokkurc/*` | The default image to use when building herokuish containers. | +| `DOKKU_IMAGE` | `gliderlabs/herokuish` | `/etc/environment`
`~dokku/.dokkurc`
`~dokku/.dokkurc/*` | The default image to use when building herokuish containers. Deprecated in favor of using `buildpacks:stack-set` | | `DOKKU_LIB_ROOT` | `/var/lib/dokku` | `/etc/environment`
`~dokku/.dokkurc`
`~dokku/.dokkurc/*` | The directory where plugins, certain data, and general configuration is stored. | | `PLUGIN_PATH` | `$DOKKU_LIB_ROOT/plugins"` | `/etc/environment`
`~dokku/.dokkurc`
`~dokku/.dokkurc/*` | The top-level directory where plugins are stored. | | `PLUGIN_AVAILABLE_PATH` | `$PLUGIN_PATH/available"` | `/etc/environment`
`~dokku/.dokkurc`
`~dokku/.dokkurc/*` | The directory that holds all available plugins, including core. | diff --git a/docs/deployment/methods/herokuish-buildpacks.md b/docs/deployment/methods/herokuish-buildpacks.md index e72d3236c..f9fc632a7 100644 --- a/docs/deployment/methods/herokuish-buildpacks.md +++ b/docs/deployment/methods/herokuish-buildpacks.md @@ -9,6 +9,7 @@ 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 buildpacks:set [--index 1] # Set new app buildpack at a given position defaulting to the first buildpack if no index is specified +buildpacks:stacks-set # Sets the stack of an app ``` > Warning: If using the `buildpacks` plugin, be sure to unset any `BUILDPACK_URL` and remove any such entries from a committed `.env` file. A specified `BUILDPACK_URL` will always override a `.buildpacks` file or the buildpacks plugin. @@ -123,6 +124,32 @@ The `buildpacks:clear` command can be used to clear all configured buildpacks fo dokku buildpacks:clear node-js-app ``` +### Customizing the Buildpack stack + +> New as of 0.23.0 + +The default stack in use by Herokuish buildpacks in Dokku is based on `gliderlabs/herokuish`. Typically, this is installed via an OS package which pulls the requisite Docker image. Users may desire to switch the stack to a custom version, either to update the stack operating system or to customize packages included with the stack. This can be performed via teh `buildpacks:stack-set` command. + +```shell +dokku buildpacks:stack-set node-js-app gliderlabs/herokuish:latest +``` + +The specified stack can also be unset by omitting the name of the stack when calling `buildpacks:stack-set`. + +```shell +dokku buildpacks:stack-set node-js-app +``` + +Finally, stacks can be set or unset globally as a fallback. This will take precedence over a globally set `DOKKU_IMAGE` environment variable (`gliderlabs/herokuish:latest` by default). + +```shell +# set globally +dokku buildpacks:stack-set --global gliderlabs/herokuish:latest + +# unset globally +dokku buildpacks:stack-set --global +``` + ### Displaying buildpack reports for an app You can get a report about the app's buildpacks status using the `buildpacks:report` command: @@ -133,11 +160,20 @@ dokku buildpacks:report ``` =====> node-js-app buildpacks information - Buildpacks list: https://github.com/heroku/heroku-buildpack-nodejs.git + Buildpacks computed stack: gliderlabs/herokuish:v0.5.23-20 + Buildpacks global stack: gliderlabs/herokuish:latest + Buildpacks list: https://github.com/heroku/heroku-buildpack-nodejs.git + Buildpacks stack: gliderlabs/herokuish:v0.5.23-20 =====> python-sample buildpacks information - Buildpacks list: https://github.com/heroku/heroku-buildpack-nodejs.git,https://github.com/heroku/heroku-buildpack-python.git + Buildpacks computed stack: gliderlabs/herokuish:v0.5.23-20 + Buildpacks global stack: gliderlabs/herokuish:latest + Buildpacks list: https://github.com/heroku/heroku-buildpack-nodejs.git,https://github.com/heroku/heroku-buildpack-python.git + Buildpacks stack: =====> ruby-sample buildpacks information + Buildpacks computed stack: gliderlabs/herokuish:v0.5.23-20 + Buildpacks global stack: gliderlabs/herokuish:latest Buildpacks list: + Buildpacks stack: ``` You can run the command for a specific app also. diff --git a/plugins/builder-herokuish/builder-build b/plugins/builder-herokuish/builder-build index b905f7f6c..76be1b392 100755 --- a/plugins/builder-herokuish/builder-build +++ b/plugins/builder-herokuish/builder-build @@ -21,9 +21,9 @@ trigger-builder-herokuish-builder-build() { pushd "$SOURCECODE_WORK_DIR" &>/dev/null - eval "$(config_export app "$APP")" + DOKKU_IMAGE="$(plugn trigger buildpack-stack-name "$APP")" - DOKKU_IMAGE="$(config_get "$APP" DOKKU_IMAGE || echo "$DOKKU_IMAGE")" + eval "$(config_export app "$APP")" plugn trigger builder-create-dokku-image "$BUILDER_TYPE" "$APP" "$SOURCECODE_WORK_DIR" "$DOKKU_IMAGE" NEW_DOKKU_IMAGE=$(plugn trigger builder-dokku-image "$BUILDER_TYPE" "$APP" "$SOURCECODE_WORK_DIR" "$DOKKU_IMAGE") [[ -n "$NEW_DOKKU_IMAGE" ]] && DOKKU_IMAGE="$NEW_DOKKU_IMAGE" diff --git a/plugins/buildpacks/Makefile b/plugins/buildpacks/Makefile index 700601cc5..5abb38ed3 100644 --- a/plugins/buildpacks/Makefile +++ b/plugins/buildpacks/Makefile @@ -1,5 +1,5 @@ -SUBCOMMANDS = subcommands/add subcommands/clear subcommands/list subcommands/remove subcommands/report subcommands/set -TRIGGERS = triggers/install triggers/post-app-clone-setup triggers/post-app-rename-setup triggers/post-delete triggers/post-extract triggers/report +SUBCOMMANDS = subcommands/add subcommands/clear subcommands/list subcommands/remove subcommands/report subcommands/set subcommands/stacks-set +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/buildpacks.go b/plugins/buildpacks/buildpacks.go new file mode 100644 index 000000000..8f4e3b956 --- /dev/null +++ b/plugins/buildpacks/buildpacks.go @@ -0,0 +1,13 @@ +package buildpacks + +var ( + // DefaultProperties is a map of all valid buildpacks properties with corresponding default property values + DefaultProperties = map[string]string{ + "stack": "", + } + + // GlobalProperties is a map of all valid global buildpacks properties + GlobalProperties = map[string]bool{ + "stack": true, + } +) diff --git a/plugins/buildpacks/report.go b/plugins/buildpacks/report.go index ca53623c2..084884b62 100644 --- a/plugins/buildpacks/report.go +++ b/plugins/buildpacks/report.go @@ -1,6 +1,7 @@ package buildpacks import ( + "os" "strings" "github.com/dokku/dokku/plugins/common" @@ -13,7 +14,10 @@ func ReportSingleApp(appName, infoFlag string) error { } flags := map[string]common.ReportFunc{ - "--buildpacks-list": reportList, + "--buildpacks-computed-stack": reportComputedStack, + "--buildpacks-global-stack": reportGlobalStack, + "--buildpacks-list": reportList, + "--buildpacks-stack": reportStack, } flagKeys := []string{} @@ -27,6 +31,28 @@ func ReportSingleApp(appName, infoFlag string) error { return common.ReportSingleApp("buildpacks", appName, infoFlag, infoFlags, flagKeys, trimPrefix, uppercaseFirstCharacter) } +func reportComputedStack(appName string) string { + if stack := common.PropertyGetDefault("buildpacks", appName, "stack", ""); stack != "" { + return stack + } + + if stack := common.PropertyGetDefault("buildpacks", "--global", "stack", ""); stack != "" { + return stack + } + + b, _ := common.PlugnTriggerOutput("config-get", []string{appName, "DOKKU_IMAGE"}...) + if dokkuImage := strings.TrimSpace(string(b[:])); dokkuImage != "" { + common.LogWarn("Deprecated: use buildpacks:stacks-set instead of specifying DOKKU_IMAGE environment variable") + return dokkuImage + } + + return os.Getenv("DOKKU_IMAGE") +} + +func reportGlobalStack(appName string) string { + return common.PropertyGetDefault("buildpacks", "--global", "stack", "") +} + func reportList(appName string) string { buildpacks, err := common.PropertyListGet("buildpacks", appName, "buildpacks") if err != nil { @@ -35,3 +61,7 @@ func reportList(appName string) string { return strings.Join(buildpacks, ",") } + +func reportStack(appName string) string { + return common.PropertyGetDefault("buildpacks", appName, "stack", "") +} diff --git a/plugins/buildpacks/src/commands/commands.go b/plugins/buildpacks/src/commands/commands.go index 5d9cfac57..baf3144a0 100644 --- a/plugins/buildpacks/src/commands/commands.go +++ b/plugins/buildpacks/src/commands/commands.go @@ -24,6 +24,7 @@ Additional commands:` buildpacks:remove , Remove a buildpack set on the app buildpacks:report [] [], Displays a buildpack report for one or more apps buildpacks:set [--index 1] , Set new app buildpack at a given position defaulting to the first buildpack if no index is specified + buildpacks:stacks-set , Sets the stack of an app ` ) diff --git a/plugins/buildpacks/src/subcommands/subcommands.go b/plugins/buildpacks/src/subcommands/subcommands.go index 7bf7a2303..b17a3c5b3 100644 --- a/plugins/buildpacks/src/subcommands/subcommands.go +++ b/plugins/buildpacks/src/subcommands/subcommands.go @@ -57,6 +57,17 @@ func main() { appName := args.Arg(0) buildpack := args.Arg(1) err = buildpacks.CommandSet(appName, buildpack, *index) + case "stacks-set": + args := flag.NewFlagSet("buildpacks:stacks-set", flag.ExitOnError) + global := args.Bool("global", false, "--global: set a global property") + args.Parse(os.Args[2:]) + appName := args.Arg(0) + stack := args.Arg(1) + if *global { + appName = "--global" + stack = args.Arg(0) + } + err = buildpacks.CommandStacksSet(appName, stack) default: common.LogFail(fmt.Sprintf("Invalid plugin subcommand call: %s", subcommand)) } diff --git a/plugins/buildpacks/src/triggers/triggers.go b/plugins/buildpacks/src/triggers/triggers.go index 63534684e..369038897 100644 --- a/plugins/buildpacks/src/triggers/triggers.go +++ b/plugins/buildpacks/src/triggers/triggers.go @@ -18,6 +18,9 @@ func main() { var err error switch trigger { + case "buildpack-stack-name": + appName := flag.Arg(0) + err = buildpacks.TriggerBuildpackStackName(appName) case "install": err = buildpacks.TriggerInstall() case "post-app-clone-setup": diff --git a/plugins/buildpacks/subcommands.go b/plugins/buildpacks/subcommands.go index a6caea1ba..3d1b81c39 100644 --- a/plugins/buildpacks/subcommands.go +++ b/plugins/buildpacks/subcommands.go @@ -138,3 +138,9 @@ func CommandSet(appName string, buildpack string, index int) error { return common.PropertyListSet("buildpacks", appName, "buildpacks", buildpack, index) } + +// CommandStacksSet implements buildpacks:stacks-set +func CommandStacksSet(appName string, stack string) error { + common.CommandPropertySet("buildpacks", appName, "stack", stack, DefaultProperties, GlobalProperties) + return common.PlugnTrigger("post-stack-set", []string{appName, stack}...) +} diff --git a/plugins/buildpacks/triggers.go b/plugins/buildpacks/triggers.go index 293c74dd6..195c41dec 100644 --- a/plugins/buildpacks/triggers.go +++ b/plugins/buildpacks/triggers.go @@ -5,10 +5,36 @@ import ( "fmt" "os" "path/filepath" + "strings" "github.com/dokku/dokku/plugins/common" ) +// TriggerBuildpackStackName echos the stack name for the app +func TriggerBuildpackStackName(appName string) error { + if stack := common.PropertyGetDefault("buildpacks", appName, "stack", ""); stack != "" { + fmt.Println(stack) + return nil + } + + if stack := common.PropertyGetDefault("buildpacks", "--global", "stack", ""); stack != "" { + fmt.Println(stack) + return nil + } + + b, _ := common.PlugnTriggerOutput("config-get", []string{appName, "DOKKU_IMAGE"}...) + dokkuImage := strings.TrimSpace(string(b[:])) + if dokkuImage != "" { + common.LogWarn("Deprecated: use buildpacks:stacks-set instead of specifying DOKKU_IMAGE environment variable") + fmt.Println(dokkuImage) + return nil + } + + fmt.Println(os.Getenv("DOKKU_IMAGE")) + + return nil +} + // TriggerInstall runs the install step for the buildpacks plugin func TriggerInstall() error { if err := common.PropertySetup("buildpacks"); err != nil { From b5c85ad5be482924f98bb8f3b5681bb390bd71b4 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sat, 23 Jan 2021 17:36:56 -0500 Subject: [PATCH 04/10] chore: rename stacks-set to stack-set You can only set one stack... --- docs/deployment/methods/herokuish-buildpacks.md | 2 +- plugins/buildpacks/Makefile | 2 +- plugins/buildpacks/report.go | 2 +- plugins/buildpacks/src/commands/commands.go | 2 +- plugins/buildpacks/src/subcommands/subcommands.go | 6 +++--- plugins/buildpacks/subcommands.go | 4 ++-- plugins/buildpacks/triggers.go | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/docs/deployment/methods/herokuish-buildpacks.md b/docs/deployment/methods/herokuish-buildpacks.md index f9fc632a7..e9ece3787 100644 --- a/docs/deployment/methods/herokuish-buildpacks.md +++ b/docs/deployment/methods/herokuish-buildpacks.md @@ -9,7 +9,7 @@ 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 buildpacks:set [--index 1] # Set new app buildpack at a given position defaulting to the first buildpack if no index is specified -buildpacks:stacks-set # Sets the stack of an app +buildpacks:stack-set # Sets the stack of an app ``` > Warning: If using the `buildpacks` plugin, be sure to unset any `BUILDPACK_URL` and remove any such entries from a committed `.env` file. A specified `BUILDPACK_URL` will always override a `.buildpacks` file or the buildpacks plugin. diff --git a/plugins/buildpacks/Makefile b/plugins/buildpacks/Makefile index 5abb38ed3..3eb867ce7 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/stacks-set +SUBCOMMANDS = subcommands/add subcommands/clear subcommands/list subcommands/remove subcommands/report subcommands/set subcommands/stack-set 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/report.go b/plugins/buildpacks/report.go index 084884b62..072124848 100644 --- a/plugins/buildpacks/report.go +++ b/plugins/buildpacks/report.go @@ -42,7 +42,7 @@ func reportComputedStack(appName string) string { b, _ := common.PlugnTriggerOutput("config-get", []string{appName, "DOKKU_IMAGE"}...) if dokkuImage := strings.TrimSpace(string(b[:])); dokkuImage != "" { - common.LogWarn("Deprecated: use buildpacks:stacks-set instead of specifying DOKKU_IMAGE environment variable") + common.LogWarn("Deprecated: use buildpacks:stack-set instead of specifying DOKKU_IMAGE environment variable") return dokkuImage } diff --git a/plugins/buildpacks/src/commands/commands.go b/plugins/buildpacks/src/commands/commands.go index baf3144a0..569121c9a 100644 --- a/plugins/buildpacks/src/commands/commands.go +++ b/plugins/buildpacks/src/commands/commands.go @@ -24,7 +24,7 @@ Additional commands:` buildpacks:remove , Remove a buildpack set on the app buildpacks:report [] [], Displays a buildpack report for one or more apps buildpacks:set [--index 1] , Set new app buildpack at a given position defaulting to the first buildpack if no index is specified - buildpacks:stacks-set , Sets the stack of an app + buildpacks:stack-set , Sets the stack of an app ` ) diff --git a/plugins/buildpacks/src/subcommands/subcommands.go b/plugins/buildpacks/src/subcommands/subcommands.go index b17a3c5b3..9f0d37f83 100644 --- a/plugins/buildpacks/src/subcommands/subcommands.go +++ b/plugins/buildpacks/src/subcommands/subcommands.go @@ -57,8 +57,8 @@ func main() { appName := args.Arg(0) buildpack := args.Arg(1) err = buildpacks.CommandSet(appName, buildpack, *index) - case "stacks-set": - args := flag.NewFlagSet("buildpacks:stacks-set", flag.ExitOnError) + case "stack-set": + args := flag.NewFlagSet("buildpacks:stack-set", flag.ExitOnError) global := args.Bool("global", false, "--global: set a global property") args.Parse(os.Args[2:]) appName := args.Arg(0) @@ -67,7 +67,7 @@ func main() { appName = "--global" stack = args.Arg(0) } - err = buildpacks.CommandStacksSet(appName, stack) + err = buildpacks.CommandStackSet(appName, stack) default: common.LogFail(fmt.Sprintf("Invalid plugin subcommand call: %s", subcommand)) } diff --git a/plugins/buildpacks/subcommands.go b/plugins/buildpacks/subcommands.go index 3d1b81c39..0befb4625 100644 --- a/plugins/buildpacks/subcommands.go +++ b/plugins/buildpacks/subcommands.go @@ -139,8 +139,8 @@ func CommandSet(appName string, buildpack string, index int) error { return common.PropertyListSet("buildpacks", appName, "buildpacks", buildpack, index) } -// CommandStacksSet implements buildpacks:stacks-set -func CommandStacksSet(appName string, stack string) error { +// CommandStackSet implements buildpacks:stack-set +func CommandStackSet(appName string, stack string) error { common.CommandPropertySet("buildpacks", appName, "stack", stack, DefaultProperties, GlobalProperties) return common.PlugnTrigger("post-stack-set", []string{appName, stack}...) } diff --git a/plugins/buildpacks/triggers.go b/plugins/buildpacks/triggers.go index 195c41dec..e5e20d6e5 100644 --- a/plugins/buildpacks/triggers.go +++ b/plugins/buildpacks/triggers.go @@ -25,7 +25,7 @@ func TriggerBuildpackStackName(appName string) error { b, _ := common.PlugnTriggerOutput("config-get", []string{appName, "DOKKU_IMAGE"}...) dokkuImage := strings.TrimSpace(string(b[:])) if dokkuImage != "" { - common.LogWarn("Deprecated: use buildpacks:stacks-set instead of specifying DOKKU_IMAGE environment variable") + common.LogWarn("Deprecated: use buildpacks:stack-set instead of specifying DOKKU_IMAGE environment variable") fmt.Println(dokkuImage) return nil } From 7caa95b3f3913b6232bfe46163cb767f46d5ed45 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sat, 23 Jan 2021 17:37:41 -0500 Subject: [PATCH 05/10] feat: conditionally execute the post-stack-set call If the value does not change, then we should not trigger the command --- docs/deployment/methods/herokuish-buildpacks.md | 2 ++ plugins/buildpacks/subcommands.go | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/docs/deployment/methods/herokuish-buildpacks.md b/docs/deployment/methods/herokuish-buildpacks.md index e9ece3787..60043d45a 100644 --- a/docs/deployment/methods/herokuish-buildpacks.md +++ b/docs/deployment/methods/herokuish-buildpacks.md @@ -140,6 +140,8 @@ The specified stack can also be unset by omitting the name of the stack when cal dokku buildpacks:stack-set node-js-app ``` +A change in the stack value will execute the `post-stack-set` trigger. + Finally, stacks can be set or unset globally as a fallback. This will take precedence over a globally set `DOKKU_IMAGE` environment variable (`gliderlabs/herokuish:latest` by default). ```shell diff --git a/plugins/buildpacks/subcommands.go b/plugins/buildpacks/subcommands.go index 0befb4625..e90ea4be4 100644 --- a/plugins/buildpacks/subcommands.go +++ b/plugins/buildpacks/subcommands.go @@ -141,6 +141,11 @@ func CommandSet(appName string, buildpack string, index int) error { // CommandStackSet implements buildpacks:stack-set func CommandStackSet(appName string, stack string) error { + oldStack := common.PropertyGet("buildpacks", appName, "stack") common.CommandPropertySet("buildpacks", appName, "stack", stack, DefaultProperties, GlobalProperties) - return common.PlugnTrigger("post-stack-set", []string{appName, stack}...) + if oldStack != stack { + return common.PlugnTrigger("post-stack-set", []string{appName, stack}...) + } + + return nil } From 308927adce0c65e275006a4d83b6c0abb2b93764 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sat, 23 Jan 2021 17:38:20 -0500 Subject: [PATCH 06/10] refactor: log what stack is being used if it is modified --- plugins/builder-cnb/builder-build | 2 ++ plugins/builder-dockerfile/builder-build | 2 ++ plugins/builder-herokuish/builder-build | 11 +++++++++-- plugins/buildpacks/triggers.go | 2 -- plugins/common/functions | 3 --- 5 files changed, 13 insertions(+), 7 deletions(-) diff --git a/plugins/builder-cnb/builder-build b/plugins/builder-cnb/builder-build index 83f1e89a4..29ba83d0a 100755 --- a/plugins/builder-cnb/builder-build +++ b/plugins/builder-cnb/builder-build @@ -13,6 +13,8 @@ trigger-builder-cnb-builder-build() { return fi + dokku_log_info1 "Building $APP from cnb (experimental)..." + if ! command -v "pack" &>/dev/null; then dokku_log_fail "Missing pack, install it" fi diff --git a/plugins/builder-dockerfile/builder-build b/plugins/builder-dockerfile/builder-build index a443da29b..dce61d6bb 100755 --- a/plugins/builder-dockerfile/builder-build +++ b/plugins/builder-dockerfile/builder-build @@ -12,6 +12,8 @@ trigger-builder-dockerfile-builder-build() { return fi + dokku_log_info1 "Building $APP from Dockerfile" + local IMAGE=$(get_app_image_name "$APP") local DOCKER_BUILD_LABEL_ARGS="--label=org.label-schema.schema-version=1.0 --label=org.label-schema.vendor=dokku --label=com.dokku.app-name=$APP" diff --git a/plugins/builder-herokuish/builder-build b/plugins/builder-herokuish/builder-build index 76be1b392..ee4b50123 100755 --- a/plugins/builder-herokuish/builder-build +++ b/plugins/builder-herokuish/builder-build @@ -12,6 +12,15 @@ trigger-builder-herokuish-builder-build() { return fi + local stack="$(plugn trigger buildpack-stack-name "$APP")" + if [[ -n "$stack" ]]; then + dokku_log_info1 "Building $APP from $stack" + DOKKU_IMAGE="$stack" + else + dokku_log_info1 "Building $APP from herokuish" + fi + + local IMAGE=$(get_app_image_name "$APP") local DOKKU_APP_CACHE_DIR="$DOKKU_ROOT/$APP/cache" local DOKKU_APP_HOST_CACHE_DIR="$DOKKU_HOST_ROOT/$APP/cache" @@ -21,8 +30,6 @@ trigger-builder-herokuish-builder-build() { pushd "$SOURCECODE_WORK_DIR" &>/dev/null - DOKKU_IMAGE="$(plugn trigger buildpack-stack-name "$APP")" - eval "$(config_export app "$APP")" plugn trigger builder-create-dokku-image "$BUILDER_TYPE" "$APP" "$SOURCECODE_WORK_DIR" "$DOKKU_IMAGE" NEW_DOKKU_IMAGE=$(plugn trigger builder-dokku-image "$BUILDER_TYPE" "$APP" "$SOURCECODE_WORK_DIR" "$DOKKU_IMAGE") diff --git a/plugins/buildpacks/triggers.go b/plugins/buildpacks/triggers.go index e5e20d6e5..ff198d4e0 100644 --- a/plugins/buildpacks/triggers.go +++ b/plugins/buildpacks/triggers.go @@ -30,8 +30,6 @@ func TriggerBuildpackStackName(appName string) error { return nil } - fmt.Println(os.Getenv("DOKKU_IMAGE")) - return nil } diff --git a/plugins/common/functions b/plugins/common/functions index 9c107192e..7fbd0b396 100755 --- a/plugins/common/functions +++ b/plugins/common/functions @@ -713,9 +713,6 @@ dokku_receive() { local DOKKU_CNB_EXPERIMENTAL="$(config_get "$APP" DOKKU_CNB_EXPERIMENTAL || true)" if [[ "$DOKKU_CNB_EXPERIMENTAL" == "1" ]]; then IMAGE_SOURCE_TYPE="cnb" - dokku_log_info1 "Building $APP from $IMAGE_SOURCE_TYPE (experimental)..." - else - dokku_log_info1 "Building $APP from $IMAGE_SOURCE_TYPE..." fi DOKKU_QUIET_OUTPUT=1 config_set --no-restart "$APP" DOKKU_APP_TYPE="$IMAGE_SOURCE_TYPE" From 8ddb214b0e705a94a47a58f52e9e6041058b163e Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sat, 23 Jan 2021 17:38:57 -0500 Subject: [PATCH 07/10] feat: clear repo cache on stack change --- plugins/repo/.gitignore | 1 + plugins/repo/Makefile | 2 +- plugins/repo/src/triggers/triggers.go | 3 +++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/plugins/repo/.gitignore b/plugins/repo/.gitignore index 2983228bd..4e8c51e8a 100644 --- a/plugins/repo/.gitignore +++ b/plugins/repo/.gitignore @@ -3,3 +3,4 @@ /triggers/* /triggers /pre-delete +/post-stack-set diff --git a/plugins/repo/Makefile b/plugins/repo/Makefile index 2dd00e389..fd3d74547 100644 --- a/plugins/repo/Makefile +++ b/plugins/repo/Makefile @@ -1,5 +1,5 @@ SUBCOMMANDS = subcommands/gc subcommands/purge-cache -TRIGGERS = triggers/pre-delete +TRIGGERS = triggers/post-stack-set triggers/pre-delete BUILD = commands subcommands triggers PLUGIN_NAME = repo diff --git a/plugins/repo/src/triggers/triggers.go b/plugins/repo/src/triggers/triggers.go index b0dbd6eff..8e170f1a6 100644 --- a/plugins/repo/src/triggers/triggers.go +++ b/plugins/repo/src/triggers/triggers.go @@ -18,6 +18,9 @@ func main() { var err error switch trigger { + case "post-stack-set": + appName := flag.Arg(0) + err = repo.PurgeCache(appName) case "pre-delete": appName := flag.Arg(0) err = repo.PurgeCache(appName) From 6a85d6a58b9a96a93041ff06c325bed4e40c50c4 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sat, 23 Jan 2021 17:39:44 -0500 Subject: [PATCH 08/10] fix: gitignore buildpack-stack-name trigger --- plugins/buildpacks/.gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/buildpacks/.gitignore b/plugins/buildpacks/.gitignore index 291036bd4..9929fd526 100644 --- a/plugins/buildpacks/.gitignore +++ b/plugins/buildpacks/.gitignore @@ -2,6 +2,7 @@ /subcommands/* /triggers/* /triggers +/buildpack-stack-name /install /post-* /report From 5d9157bc40b36df4ba70632b09764a9bf327537d Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sat, 23 Jan 2021 18:06:57 -0500 Subject: [PATCH 09/10] feat: add support for specifying stack builders for builder-cnb --- .../methods/cloud-native-buildpacks.md | 35 +++++++++++++++++-- .../methods/herokuish-buildpacks.md | 10 +++--- dokku | 1 + plugins/builder-cnb/builder-build | 10 ++++-- plugins/builder-herokuish/builder-build | 1 - 5 files changed, 46 insertions(+), 11 deletions(-) diff --git a/docs/deployment/methods/cloud-native-buildpacks.md b/docs/deployment/methods/cloud-native-buildpacks.md index 0237626d8..4ff249784 100644 --- a/docs/deployment/methods/cloud-native-buildpacks.md +++ b/docs/deployment/methods/cloud-native-buildpacks.md @@ -2,6 +2,9 @@ > New as of 0.22.0 +``` +buildpacks:stack-set # Sets the stack of an app +``` Cloud Native Buildpacks are an evolution over the Buildpacks technology provided by the Herokuish builder. See the [herokuish buildpacks documentation](/docs/deployment/methods/herokuish.md) for more information on how to clear buildpack build cache for an application. > Warning: This functionality uses the `pack` cli from the [Cloud Native Buildpacks](https://buildpacks.io) project to build apps. As the integration is experimental in Dokku, it is likely to change over time. @@ -22,10 +25,8 @@ Builds will proceed with the `pack` cli for the app from then on. As this functionality is highly experimental, there are a number of caveats. Please note that not all issuesare listed below. -- The `heroku/buildpacks:latest` CNB builder is currently enforced. Specifying specific builders is not currently possible. - - A future release will allow modifying the chosen builder. - Specifying specific buildpacks is not currently possible. - - A future release will add support for the `buildpacks` plugin. + - A future release will add support for specifying buildpacks via the `buildpacks` plugin. - There is currently no way to specify extra arguments for `pack` cli invocations. - A future release will add support for injecting extra arguments during the build process. - The default process type is `web`. @@ -33,3 +34,31 @@ As this functionality is highly experimental, there are a number of caveats. Ple - A future version will add integration with the `repo` plugin. - `pack` is not currently included with Dokku, nor is it added as a package dependency. - A future version will include it as a package dependency. + +### Customizing the Buildpack stack builder + +> New as of 0.23.0 + +The default stack builder in use by CNB buildpacks in Dokku is based on `heroku/buildpacks`. Users may desire to switch the stack builder to a custom version, either to update the operating system or to customize packages included with the stack builder. This can be performed via the `buildpacks:stack-set` command. + +```shell +dokku buildpacks:stack-set node-js-app paketobuildpacks/build:base-cnb +``` + +The specified stack builder can also be unset by omitting the name of the stack builder when calling `buildpacks:stack-set`. + +```shell +dokku buildpacks:stack-set node-js-app +``` + +A change in the stack builder value will execute the `post-stack-set` trigger. + +Finally, stack builders can be set or unset globally as a fallback. This will take precedence over a globally set `DOKKU_CNB_STACK` environment variable (`heroku/buildpacks` by default). + +```shell +# set globally +dokku buildpacks:stack-set --global paketobuildpacks/build:base-cnb + +# unset globally +dokku buildpacks:stack-set --global +``` diff --git a/docs/deployment/methods/herokuish-buildpacks.md b/docs/deployment/methods/herokuish-buildpacks.md index 60043d45a..7d1d68976 100644 --- a/docs/deployment/methods/herokuish-buildpacks.md +++ b/docs/deployment/methods/herokuish-buildpacks.md @@ -124,25 +124,25 @@ The `buildpacks:clear` command can be used to clear all configured buildpacks fo dokku buildpacks:clear node-js-app ``` -### Customizing the Buildpack stack +### Customizing the Buildpack stack builder > New as of 0.23.0 -The default stack in use by Herokuish buildpacks in Dokku is based on `gliderlabs/herokuish`. Typically, this is installed via an OS package which pulls the requisite Docker image. Users may desire to switch the stack to a custom version, either to update the stack operating system or to customize packages included with the stack. This can be performed via teh `buildpacks:stack-set` command. +The default stack builder in use by Herokuish buildpacks in Dokku is based on `gliderlabs/herokuish:latest`. Typically, this is installed via an OS package which pulls the requisite Docker image. Users may desire to switch the stack builder to a custom version, either to update the operating system or to customize packages included with the stack builder. This can be performed via the `buildpacks:stack-set` command. ```shell dokku buildpacks:stack-set node-js-app gliderlabs/herokuish:latest ``` -The specified stack can also be unset by omitting the name of the stack when calling `buildpacks:stack-set`. +The specified stack builder can also be unset by omitting the name of the stack builder when calling `buildpacks:stack-set`. ```shell dokku buildpacks:stack-set node-js-app ``` -A change in the stack value will execute the `post-stack-set` trigger. +A change in the stack builder value will execute the `post-stack-set` trigger. -Finally, stacks can be set or unset globally as a fallback. This will take precedence over a globally set `DOKKU_IMAGE` environment variable (`gliderlabs/herokuish:latest` by default). +Finally, stack builders can be set or unset globally as a fallback. This will take precedence over a globally set `DOKKU_IMAGE` environment variable (`gliderlabs/herokuish:latest` by default). ```shell # set globally diff --git a/dokku b/dokku index 8317c395f..cdbc45431 100755 --- a/dokku +++ b/dokku @@ -42,6 +42,7 @@ DOKKU_DISTRO=$( export DOCKER_BIN=${DOCKER_BIN:="docker"} export DOKKU_IMAGE=${DOKKU_IMAGE:="gliderlabs/herokuish:latest"} +export DOKKU_CNB_BUILDER=${DOKKU_CNB_BUILDER:="heroku/buildpacks"} export DOKKU_LIB_ROOT=${DOKKU_LIB_PATH:="/var/lib/dokku"} export PLUGIN_PATH=${PLUGIN_PATH:="$DOKKU_LIB_ROOT/plugins"} diff --git a/plugins/builder-cnb/builder-build b/plugins/builder-cnb/builder-build index 29ba83d0a..a147023e0 100755 --- a/plugins/builder-cnb/builder-build +++ b/plugins/builder-cnb/builder-build @@ -13,7 +13,13 @@ trigger-builder-cnb-builder-build() { return fi - dokku_log_info1 "Building $APP from cnb (experimental)..." + + local stack="$(plugn trigger buildpack-stack-name "$APP")" + if [[ -z "$stack" ]]; then + DOKKU_CNB_STACK="$stack" + fi + + dokku_log_info1 "Building $APP from cnb stack $DOKKU_CNB_STACK (experimental)..." if ! command -v "pack" &>/dev/null; then dokku_log_fail "Missing pack, install it" @@ -30,7 +36,7 @@ trigger-builder-cnb-builder-build() { plugn trigger pre-build-cnb "$APP" "$SOURCECODE_WORK_DIR" - pack build "$IMAGE" --builder heroku/buildpacks --path "$SOURCECODE_WORK_DIR" --default-process web + pack build "$IMAGE" --builder "$DOKKU_CNB_BUILDER" --path "$SOURCECODE_WORK_DIR" --default-process web echo "FROM $IMAGE" | suppress_output "$DOCKER_BIN" image build --label=com.dokku.image-stage=build --label=org.label-schema.schema-version=1.0 --label=org.label-schema.vendor=dokku --label=com.dokku.app-name=$APP --label=dokku -t "$IMAGE" - diff --git a/plugins/builder-herokuish/builder-build b/plugins/builder-herokuish/builder-build index ee4b50123..b3b67465f 100755 --- a/plugins/builder-herokuish/builder-build +++ b/plugins/builder-herokuish/builder-build @@ -20,7 +20,6 @@ trigger-builder-herokuish-builder-build() { dokku_log_info1 "Building $APP from herokuish" fi - local IMAGE=$(get_app_image_name "$APP") local DOKKU_APP_CACHE_DIR="$DOKKU_ROOT/$APP/cache" local DOKKU_APP_HOST_CACHE_DIR="$DOKKU_HOST_ROOT/$APP/cache" From f81c802eccb5b7ad16a078efc7f86990acfeefa5 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sat, 23 Jan 2021 18:17:40 -0500 Subject: [PATCH 10/10] refactor: rename command to :set-property This will allow us to set other property values for the buildpacks plugin. --- docs/configuration/environment-variables.md | 2 +- .../methods/cloud-native-buildpacks.md | 14 +++++----- .../methods/herokuish-buildpacks.md | 26 +++++++++---------- plugins/buildpacks/Makefile | 2 +- plugins/buildpacks/report.go | 2 +- plugins/buildpacks/src/commands/commands.go | 2 +- .../buildpacks/src/subcommands/subcommands.go | 12 +++++---- plugins/buildpacks/subcommands.go | 16 +++++++----- plugins/buildpacks/triggers.go | 2 +- 9 files changed, 42 insertions(+), 36 deletions(-) diff --git a/docs/configuration/environment-variables.md b/docs/configuration/environment-variables.md index ab46dece2..eab4db630 100644 --- a/docs/configuration/environment-variables.md +++ b/docs/configuration/environment-variables.md @@ -78,7 +78,7 @@ The following config variables have special meanings and can be set in a variety | Name | Default | How to modify | Description | | ------------------------------ | ------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------- | | `DOKKU_ROOT` | `~dokku` | `/etc/environment` | The root directory where dokku will store application repositories, as well as certain configuration files. | -| `DOKKU_IMAGE` | `gliderlabs/herokuish` | `/etc/environment`
`~dokku/.dokkurc`
`~dokku/.dokkurc/*` | The default image to use when building herokuish containers. Deprecated in favor of using `buildpacks:stack-set` | +| `DOKKU_IMAGE` | `gliderlabs/herokuish` | `/etc/environment`
`~dokku/.dokkurc`
`~dokku/.dokkurc/*` | The default image to use when building herokuish containers. Deprecated in favor of using `buildpacks:set-property` | | `DOKKU_LIB_ROOT` | `/var/lib/dokku` | `/etc/environment`
`~dokku/.dokkurc`
`~dokku/.dokkurc/*` | The directory where plugins, certain data, and general configuration is stored. | | `PLUGIN_PATH` | `$DOKKU_LIB_ROOT/plugins"` | `/etc/environment`
`~dokku/.dokkurc`
`~dokku/.dokkurc/*` | The top-level directory where plugins are stored. | | `PLUGIN_AVAILABLE_PATH` | `$PLUGIN_PATH/available"` | `/etc/environment`
`~dokku/.dokkurc`
`~dokku/.dokkurc/*` | The directory that holds all available plugins, including core. | diff --git a/docs/deployment/methods/cloud-native-buildpacks.md b/docs/deployment/methods/cloud-native-buildpacks.md index 4ff249784..532c4f8ef 100644 --- a/docs/deployment/methods/cloud-native-buildpacks.md +++ b/docs/deployment/methods/cloud-native-buildpacks.md @@ -3,7 +3,7 @@ > New as of 0.22.0 ``` -buildpacks:stack-set # Sets the stack of an app +buildpacks:set-property [--global|] # Set or clear a buildpacks property for an app ``` Cloud Native Buildpacks are an evolution over the Buildpacks technology provided by the Herokuish builder. See the [herokuish buildpacks documentation](/docs/deployment/methods/herokuish.md) for more information on how to clear buildpack build cache for an application. @@ -39,16 +39,16 @@ As this functionality is highly experimental, there are a number of caveats. Ple > New as of 0.23.0 -The default stack builder in use by CNB buildpacks in Dokku is based on `heroku/buildpacks`. Users may desire to switch the stack builder to a custom version, either to update the operating system or to customize packages included with the stack builder. This can be performed via the `buildpacks:stack-set` command. +The default stack builder in use by CNB buildpacks in Dokku is based on `heroku/buildpacks`. Users may desire to switch the stack builder to a custom version, either to update the operating system or to customize packages included with the stack builder. This can be performed via the `buildpacks:set-property` command. ```shell -dokku buildpacks:stack-set node-js-app paketobuildpacks/build:base-cnb +dokku buildpacks:set-property node-js-app paketobuildpacks/build:base-cnb ``` -The specified stack builder can also be unset by omitting the name of the stack builder when calling `buildpacks:stack-set`. +The specified stack builder can also be unset by omitting the name of the stack builder when calling `buildpacks:set-property`. ```shell -dokku buildpacks:stack-set node-js-app +dokku buildpacks:set-property node-js-app ``` A change in the stack builder value will execute the `post-stack-set` trigger. @@ -57,8 +57,8 @@ Finally, stack builders can be set or unset globally as a fallback. This will ta ```shell # set globally -dokku buildpacks:stack-set --global paketobuildpacks/build:base-cnb +dokku buildpacks:set-property --global paketobuildpacks/build:base-cnb # unset globally -dokku buildpacks:stack-set --global +dokku buildpacks:set-property --global ``` diff --git a/docs/deployment/methods/herokuish-buildpacks.md b/docs/deployment/methods/herokuish-buildpacks.md index 7d1d68976..b6a278cc6 100644 --- a/docs/deployment/methods/herokuish-buildpacks.md +++ b/docs/deployment/methods/herokuish-buildpacks.md @@ -3,13 +3,13 @@ > Subcommands new as of 0.15.0 ``` -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: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 -buildpacks:set [--index 1] # Set new app buildpack at a given position defaulting to the first buildpack if no index is specified -buildpacks:stack-set # Sets the stack of an app +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: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 +buildpacks:set [--index 1] # Set new app buildpack at a given position defaulting to the first buildpack if no index is specified +buildpacks:set-property [--global|] # Set or clear a buildpacks property for an app ``` > Warning: If using the `buildpacks` plugin, be sure to unset any `BUILDPACK_URL` and remove any such entries from a committed `.env` file. A specified `BUILDPACK_URL` will always override a `.buildpacks` file or the buildpacks plugin. @@ -128,16 +128,16 @@ dokku buildpacks:clear node-js-app > New as of 0.23.0 -The default stack builder in use by Herokuish buildpacks in Dokku is based on `gliderlabs/herokuish:latest`. Typically, this is installed via an OS package which pulls the requisite Docker image. Users may desire to switch the stack builder to a custom version, either to update the operating system or to customize packages included with the stack builder. This can be performed via the `buildpacks:stack-set` command. +The default stack builder in use by Herokuish buildpacks in Dokku is based on `gliderlabs/herokuish:latest`. Typically, this is installed via an OS package which pulls the requisite Docker image. Users may desire to switch the stack builder to a custom version, either to update the operating system or to customize packages included with the stack builder. This can be performed via the `buildpacks:set-property` command. ```shell -dokku buildpacks:stack-set node-js-app gliderlabs/herokuish:latest +dokku buildpacks:set-property node-js-app gliderlabs/herokuish:latest ``` -The specified stack builder can also be unset by omitting the name of the stack builder when calling `buildpacks:stack-set`. +The specified stack builder can also be unset by omitting the name of the stack builder when calling `buildpacks:set-property`. ```shell -dokku buildpacks:stack-set node-js-app +dokku buildpacks:set-property node-js-app ``` A change in the stack builder value will execute the `post-stack-set` trigger. @@ -146,10 +146,10 @@ Finally, stack builders can be set or unset globally as a fallback. This will ta ```shell # set globally -dokku buildpacks:stack-set --global gliderlabs/herokuish:latest +dokku buildpacks:set-property --global gliderlabs/herokuish:latest # unset globally -dokku buildpacks:stack-set --global +dokku buildpacks:set-property --global ``` ### Displaying buildpack reports for an app diff --git a/plugins/buildpacks/Makefile b/plugins/buildpacks/Makefile index 3eb867ce7..aff09a27a 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/stack-set +SUBCOMMANDS = subcommands/add subcommands/clear 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/report.go b/plugins/buildpacks/report.go index 072124848..135f74920 100644 --- a/plugins/buildpacks/report.go +++ b/plugins/buildpacks/report.go @@ -42,7 +42,7 @@ func reportComputedStack(appName string) string { b, _ := common.PlugnTriggerOutput("config-get", []string{appName, "DOKKU_IMAGE"}...) if dokkuImage := strings.TrimSpace(string(b[:])); dokkuImage != "" { - common.LogWarn("Deprecated: use buildpacks:stack-set instead of specifying DOKKU_IMAGE environment variable") + common.LogWarn("Deprecated: use buildpacks:set-property instead of specifying DOKKU_IMAGE environment variable") return dokkuImage } diff --git a/plugins/buildpacks/src/commands/commands.go b/plugins/buildpacks/src/commands/commands.go index 569121c9a..08ec2195c 100644 --- a/plugins/buildpacks/src/commands/commands.go +++ b/plugins/buildpacks/src/commands/commands.go @@ -24,7 +24,7 @@ Additional commands:` buildpacks:remove , Remove a buildpack set on the app buildpacks:report [] [], Displays a buildpack report for one or more apps buildpacks:set [--index 1] , Set new app buildpack at a given position defaulting to the first buildpack if no index is specified - buildpacks:stack-set , Sets the stack of an app + buildpacks:set-property [--global|] , Set or clear a buildpacks property for an app ` ) diff --git a/plugins/buildpacks/src/subcommands/subcommands.go b/plugins/buildpacks/src/subcommands/subcommands.go index 9f0d37f83..673d7fcfa 100644 --- a/plugins/buildpacks/src/subcommands/subcommands.go +++ b/plugins/buildpacks/src/subcommands/subcommands.go @@ -57,17 +57,19 @@ func main() { appName := args.Arg(0) buildpack := args.Arg(1) err = buildpacks.CommandSet(appName, buildpack, *index) - case "stack-set": - args := flag.NewFlagSet("buildpacks:stack-set", flag.ExitOnError) + case "set-property": + args := flag.NewFlagSet("buildpacks:set-property", flag.ExitOnError) global := args.Bool("global", false, "--global: set a global property") args.Parse(os.Args[2:]) appName := args.Arg(0) - stack := args.Arg(1) + property := args.Arg(1) + value := args.Arg(2) if *global { appName = "--global" - stack = args.Arg(0) + property = args.Arg(0) + value = args.Arg(1) } - err = buildpacks.CommandStackSet(appName, stack) + err = buildpacks.CommandSetProperty(appName, property, value) default: common.LogFail(fmt.Sprintf("Invalid plugin subcommand call: %s", subcommand)) } diff --git a/plugins/buildpacks/subcommands.go b/plugins/buildpacks/subcommands.go index e90ea4be4..173db4d99 100644 --- a/plugins/buildpacks/subcommands.go +++ b/plugins/buildpacks/subcommands.go @@ -139,12 +139,16 @@ func CommandSet(appName string, buildpack string, index int) error { return common.PropertyListSet("buildpacks", appName, "buildpacks", buildpack, index) } -// CommandStackSet implements buildpacks:stack-set -func CommandStackSet(appName string, stack string) error { - oldStack := common.PropertyGet("buildpacks", appName, "stack") - common.CommandPropertySet("buildpacks", appName, "stack", stack, DefaultProperties, GlobalProperties) - if oldStack != stack { - return common.PlugnTrigger("post-stack-set", []string{appName, stack}...) +// CommandSetProperty implements buildpacks:set-property +func CommandSetProperty(appName string, property string, value string) error { + oldStack := "" + if property == "stack" { + oldStack = common.PropertyGet("buildpacks", appName, "stack") + } + + common.CommandPropertySet("buildpacks", appName, property, value, DefaultProperties, GlobalProperties) + if property == "stack" && oldStack != value { + return common.PlugnTrigger("post-stack-set", []string{appName, value}...) } return nil diff --git a/plugins/buildpacks/triggers.go b/plugins/buildpacks/triggers.go index ff198d4e0..9c07b2a97 100644 --- a/plugins/buildpacks/triggers.go +++ b/plugins/buildpacks/triggers.go @@ -25,7 +25,7 @@ func TriggerBuildpackStackName(appName string) error { b, _ := common.PlugnTriggerOutput("config-get", []string{appName, "DOKKU_IMAGE"}...) dokkuImage := strings.TrimSpace(string(b[:])) if dokkuImage != "" { - common.LogWarn("Deprecated: use buildpacks:stack-set instead of specifying DOKKU_IMAGE environment variable") + common.LogWarn("Deprecated: use buildpacks:set-property instead of specifying DOKKU_IMAGE environment variable") fmt.Println(dokkuImage) return nil }