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
This commit is contained in:
Jose Diaz-Gonzalez committed 2021-01-23 16:19:12 -05:00
1 parent 4c74e0dfba
commit bad90b2b1d
11 files changed
+134 -8

No files matched your search

+31 -1
View File
@@ -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", "")
}