From 0963c403ab2eafc42cd5f31ba666866f8134dcff Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Wed, 10 Feb 2021 11:18:08 -0500 Subject: [PATCH 01/11] refactor: simplify container creation call --- .../scheduler-docker-local/scheduler-deploy | 34 ++++++++----------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/plugins/scheduler-docker-local/scheduler-deploy b/plugins/scheduler-docker-local/scheduler-deploy index f7dfc6d94..f487a4920 100755 --- a/plugins/scheduler-docker-local/scheduler-deploy +++ b/plugins/scheduler-docker-local/scheduler-deploy @@ -17,7 +17,7 @@ trigger-scheduler-docker-local-scheduler-deploy() { rm -f "${DOKKU_LIB_ROOT}/data/scheduler-docker-local/$APP/failed-containers" - local DOCKER_RUN_LABEL_ARGS="--label=com.dokku.app-name=$APP" + local DOCKER_RUN_LABEL_ARGS="--label=com.dokku.app-name=$APP --label=com.dokku.container-type=deploy" local DOKKU_DOCKER_STOP_TIMEOUT DOKKU_HEROKUISH DOKKU_NETWORK_BIND_ALL IMAGE DOKKU_HEROKUISH=false IMAGE=$(get_deploying_app_image_name "$APP" "$IMAGE_TAG") @@ -72,43 +72,37 @@ trigger-scheduler-docker-local-scheduler-deploy() { # start the app local DOCKER_ARGS DOCKER_ARGS=$(: | plugn trigger docker-args-deploy "$APP" "$IMAGE_TAG" "$PROC_TYPE" "$CONTAINER_INDEX") + DOCKER_ARGS+=" --label=com.dokku.process-type=$PROC_TYPE --label=com.dokku.dyno=$DYNO " DOCKER_ARGS+=" -e DYNO=$DYNO " + DOCKER_ARGS+=" --init " + DOCKER_ARGS+=" $DOCKER_RUN_LABEL_ARGS $DOKKU_GLOBAL_RUN_ARGS " DOCKER_ARGS+=$(: | plugn trigger docker-args-process-deploy "$APP" "$IMAGE_SOURCE_TYPE" "$IMAGE_TAG" "$PROC_TYPE" "$CONTAINER_INDEX") [[ "$DOKKU_TRACE" ]] && DOCKER_ARGS+=" -e TRACE=true " - declare -a ARG_ARRAY - eval "ARG_ARRAY=($DOCKER_ARGS)" - local START_CMD [[ "$DOKKU_HEROKUISH" == "true" ]] && START_CMD="/start $PROC_TYPE" [[ -n "$DOKKU_START_CMD" ]] && START_CMD="$DOKKU_START_CMD" + local DOKKU_PORT="" if [[ "$PROC_TYPE" == "web" ]]; then ports=($(plugn trigger network-compute-ports "$APP" "$PROC_TYPE" "$DOKKU_HEROKUISH" "$CONTAINER_INDEX")) local DOKKU_DOCKER_PORT_ARGS="" - local DOKKU_PORT="" for p in "${ports[@]}"; do if [[ ! "$p" =~ .*udp.* ]]; then DOKKU_PORT=${DOKKU_PORT:="$p"} fi - DOKKU_DOCKER_PORT_ARGS+=" -p $p " + + if [[ "$DOKKU_NETWORK_BIND_ALL" == "true" ]]; then + DOCKER_ARGS+=" -p $p " + fi done - - START_CMD=$(fn-scheduler-docker-local-extract-start-cmd "$APP" "$PROC_TYPE" "$START_CMD" "$DOKKU_HEROKUISH" "$DOKKU_PORT") - if [[ "$DOKKU_NETWORK_BIND_ALL" == "false" ]]; then - # shellcheck disable=SC2086 - cid=$("$DOCKER_BIN" container create --label=com.dokku.container-type=deploy --label=com.dokku.process-type=$PROC_TYPE --label=com.dokku.dyno=$DYNO "${DOCKER_RUN_LABEL_ARGS[@]}" $DOKKU_GLOBAL_RUN_ARGS --init --env PORT=$DOKKU_PORT "${ARG_ARRAY[@]}" $IMAGE $START_CMD) - else - # shellcheck disable=SC2086 - cid=$("$DOCKER_BIN" container create --label=com.dokku.container-type=deploy --label=com.dokku.process-type=$PROC_TYPE --label=com.dokku.dyno=$DYNO "${DOCKER_RUN_LABEL_ARGS[@]}" $DOKKU_GLOBAL_RUN_ARGS --init $DOKKU_DOCKER_PORT_ARGS --env PORT=$DOKKU_PORT "${ARG_ARRAY[@]}" $IMAGE $START_CMD) - fi - else - START_CMD=$(fn-scheduler-docker-local-extract-start-cmd "$APP" "$PROC_TYPE" "$START_CMD" "$DOKKU_HEROKUISH") - - # shellcheck disable=SC2086 - cid=$("$DOCKER_BIN" container create --label=com.dokku.container-type=deploy --label=com.dokku.process-type=$PROC_TYPE --label=com.dokku.dyno=$DYNO "${DOCKER_RUN_LABEL_ARGS[@]}" $DOKKU_GLOBAL_RUN_ARGS --init --env PORT=$DOKKU_PORT "${ARG_ARRAY[@]}" $IMAGE $START_CMD) fi + DOCKER_ARGS+=" --env PORT=$DOKKU_PORT " + START_CMD=$(fn-scheduler-docker-local-extract-start-cmd "$APP" "$PROC_TYPE" "$START_CMD" "$DOKKU_HEROKUISH" "$DOKKU_PORT") + # shellcheck disable=SC2086 + cid=$("$DOCKER_BIN" container create $DOCKER_ARGS $IMAGE $START_CMD) + plugn trigger post-container-create "app" "$cid" "$APP" "deploy" "$PROC_TYPE" "$DOCKER_BIN" container start "$cid" >/dev/null || true From 25ab915883c976d58793e44651955b739a0d9821 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Thu, 11 Feb 2021 02:21:16 -0500 Subject: [PATCH 02/11] refactor: standardize on using long-form and equal sign for docker arguments --- plugins/builder-herokuish/builder-build | 4 ++-- plugins/logs/triggers.go | 2 +- plugins/scheduler-docker-local/scheduler-deploy | 6 +++--- tests/unit/logs.bats | 6 +++--- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/plugins/builder-herokuish/builder-build b/plugins/builder-herokuish/builder-build index b3b67465f..74d989cc7 100755 --- a/plugins/builder-herokuish/builder-build +++ b/plugins/builder-herokuish/builder-build @@ -47,14 +47,14 @@ trigger-builder-herokuish-builder-build() { plugn trigger pre-build-buildpack "$APP" "$SOURCECODE_WORK_DIR" local DOCKER_ARGS=$(: | plugn trigger docker-args-build "$APP" "$BUILDER_TYPE") - [[ "$DOKKU_TRACE" ]] && DOCKER_ARGS+=" -e TRACE=true " + [[ "$DOKKU_TRACE" ]] && DOCKER_ARGS+=" --env=TRACE=true " DOCKER_ARGS+=$(: | plugn trigger docker-args-process-build "$APP" "$BUILDER_TYPE") declare -a ARG_ARRAY eval "ARG_ARRAY=($DOCKER_ARGS)" local DOKKU_CONTAINER_EXIT_CODE=0 - local CID=$("$DOCKER_BIN" container create "${DOCKER_RUN_LABEL_ARGS[@]}" $DOKKU_GLOBAL_RUN_ARGS -v $DOKKU_APP_HOST_CACHE_DIR:/cache -e CACHE_PATH=/cache "${ARG_ARRAY[@]}" $IMAGE /build) + local CID=$("$DOCKER_BIN" container create "${DOCKER_RUN_LABEL_ARGS[@]}" $DOKKU_GLOBAL_RUN_ARGS -v $DOKKU_APP_HOST_CACHE_DIR:/cache --env=CACHE_PATH=/cache "${ARG_ARRAY[@]}" $IMAGE /build) plugn trigger post-container-create "app" "$CID" "$APP" "build" "$DOCKER_BIN" container start "$CID" >/dev/null || DOKKU_CONTAINER_EXIT_CODE=$? "$DOCKER_BIN" container attach "$CID" diff --git a/plugins/logs/triggers.go b/plugins/logs/triggers.go index fdadb55b7..31c829b50 100644 --- a/plugins/logs/triggers.go +++ b/plugins/logs/triggers.go @@ -49,7 +49,7 @@ func TriggerDockerArgsProcessDeploy(appName string) error { } if maxSize != "unlimited" { - fmt.Printf(" --log-opt max-size=%s ", maxSize) + fmt.Printf(" --log-opt=max-size=%s ", maxSize) } } diff --git a/plugins/scheduler-docker-local/scheduler-deploy b/plugins/scheduler-docker-local/scheduler-deploy index f487a4920..67c45dc9b 100755 --- a/plugins/scheduler-docker-local/scheduler-deploy +++ b/plugins/scheduler-docker-local/scheduler-deploy @@ -73,11 +73,11 @@ trigger-scheduler-docker-local-scheduler-deploy() { local DOCKER_ARGS DOCKER_ARGS=$(: | plugn trigger docker-args-deploy "$APP" "$IMAGE_TAG" "$PROC_TYPE" "$CONTAINER_INDEX") DOCKER_ARGS+=" --label=com.dokku.process-type=$PROC_TYPE --label=com.dokku.dyno=$DYNO " - DOCKER_ARGS+=" -e DYNO=$DYNO " + DOCKER_ARGS+=" --env=DYNO=$DYNO " DOCKER_ARGS+=" --init " DOCKER_ARGS+=" $DOCKER_RUN_LABEL_ARGS $DOKKU_GLOBAL_RUN_ARGS " DOCKER_ARGS+=$(: | plugn trigger docker-args-process-deploy "$APP" "$IMAGE_SOURCE_TYPE" "$IMAGE_TAG" "$PROC_TYPE" "$CONTAINER_INDEX") - [[ "$DOKKU_TRACE" ]] && DOCKER_ARGS+=" -e TRACE=true " + [[ "$DOKKU_TRACE" ]] && DOCKER_ARGS+=" --env=TRACE=true " local START_CMD [[ "$DOKKU_HEROKUISH" == "true" ]] && START_CMD="/start $PROC_TYPE" @@ -98,7 +98,7 @@ trigger-scheduler-docker-local-scheduler-deploy() { done fi - DOCKER_ARGS+=" --env PORT=$DOKKU_PORT " + DOCKER_ARGS+=" --env=PORT=$DOKKU_PORT " START_CMD=$(fn-scheduler-docker-local-extract-start-cmd "$APP" "$PROC_TYPE" "$START_CMD" "$DOKKU_HEROKUISH" "$DOKKU_PORT") # shellcheck disable=SC2086 cid=$("$DOCKER_BIN" container create $DOCKER_ARGS $IMAGE $START_CMD) diff --git a/tests/unit/logs.bats b/tests/unit/logs.bats index f0ec2747e..70677b00e 100644 --- a/tests/unit/logs.bats +++ b/tests/unit/logs.bats @@ -385,7 +385,7 @@ teardown() { echo "output: $output" echo "status: $status" assert_success - assert_output "--log-opt max-size=20m" + assert_output "--log-opt=max-size=20m" run /bin/bash -c "dokku docker-options:add $TEST_APP deploy --log-driver=local" 2>&1 echo "output: $output" @@ -396,7 +396,7 @@ teardown() { echo "output: $output" echo "status: $status" assert_success - assert_output "--log-opt max-size=20m" + assert_output "--log-opt=max-size=20m" run /bin/bash -c "dokku docker-options:add $TEST_APP deploy --log-driver=json-file" 2>&1 echo "output: $output" @@ -407,7 +407,7 @@ teardown() { echo "output: $output" echo "status: $status" assert_success - assert_output "--log-opt max-size=20m" + assert_output "--log-opt=max-size=20m" run /bin/bash -c "dokku docker-options:add $TEST_APP deploy --log-driver=journald" 2>&1 echo "output: $output" From 82afae644720f92d9f1369dfa866505881336b5e Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Thu, 11 Feb 2021 02:21:29 -0500 Subject: [PATCH 03/11] tests: add missing assertion --- tests/unit/docker-options.bats | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/unit/docker-options.bats b/tests/unit/docker-options.bats index e5b911b18..4ac48686a 100644 --- a/tests/unit/docker-options.bats +++ b/tests/unit/docker-options.bats @@ -303,9 +303,14 @@ teardown() { echo "output: $output" echo "status: $status" assert_success + run /bin/bash -c "dokku docker-options:add $TEST_APP build \"--link postgres\"" echo "output: $output" echo "status: $status" assert_success - deploy_app dockerfile + + run deploy_app dockerfile + echo "output: $output" + echo "status: $status" + assert_success } From 49a2f8ab823a6d3a9f12e4939eafdc88c8b5b5c8 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Thu, 11 Feb 2021 02:21:43 -0500 Subject: [PATCH 04/11] fix: properly specify as argument array --- plugins/scheduler-docker-local/scheduler-deploy | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/plugins/scheduler-docker-local/scheduler-deploy b/plugins/scheduler-docker-local/scheduler-deploy index 67c45dc9b..0c6887a69 100755 --- a/plugins/scheduler-docker-local/scheduler-deploy +++ b/plugins/scheduler-docker-local/scheduler-deploy @@ -99,9 +99,11 @@ trigger-scheduler-docker-local-scheduler-deploy() { fi DOCKER_ARGS+=" --env=PORT=$DOKKU_PORT " + declare -a ARG_ARRAY + eval "ARG_ARRAY=($DOCKER_ARGS)" + START_CMD=$(fn-scheduler-docker-local-extract-start-cmd "$APP" "$PROC_TYPE" "$START_CMD" "$DOKKU_HEROKUISH" "$DOKKU_PORT") - # shellcheck disable=SC2086 - cid=$("$DOCKER_BIN" container create $DOCKER_ARGS $IMAGE $START_CMD) + cid=$("$DOCKER_BIN" container create "${ARG_ARRAY[@]}" "$IMAGE" $START_CMD) plugn trigger post-container-create "app" "$cid" "$APP" "deploy" "$PROC_TYPE" "$DOCKER_BIN" container start "$cid" >/dev/null || true From d7562d36e6a2e0aabc6ceeae941e36173623ab5c Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Thu, 11 Feb 2021 03:48:42 -0500 Subject: [PATCH 05/11] chore: drop unused destroy --- tests/unit/ps-herokuish-1.bats | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/unit/ps-herokuish-1.bats b/tests/unit/ps-herokuish-1.bats index c6002ef66..10178ca21 100644 --- a/tests/unit/ps-herokuish-1.bats +++ b/tests/unit/ps-herokuish-1.bats @@ -9,7 +9,6 @@ setup() { teardown() { destroy_app - destroy_app 0 "$MYAPP" || true global_teardown } From 33d5dd44d9083062149270551ccce4ce1f25ff34 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Thu, 11 Feb 2021 03:49:46 -0500 Subject: [PATCH 06/11] refactor: pull container creation into standalone function this is necessary for us to be able to inject env vars into the call. --- plugins/scheduler-docker-local/scheduler-deploy | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/plugins/scheduler-docker-local/scheduler-deploy b/plugins/scheduler-docker-local/scheduler-deploy index 0c6887a69..9e5bbd691 100755 --- a/plugins/scheduler-docker-local/scheduler-deploy +++ b/plugins/scheduler-docker-local/scheduler-deploy @@ -99,11 +99,12 @@ trigger-scheduler-docker-local-scheduler-deploy() { fi DOCKER_ARGS+=" --env=PORT=$DOKKU_PORT " - declare -a ARG_ARRAY - eval "ARG_ARRAY=($DOCKER_ARGS)" START_CMD=$(fn-scheduler-docker-local-extract-start-cmd "$APP" "$PROC_TYPE" "$START_CMD" "$DOKKU_HEROKUISH" "$DOKKU_PORT") - cid=$("$DOCKER_BIN" container create "${ARG_ARRAY[@]}" "$IMAGE" $START_CMD) + DOCKER_ARGS+=" $IMAGE " + DOCKER_ARGS+=" $START_CMD " + + cid=$(fn-start-app-container "$DOCKER_ARGS") plugn trigger post-container-create "app" "$cid" "$APP" "deploy" "$PROC_TYPE" "$DOCKER_BIN" container start "$cid" >/dev/null || true @@ -215,4 +216,13 @@ fn-scheduler-docker-local-extract-start-cmd() { echo "$START_CMD" } +fn-start-app-container() { + declare desc="starts a single app container" + declare DOCKER_ARGS="$1" + + declare -a __DOKKU_DOCKER_ARG_ARRAY + eval "__DOKKU_DOCKER_ARG_ARRAY=($DOCKER_ARGS)" + "$DOCKER_BIN" container create "${__DOKKU_DOCKER_ARG_ARRAY[@]}" +} + trigger-scheduler-docker-local-scheduler-deploy "$@" From 5921692f83d30b1ef39d0e8407c3c31e3a352360 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Thu, 11 Feb 2021 03:50:51 -0500 Subject: [PATCH 07/11] feat: add ability to export env vars as a `--env=key ...` string --- plugins/config/environment.go | 16 +++++++++++++++- plugins/config/environment_test.go | 1 + plugins/config/src/subcommands/subcommands.go | 2 +- plugins/config/subcommands.go | 15 ++++++++------- 4 files changed, 25 insertions(+), 9 deletions(-) diff --git a/plugins/config/environment.go b/plugins/config/environment.go index 23e639eda..d4a96b3ee 100644 --- a/plugins/config/environment.go +++ b/plugins/config/environment.go @@ -24,8 +24,10 @@ const ( ExportFormatExports ExportFormat = iota //ExportFormatEnvfile format: dotenv file ExportFormatEnvfile - //ExportFormatDockerArgs format: --env args for docker + //ExportFormatDockerArgs format: --env KEY=VALUE args for docker ExportFormatDockerArgs + //ExportFormatDockerArgsKeys format: --env KEY args for docker + ExportFormatDockerArgsKeys //ExportFormatShell format: env arguments for shell ExportFormatShell //ExportFormatPretty format: pretty-printed in columns @@ -171,6 +173,8 @@ func (e *Env) Export(format ExportFormat) string { return e.EnvfileString() case ExportFormatDockerArgs: return e.DockerArgsString() + case ExportFormatDockerArgsKeys: + return e.DockerArgsKeysString() case ExportFormatShell: return e.ShellString() case ExportFormatPretty: @@ -201,6 +205,16 @@ func (e *Env) DockerArgsString() string { return e.stringWithPrefixAndSeparator("--env=", " ") } +//DockerArgsStringKeys gets the contents of this Env in the form -env=KEY --env... +func (e *Env) DockerArgsKeysString() 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, " ") +} + //JSONString returns the contents of this Env as a key/value json object func (e *Env) JSONString() string { data, err := json.Marshal(e.Map()) diff --git a/plugins/config/environment_test.go b/plugins/config/environment_test.go index 8f87a4a3b..dbe0bf744 100644 --- a/plugins/config/environment_test.go +++ b/plugins/config/environment_test.go @@ -54,6 +54,7 @@ func TestExport(t *testing.T) { e, _ := newEnvFromString("BAR='BAZ'\nFOO='b'ar '\nBAZ='a\\nb'") Expect(e.Export(ExportFormatEnvfile)).To(Equal("BAR=\"BAZ\"\nBAZ=\"a\\nb\"\nFOO=\"b'ar \"")) Expect(e.Export(ExportFormatDockerArgs)).To(Equal("--env=BAR='BAZ' --env=BAZ='a\nb' --env=FOO='b'\\''ar '")) + Expect(e.Export(ExportFormatDockerArgsKeys)).To(Equal("--env=BAR --env=BAZ --env=FOO")) Expect(e.Export(ExportFormatShell)).To(Equal("BAR='BAZ' BAZ='a\nb' FOO='b'\\''ar '")) Expect(e.Export(ExportFormatExports)).To(Equal("export BAR='BAZ'\nexport BAZ='a\nb'\nexport FOO='b'\\''ar '")) Expect(e.Export(ExportFormatPretty)).To(Equal("BAR: BAZ\nBAZ: a\nb\nFOO: b'ar")) diff --git a/plugins/config/src/subcommands/subcommands.go b/plugins/config/src/subcommands/subcommands.go index 0ad64a674..ae543e1ab 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 | shell | pretty | json | json-list ] which format to export as)") + format := args.String("format", "exports", "--format: [ exports | envfile | docker-args | docker-args-keys | shell | pretty | json | json-list ] which format to export as)") args.Parse(os.Args[2:]) if !*global { appName = args.Arg(0) diff --git a/plugins/config/subcommands.go b/plugins/config/subcommands.go index 331deb165..fdf30af52 100644 --- a/plugins/config/subcommands.go +++ b/plugins/config/subcommands.go @@ -43,13 +43,14 @@ func CommandExport(appName string, global bool, merged bool, format string) erro suffix := "\n" exportTypes := map[string]ExportFormat{ - "exports": ExportFormatExports, - "envfile": ExportFormatEnvfile, - "docker-args": ExportFormatDockerArgs, - "shell": ExportFormatShell, - "pretty": ExportFormatPretty, - "json": ExportFormatJSON, - "json-list": ExportFormatJSONList, + "exports": ExportFormatExports, + "envfile": ExportFormatEnvfile, + "docker-args": ExportFormatDockerArgs, + "docker-args-keys": ExportFormatDockerArgsKeys, + "shell": ExportFormatShell, + "pretty": ExportFormatPretty, + "json": ExportFormatJSON, + "json-list": ExportFormatJSONList, } exportType, ok := exportTypes[format] From 812e34c6f54859920dafc9a28ddeba7b8aa75a3a Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Thu, 11 Feb 2021 03:52:02 -0500 Subject: [PATCH 08/11] feat: properly export env vars for cnb apps They are not baked into the image like they are for herokuish, so we need to manually set them via --env. Additionally, due to newline constraints in docker, we need to use `--env=key` format to correctly pull the values into place. --- plugins/config/docker-args-deploy | 4 +-- .../scheduler-docker-local/scheduler-deploy | 1 + tests/apps/python/web.py | 8 ++++- tests/unit/ps-cnb.bats | 31 +++++++++++++++++++ tests/unit/test_helper.bash | 7 +++++ 5 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 tests/unit/ps-cnb.bats diff --git a/plugins/config/docker-args-deploy b/plugins/config/docker-args-deploy index 1f1e53579..53f44fd70 100755 --- a/plugins/config/docker-args-deploy +++ b/plugins/config/docker-args-deploy @@ -14,8 +14,8 @@ trigger-config-docker-args() { STDIN=$(cat) trigger="$0 config_docker_args" - if ! is_image_herokuish_based "$IMAGE" "$APP"; then - ENV_ARGS="$(config_export app "$APP" --format docker-args --merged)" + if ! is_image_herokuish_based "$IMAGE" "$APP" || is_image_cnb_based "$IMAGE"; then + ENV_ARGS="$(config_export app "$APP" --format docker-args-keys --merged)" echo -n "$STDIN $ENV_ARGS" else echo -n "$STDIN" diff --git a/plugins/scheduler-docker-local/scheduler-deploy b/plugins/scheduler-docker-local/scheduler-deploy index 9e5bbd691..521afc1a8 100755 --- a/plugins/scheduler-docker-local/scheduler-deploy +++ b/plugins/scheduler-docker-local/scheduler-deploy @@ -222,6 +222,7 @@ fn-start-app-container() { declare -a __DOKKU_DOCKER_ARG_ARRAY eval "__DOKKU_DOCKER_ARG_ARRAY=($DOCKER_ARGS)" + eval "$(config_export app "$APP")" "$DOCKER_BIN" container create "${__DOKKU_DOCKER_ARG_ARRAY[@]}" } diff --git a/tests/apps/python/web.py b/tests/apps/python/web.py index b3e8ef728..c7c3d36a3 100644 --- a/tests/apps/python/web.py +++ b/tests/apps/python/web.py @@ -1,4 +1,5 @@ import http.server +import json import os @@ -7,7 +8,12 @@ class GetHandler(http.server.BaseHTTPRequestHandler): self.send_response(200) self.send_header("Content-Type", "text/plain; charset=utf-8") self.end_headers() - self.wfile.write("python/http.server".encode("utf-8")) + + if self.path == '/': + self.wfile.write("python/http.server".encode("utf-8")) + else: + data = json.dumps(dict(os.environ), sort_keys=True, indent=4) + self.wfile.write(data.encode("utf-8")) if __name__ == "__main__": diff --git a/tests/unit/ps-cnb.bats b/tests/unit/ps-cnb.bats new file mode 100644 index 000000000..e12483e66 --- /dev/null +++ b/tests/unit/ps-cnb.bats @@ -0,0 +1,31 @@ +#!/usr/bin/env bats + +load test_helper + +setup() { + global_setup + create_app +} + +teardown() { + destroy_app + global_teardown +} + +@test "(ps) cnb env vars" { + run /bin/bash -c "dokku config:set $TEST_APP DOKKU_CNB_EXPERIMENTAL=1" + echo "output: $output" + echo "status: $status" + assert_success + + run deploy_app python dokku@dokku.me:$TEST_APP add_requirements_txt + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "curl $(dokku url $TEST_APP)/env" + echo "output: $output" + echo "status: $status" + assert_success + assert_output_contains '"DOKKU_CNB_EXPERIMENTAL": "1"' +} diff --git a/tests/unit/test_helper.bash b/tests/unit/test_helper.bash index 8d693fd9d..816fa98a4 100644 --- a/tests/unit/test_helper.bash +++ b/tests/unit/test_helper.bash @@ -513,6 +513,13 @@ add_release_command() { echo "release: touch /app/release.test" >> "$APP_REPO_DIR/Procfile" } +add_requirements_txt() { + local APP="$1" + local APP_REPO_DIR="$2" + [[ -z "$APP" ]] && local APP="$TEST_APP" + echo "flask" >> "$APP_REPO_DIR/requirements.txt" +} + build_nginx_config() { # simulate nginx post-deploy dokku domains:setup "$TEST_APP" From 031159c1b9740f0f411a2cd78cd5ac56d7e563df Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Thu, 11 Feb 2021 04:02:06 -0500 Subject: [PATCH 09/11] fix: correct dockblock --- plugins/config/environment.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/config/environment.go b/plugins/config/environment.go index d4a96b3ee..2b4602f0b 100644 --- a/plugins/config/environment.go +++ b/plugins/config/environment.go @@ -205,7 +205,7 @@ func (e *Env) DockerArgsString() string { return e.stringWithPrefixAndSeparator("--env=", " ") } -//DockerArgsStringKeys gets the contents of this Env in the form -env=KEY --env... +//DockerArgsKeysString gets the contents of this Env in the form -env=KEY --env... func (e *Env) DockerArgsKeysString() string { keys := e.Keys() entries := make([]string, len(keys)) From 681fd6abf60f34fbfaf50b8dadada305779a9d89 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Thu, 11 Feb 2021 04:04:25 -0500 Subject: [PATCH 10/11] fix: install pack for tests --- tests/unit/ps-cnb.bats | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/unit/ps-cnb.bats b/tests/unit/ps-cnb.bats index e12483e66..b7045ee9a 100644 --- a/tests/unit/ps-cnb.bats +++ b/tests/unit/ps-cnb.bats @@ -2,6 +2,12 @@ load test_helper +setup_file() { + add-apt-repository --yes ppa:cncf-buildpacks/pack-cli + apt-get update + apt-get --yes install pack-cli +} + setup() { global_setup create_app From 1568fc78274e6f34d60814f0265d9e7a8877cbe5 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Thu, 11 Feb 2021 04:21:08 -0500 Subject: [PATCH 11/11] refactor: only special case cnb for now --- plugins/config/docker-args-deploy | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/plugins/config/docker-args-deploy b/plugins/config/docker-args-deploy index 53f44fd70..c429e3a83 100755 --- a/plugins/config/docker-args-deploy +++ b/plugins/config/docker-args-deploy @@ -14,9 +14,15 @@ trigger-config-docker-args() { STDIN=$(cat) trigger="$0 config_docker_args" - if ! is_image_herokuish_based "$IMAGE" "$APP" || is_image_cnb_based "$IMAGE"; then + if is_image_cnb_based "$IMAGE"; then ENV_ARGS="$(config_export app "$APP" --format docker-args-keys --merged)" echo -n "$STDIN $ENV_ARGS" + return + fi + + if ! is_image_herokuish_based "$IMAGE" "$APP"; then + ENV_ARGS="$(config_export app "$APP" --format docker-args --merged)" + echo -n "$STDIN $ENV_ARGS" else echo -n "$STDIN" fi