mirror of
https://github.com/dokku/dokku.git
synced 2026-08-29 10:08:53 +02:00
feat: migrate environment variables to plugin properties
Standardize how environment variables are migrated to properties during install triggers and migrate all remaining DOKKU_* config vars to their appropriate plugin properties. Adds a reusable MigrateConfigToProperties() function in the common package with Transform callback and ListProperty support, plus a migrate-config-to-property subcommand for the prop binary so shell plugins can use the same code path. Migrated variables and their new property owners: - DOKKU_APP_PROXY_TYPE/DOKKU_PROXY_TYPE → proxy type - DOKKU_DISABLE_PROXY → proxy disabled - DOKKU_PROXY_PORT → ports proxy-port - DOKKU_PROXY_SSL_PORT → ports proxy-ssl-port - DOKKU_APP_RESTORE → ps restore - DOKKU_SKIP_DEPLOY → ps skip-deploy - DOKKU_START_CMD → ps start-cmd - DOKKU_DOCKERFILE_START_CMD → ps dockerfile-start-cmd - DOKKU_DISABLE_APP_AUTOCREATION → apps disable-autocreation - DOKKU_APP_SHELL → scheduler shell - DOKKU_SKIP_CLEANUP → builder skip-cleanup - DOKKU_CHECKS_DISABLED → checks disabled - DOKKU_CHECKS_SKIPPED → checks skipped - DOKKU_CHECKS_WAIT → checks wait - DOKKU_CHECKS_TIMEOUT → checks timeout - DOKKU_CHECKS_ATTEMPTS → checks attempts - DOKKU_DEFAULT_CHECKS_WAIT → checks default-wait - DOKKU_SKIP_ALL_CHECKS → checks disabled (legacy) - DOKKU_SKIP_DEFAULT_CHECKS → checks skipped (legacy) Also refactors existing bespoke migration loops in scheduler, ports, ps, builder, and nginx-vhosts plugins to use the standardized utility. Removes DOKKU_PARALLEL_ARGUMENTS from documentation (unused in core). Deprecates fn-migrate-config-to-property bash function. closes #1558
This commit is contained in:
@@ -10,7 +10,6 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/dokku/dokku/plugins/common"
|
||||
"github.com/dokku/dokku/plugins/config"
|
||||
"github.com/ryanuber/columnize"
|
||||
)
|
||||
|
||||
@@ -162,11 +161,8 @@ func getDetectedPortMaps(appName string) []PortMap {
|
||||
// getGlobalProxyPort gets the global proxy port
|
||||
func getGlobalProxyPort() int {
|
||||
port := 0
|
||||
results, _ := common.CallPlugnTrigger(common.PlugnTriggerInput{
|
||||
Trigger: "config-get-global",
|
||||
Args: []string{"DOKKU_PROXY_PORT"},
|
||||
})
|
||||
if intVar, err := strconv.Atoi(results.StdoutContents()); err == nil {
|
||||
value := common.PropertyGet("ports", "--global", "proxy-port")
|
||||
if intVar, err := strconv.Atoi(value); err == nil {
|
||||
port = intVar
|
||||
}
|
||||
|
||||
@@ -176,11 +172,8 @@ func getGlobalProxyPort() int {
|
||||
// getGlobalProxySSLPort gets the global proxy ssl port
|
||||
func getGlobalProxySSLPort() int {
|
||||
port := 0
|
||||
results, _ := common.CallPlugnTrigger(common.PlugnTriggerInput{
|
||||
Trigger: "config-get-global",
|
||||
Args: []string{"DOKKU_PROXY_SSL_PORT"},
|
||||
})
|
||||
if intVar, err := strconv.Atoi(results.StdoutContents()); err == nil {
|
||||
value := common.PropertyGet("ports", "--global", "proxy-ssl-port")
|
||||
if intVar, err := strconv.Atoi(value); err == nil {
|
||||
port = intVar
|
||||
}
|
||||
|
||||
@@ -201,11 +194,8 @@ func getPortMaps(appName string) []PortMap {
|
||||
// getProxyPort gets the proxy port for an app
|
||||
func getProxyPort(appName string) int {
|
||||
port := 0
|
||||
results, _ := common.CallPlugnTrigger(common.PlugnTriggerInput{
|
||||
Trigger: "config-get",
|
||||
Args: []string{appName, "DOKKU_PROXY_PORT"},
|
||||
})
|
||||
if intVar, err := strconv.Atoi(results.StdoutContents()); err == nil {
|
||||
value := common.PropertyGet("ports", appName, "proxy-port")
|
||||
if intVar, err := strconv.Atoi(value); err == nil {
|
||||
port = intVar
|
||||
}
|
||||
|
||||
@@ -215,11 +205,8 @@ func getProxyPort(appName string) int {
|
||||
// getProxySSLPort gets the proxy ssl port for an app
|
||||
func getProxySSLPort(appName string) int {
|
||||
port := 0
|
||||
results, _ := common.CallPlugnTrigger(common.PlugnTriggerInput{
|
||||
Trigger: "config-get",
|
||||
Args: []string{appName, "DOKKU_PROXY_SSL_PORT"},
|
||||
})
|
||||
if intVar, err := strconv.Atoi(results.StdoutContents()); err == nil {
|
||||
value := common.PropertyGet("ports", appName, "proxy-ssl-port")
|
||||
if intVar, err := strconv.Atoi(value); err == nil {
|
||||
port = intVar
|
||||
}
|
||||
|
||||
@@ -445,22 +432,22 @@ func setPortMaps(appName string, portMaps []PortMap) error {
|
||||
|
||||
// setProxyPort sets the proxy port for an app
|
||||
func setProxyPort(appName string, port int) error {
|
||||
return common.EnvWrap(func() error {
|
||||
entries := map[string]string{
|
||||
"DOKKU_PROXY_PORT": fmt.Sprint(port),
|
||||
}
|
||||
return config.SetMany(appName, entries, false, false)
|
||||
}, map[string]string{"DOKKU_QUIET_OUTPUT": "1"})
|
||||
return common.PropertyWrite("ports", appName, "proxy-port", fmt.Sprint(port))
|
||||
}
|
||||
|
||||
// setProxySSLPort sets the proxy ssl port for an app
|
||||
func setProxySSLPort(appName string, port int) error {
|
||||
return common.EnvWrap(func() error {
|
||||
entries := map[string]string{
|
||||
"DOKKU_PROXY_SSL_PORT": fmt.Sprint(port),
|
||||
}
|
||||
return config.SetMany(appName, entries, false, false)
|
||||
}, map[string]string{"DOKKU_QUIET_OUTPUT": "1"})
|
||||
return common.PropertyWrite("ports", appName, "proxy-ssl-port", fmt.Sprint(port))
|
||||
}
|
||||
|
||||
// transformPortMap normalizes a port map string for migration to list properties
|
||||
func transformPortMap(value string) string {
|
||||
portMaps, _ := parsePortMapString(value)
|
||||
var parts []string
|
||||
for _, portMap := range portMaps {
|
||||
parts = append(parts, portMap.String())
|
||||
}
|
||||
return strings.Join(parts, " ")
|
||||
}
|
||||
|
||||
// uniquePortMaps returns a unique set of port maps
|
||||
|
||||
@@ -4,6 +4,20 @@ import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
var (
|
||||
// DefaultProperties is a map of all valid ports properties with corresponding default property values
|
||||
DefaultProperties = map[string]string{
|
||||
"proxy-port": "",
|
||||
"proxy-ssl-port": "",
|
||||
}
|
||||
|
||||
// GlobalProperties is a map of all valid global ports properties
|
||||
GlobalProperties = map[string]bool{
|
||||
"proxy-port": true,
|
||||
"proxy-ssl-port": true,
|
||||
}
|
||||
)
|
||||
|
||||
// PortMap is a struct that contains a scheme:host-port:container-port mapping
|
||||
type PortMap struct {
|
||||
// ContainerPort is the port on the container
|
||||
|
||||
@@ -2,12 +2,10 @@ package ports
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"sort"
|
||||
|
||||
"github.com/dokku/dokku/plugins/common"
|
||||
"github.com/dokku/dokku/plugins/config"
|
||||
)
|
||||
|
||||
// TriggerInstall migrates the ports config to properties
|
||||
@@ -16,44 +14,25 @@ func TriggerInstall() error {
|
||||
return fmt.Errorf("Unable to install the ports plugin: %s", err.Error())
|
||||
}
|
||||
|
||||
apps, err := common.UnfilteredDokkuApps()
|
||||
if err != nil && !errors.Is(err, common.NoAppsExist) {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, appName := range apps {
|
||||
if common.PropertyExists("ports", appName, "map") {
|
||||
continue
|
||||
}
|
||||
|
||||
results, _ := common.CallPlugnTrigger(common.PlugnTriggerInput{
|
||||
Trigger: "config-get",
|
||||
Args: []string{appName, "DOKKU_PROXY_PORT_MAP"},
|
||||
})
|
||||
portMapString := results.StdoutContents()
|
||||
if portMapString == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
common.LogVerboseQuiet(fmt.Sprintf("Setting %s ports property 'map' to %v", appName, portMapString))
|
||||
portMaps, _ := parsePortMapString(portMapString)
|
||||
|
||||
propertyValue := []string{}
|
||||
for _, portMap := range portMaps {
|
||||
propertyValue = append(propertyValue, portMap.String())
|
||||
}
|
||||
|
||||
if err := common.PropertyListWrite("ports", appName, "map", propertyValue); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err := common.CallPlugnTrigger(common.PlugnTriggerInput{
|
||||
Trigger: "config-unset",
|
||||
Args: []string{appName, "DOKKU_PROXY_PORT_MAP"},
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := common.MigrateConfigToProperties("ports", []common.MigrateConfigEntry{
|
||||
{
|
||||
ConfigVar: "DOKKU_PROXY_PORT_MAP",
|
||||
Property: "map",
|
||||
ListProperty: true,
|
||||
Transform: transformPortMap,
|
||||
},
|
||||
{
|
||||
ConfigVar: "DOKKU_PROXY_PORT",
|
||||
GlobalConfigVar: "DOKKU_PROXY_PORT",
|
||||
Property: "proxy-port",
|
||||
},
|
||||
{
|
||||
ConfigVar: "DOKKU_PROXY_SSL_PORT",
|
||||
GlobalConfigVar: "DOKKU_PROXY_SSL_PORT",
|
||||
Property: "proxy-ssl-port",
|
||||
},
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -185,34 +164,26 @@ func TriggerPostAppRenameSetup(oldAppName string, newAppName string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// TriggerPostCertsRemove unsets port config vars after SSL cert is added
|
||||
// TriggerPostCertsRemove unsets port properties after SSL cert is removed
|
||||
func TriggerPostCertsRemove(appName string) error {
|
||||
keys := []string{"DOKKU_PROXY_SSL_PORT"}
|
||||
if err := config.UnsetMany(appName, keys, false); err != nil {
|
||||
if err := common.PropertyDelete("ports", appName, "proxy-ssl-port"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return removePortMaps(appName, filterAppPortMaps(appName, "https", 443))
|
||||
}
|
||||
|
||||
// TriggerPostCertsUpdate sets port config vars after SSL cert is added
|
||||
// TriggerPostCertsUpdate sets port properties after SSL cert is added
|
||||
func TriggerPostCertsUpdate(appName string) error {
|
||||
port := config.GetWithDefault(appName, "DOKKU_PROXY_PORT", "")
|
||||
sslPort := config.GetWithDefault(appName, "DOKKU_PROXY_SSL_PORT", "")
|
||||
port := common.PropertyGet("ports", appName, "proxy-port")
|
||||
sslPort := common.PropertyGet("ports", appName, "proxy-ssl-port")
|
||||
portMaps := getPortMaps(appName)
|
||||
|
||||
toUnset := []string{}
|
||||
if port == "80" {
|
||||
toUnset = append(toUnset, "DOKKU_PROXY_PORT")
|
||||
common.PropertyDelete("ports", appName, "proxy-port")
|
||||
}
|
||||
if sslPort == "443" {
|
||||
toUnset = append(toUnset, "DOKKU_PROXY_SSL_PORT")
|
||||
}
|
||||
|
||||
if len(toUnset) > 0 {
|
||||
if err := config.UnsetMany(appName, toUnset, false); err != nil {
|
||||
return err
|
||||
}
|
||||
common.PropertyDelete("ports", appName, "proxy-ssl-port")
|
||||
}
|
||||
|
||||
var http80Ports []PortMap
|
||||
|
||||
Reference in New Issue
Block a user