diff --git a/plugins/builder-pack/builder-build b/plugins/builder-pack/builder-build index 39a21088e..189b3d48d 100755 --- a/plugins/builder-pack/builder-build +++ b/plugins/builder-pack/builder-build @@ -28,18 +28,11 @@ trigger-builder-pack-builder-build() { pushd "$SOURCECODE_WORK_DIR" &>/dev/null - ENV_ARGS_VALUES="$(config_export app "$APP" --format envfile --merged)" - - while IFS= read -r line; do - ENV_ARGS="$ENV_ARGS--env ${line%=*} " - done <<< "$ENV_ARGS_VALUES" - + ENV_ARGS=($(config_export app "$APP" --format pack --merged)) eval "$(config_export app "$APP" --merged)" plugn trigger pre-build-pack "$APP" "$SOURCECODE_WORK_DIR" - - eval "pack build "$IMAGE" --builder "$DOKKU_CNB_BUILDER" --path "$SOURCECODE_WORK_DIR" --default-process web "$ENV_ARGS"" - + pack build "$IMAGE" --builder "$DOKKU_CNB_BUILDER" --path "$SOURCECODE_WORK_DIR" --default-process web "${ENV_ARGS[@]}" docker-image-labeler --label=com.dokku.image-stage=build --label=com.dokku.app-name=$APP --label=org.label-schema.schema-version=1.0 --label=org.label-schema.vendor=dokku --label=dokku "$IMAGE" plugn trigger post-build-pack "$APP" "$SOURCECODE_WORK_DIR" diff --git a/plugins/config/environment.go b/plugins/config/environment.go index 0798c3200..ffd0daf28 100644 --- a/plugins/config/environment.go +++ b/plugins/config/environment.go @@ -26,7 +26,7 @@ const ( ExportFormatEnvfile //ExportFormatDockerArgs format: --env KEY=VALUE args for docker ExportFormatDockerArgs - //ExportFormatDockerArgsKeys format: --env KEY args for docker + //ExportFormatDockerArgsKeys format: --env=KEY args for docker ExportFormatDockerArgsKeys //ExportFormatShell format: env arguments for shell ExportFormatShell @@ -36,6 +36,8 @@ const ( ExportFormatJSON //ExportFormatJSONList format: json output as a list of objects ExportFormatJSONList + //ExportFormatPackArgKeys format: --env KEY args for pack + ExportFormatPackArgKeys ) //Env is a representation for global or app environment @@ -183,6 +185,8 @@ func (e *Env) Export(format ExportFormat) string { return e.JSONString() case ExportFormatJSONList: return e.JSONListString() + case ExportFormatPackArgKeys: + return e.PackArgKeysAsString() default: common.LogFail(fmt.Sprintf("Unknown export format: %v", format)) return "" @@ -244,6 +248,16 @@ func (e *Env) JSONListString() string { return string(data) } +//PackArgKeysAsString gets the contents of this Env in the form -env KEY --env... +func (e *Env) PackArgKeysAsString() string { + keys := e.Keys() + entries := make([]string, len(keys)) + for i, k := range keys { + entries[i] = fmt.Sprintf("%s%s", "--env ", k) + } + return strings.Join(entries, " ") +} + //ShellString gets the contents of this Env in the form "KEY='value' KEY2='value'" // for passing the environment in the shell func (e *Env) ShellString() string { diff --git a/plugins/config/functions.go b/plugins/config/functions.go index 72b46aa7a..49c6d6a5b 100644 --- a/plugins/config/functions.go +++ b/plugins/config/functions.go @@ -13,14 +13,15 @@ func export(appName string, global bool, merged bool, format string) error { suffix := "\n" exportTypes := map[string]ExportFormat{ - "exports": ExportFormatExports, - "envfile": ExportFormatEnvfile, "docker-args": ExportFormatDockerArgs, "docker-args-keys": ExportFormatDockerArgsKeys, - "shell": ExportFormatShell, - "pretty": ExportFormatPretty, + "envfile": ExportFormatEnvfile, + "exports": ExportFormatExports, "json": ExportFormatJSON, "json-list": ExportFormatJSONList, + "pack": ExportFormatPackArgKeys, + "pretty": ExportFormatPretty, + "shell": ExportFormatShell, } exportType, ok := exportTypes[format] diff --git a/plugins/config/src/subcommands/subcommands.go b/plugins/config/src/subcommands/subcommands.go index f7f1f0d09..2032b147d 100644 --- a/plugins/config/src/subcommands/subcommands.go +++ b/plugins/config/src/subcommands/subcommands.go @@ -49,7 +49,7 @@ func main() { args := flag.NewFlagSet("config:export", flag.ExitOnError) global := args.Bool("global", false, "--global: use the global environment") merged := args.Bool("merged", false, "--merged: merge app environment and global environment") - format := args.String("format", "exports", "--format: [ exports | envfile | docker-args | docker-args-keys | shell | pretty | json | json-list ] which format to export as)") + format := args.String("format", "exports", "--format: [ docker-args | docker-args-keys | exports | envfile | json | json-list | pack | pretty | shell ] which format to export as)") args.Parse(os.Args[2:]) if !*global { appName = args.Arg(0) diff --git a/tests/apps/python/bin/pre_compile b/tests/apps/python/bin/pre_compile new file mode 100755 index 000000000..67e0b7924 --- /dev/null +++ b/tests/apps/python/bin/pre_compile @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +echo "Build time env var SECRET_KEY=${SECRET_KEY}" \ No newline at end of file diff --git a/tests/unit/builder-pack.bats b/tests/unit/builder-pack.bats index 46e13eeb5..ddc8b966b 100644 --- a/tests/unit/builder-pack.bats +++ b/tests/unit/builder-pack.bats @@ -15,6 +15,11 @@ teardown() { } @test "(builder-pack:set)" { + run /bin/bash -c "dokku config:set $TEST_APP SECRET_KEY=fjdkslafjdk" + echo "output: $output" + echo "status: $status" + assert_success + run /bin/bash -c "dokku builder:set $TEST_APP selected pack" echo "output: $output" echo "status: $status" @@ -31,6 +36,7 @@ teardown() { assert_success assert_output_contains 'Building with buildpack 1' 0 assert_output_contains 'Installing requirements with pip' + assert_output_contains "Build time env var SECRET_KEY=fjdkslafjdk" run /bin/bash -c "dokku builder-pack:set $TEST_APP projecttoml-path nonexistent.toml" echo "output: $output"