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:
45 files changed
+604
-468
No files matched your search
+26
-55
@@ -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