Every Go-implemented plugin's `:report --format json` now emits keys without the redundant `<plugin>-` head segment, matching the shape bash plugins have always emitted. The CLI flag names and `:set` semantics are unchanged. For backwards compatibility during the 0.38.x patch series, the legacy `<plugin>-<property>` keys are emitted side-by-side with the new keys, and a future major release will drop the legacy keys. `common.ReportSingleApp` is refactored to accept a `ReportSingleAppInput` struct with a `Validate()` method so the input is checked before any work runs, which also catches the latent `"docker options"` reportType bug at the API boundary.
88 lines
2.4 KiB
Go
88 lines
2.4 KiB
Go
package buildpacks
|
|
|
|
import (
|
|
"os"
|
|
"strings"
|
|
|
|
"github.com/dokku/dokku/plugins/common"
|
|
)
|
|
|
|
// ReportSingleApp is an internal function that displays the buildpacks report for one or more apps
|
|
func ReportSingleApp(appName string, format string, infoFlag string) error {
|
|
if appName != "--global" {
|
|
if err := common.VerifyAppName(appName); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
var flags map[string]common.ReportFunc
|
|
if appName == "--global" {
|
|
flags = map[string]common.ReportFunc{
|
|
"--buildpacks-global-stack": reportGlobalStack,
|
|
}
|
|
} else {
|
|
flags = map[string]common.ReportFunc{
|
|
"--buildpacks-computed-stack": reportComputedStack,
|
|
"--buildpacks-global-stack": reportGlobalStack,
|
|
"--buildpacks-list": reportList,
|
|
"--buildpacks-stack": reportStack,
|
|
}
|
|
}
|
|
|
|
flagKeys := []string{}
|
|
for flagKey := range flags {
|
|
flagKeys = append(flagKeys, flagKey)
|
|
}
|
|
|
|
infoFlags := common.CollectReport(appName, infoFlag, flags)
|
|
return common.ReportSingleApp(common.ReportSingleAppInput{
|
|
ReportType: "buildpacks",
|
|
AppName: appName,
|
|
InfoFlag: infoFlag,
|
|
InfoFlags: infoFlags,
|
|
InfoFlagKeys: flagKeys,
|
|
Format: format,
|
|
TrimPrefix: true,
|
|
UppercaseFirstCharacter: true,
|
|
EmitLegacyPrefix: true,
|
|
})
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
results, _ := common.CallPlugnTrigger(common.PlugnTriggerInput{
|
|
Trigger: "config-get",
|
|
Args: []string{appName, "DOKKU_IMAGE"},
|
|
})
|
|
if dokkuImage := results.StdoutContents(); dokkuImage != "" {
|
|
common.LogWarn("Deprecated: use buildpacks:set-property 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 {
|
|
return ""
|
|
}
|
|
|
|
return strings.Join(buildpacks, ",")
|
|
}
|
|
|
|
func reportStack(appName string) string {
|
|
return common.PropertyGetDefault("buildpacks", appName, "stack", "")
|
|
}
|