diff --git a/docs/configuration/environment-variables.md b/docs/configuration/environment-variables.md index fd39408d4..3bfffe858 100644 --- a/docs/configuration/environment-variables.md +++ b/docs/configuration/environment-variables.md @@ -5,10 +5,11 @@ Typically an application will require some configuration to run properly. Dokku The `config` plugin provides the following commands to manage your variables: ``` -config (|--global) Display all global or app-specific config vars -config:get (|--global) KEY Display a global or app-specific config value -config:set (|--global) KEY1=VALUE1 [KEY2=VALUE2 ...] Set one or more config vars -config:unset (|--global) KEY1 [KEY2 ...] Unset one or more config vars +config (|--global) Display all global or app-specific config vars +config:get (|--global) KEY Display a global or app-specific config value +config:set (|--global) KEY1=VALUE1 [KEY2=VALUE2 ...] Set one or more config vars +config:unset (|--global) KEY1 [KEY2 ...] Unset one or more config vars +config:export [--format=FORMAT] [--merged] (|--global) Export all global or app-specific configuration ``` The variables are available both at run time and during the application build/compilation step for buildpack-based deploys. For security reasons - and as per [docker recommendations](https://github.com/docker/docker/issues/13490) - Dockerfile-based deploys have variables available *only* during runtime, as noted in [this issue](https://github.com/dokku/dokku/issues/1860). @@ -50,13 +51,14 @@ dokku config:export node-js-app # export COMPILE_ASSETS='1' # source in all the node-js-app app environment variables -eval $(dokku config node-js-app --export) +eval $(dokku config:export node-js-app) ``` -You can also output the variables in a single-line for usage in command-line utilities with the `--shell` flag: +You can control the format of the exported variables with the `--format` flag. +`--format=shell` will output the variables in a single-line for usage in command-line utilities: ```shell -dokku config:export node-js-app --format shell +dokku config:export --format shell node-js-app # outputs variables in the form: # diff --git a/plugins/config/src/commands/commands.go b/plugins/config/src/commands/commands.go index 040345e42..20590e88e 100644 --- a/plugins/config/src/commands/commands.go +++ b/plugins/config/src/commands/commands.go @@ -7,6 +7,9 @@ import ( "strconv" "strings" + "github.com/dokku/dokku/plugins/common" + "github.com/dokku/dokku/plugins/config/src/configenv" + "github.com/dokku/dokku/plugins/config" columnize "github.com/ryanuber/columnize" ) @@ -36,13 +39,32 @@ func main() { cmd := flag.Arg(0) switch cmd { case "config", "config:show": - target := flag.Arg(1) - env := config.GetConfig(target, false) - fmt.Print(config.PrettyPrintEnvEntries("", env.Map())) + args := flag.NewFlagSet("config:show", flag.ExitOnError) + global := args.Bool("global", false, "--global: use the global environment") + shell := args.Bool("shell", false, "--shell: in a single-line for usage in command-line utilities [deprecated]") + export := args.Bool("export", false, "--export: print the env as eval-compatible exports [deprecated]") + args.Parse(os.Args[2:]) + appName, _ := config.GetCommonArgs(*global, args.Args()) + env := config.GetConfig(appName, false) + + if *shell && *export { + common.LogFail("Only one of --shell and --export can be given") + } + if *shell { + fmt.Print(env.Export(configenv.Shell)) + } else if *export { + fmt.Println(env.Export(configenv.Exports)) + } else { + contextName := "global" + if appName != "" { + contextName = appName + } + common.LogInfo2(contextName + " config vars") + fmt.Println(config.PrettyPrintEnvEntries("", env.Map())) + } case "config:help": - usage() case "help": - fmt.Print(helpContent) + usage() default: dokkuNotImplementExitCode, err := strconv.Atoi(os.Getenv("DOKKU_NOT_IMPLEMENTED_EXIT")) if err != nil {