diff --git a/plugins/00_dokku-standard/commands b/plugins/00_dokku-standard/commands index 15e59075487..b72507d7bc5 100755 --- a/plugins/00_dokku-standard/commands +++ b/plugins/00_dokku-standard/commands @@ -134,9 +134,11 @@ case "$1" in shift 2 - DOKKU_APP_RM_CONTAINER=$(dokku config:get $APP DOKKU_RM_CONTAINER || true) - DOKKU_GLOBAL_RM_CONTAINER=$(dokku config:get --global DOKKU_RM_CONTAINER || true) - DOKKU_RM_CONTAINER=${DOKKU_APP_RM_CONTAINER:="$DOKKU_GLOBAL_RM_CONTAINER"} + if [[ -z "$DOKKU_RM_CONTAINER" ]]; then + DOKKU_APP_RM_CONTAINER=$(dokku config:get $APP DOKKU_RM_CONTAINER || true) + DOKKU_GLOBAL_RM_CONTAINER=$(dokku config:get --global DOKKU_RM_CONTAINER || true) + DOKKU_RM_CONTAINER=${DOKKU_APP_RM_CONTAINER:="$DOKKU_GLOBAL_RM_CONTAINER"} + fi DOCKER_ARGS=$(: | plugn trigger docker-args-run $APP $IMAGE_TAG) [[ "$DOKKU_TRACE" ]] && DOCKER_ARGS+=" -e TRACE=true " diff --git a/tests/unit/10_core_1.bats b/tests/unit/10_core_1.bats index 01b9d652e1c..71ca38a794d 100644 --- a/tests/unit/10_core_1.bats +++ b/tests/unit/10_core_1.bats @@ -10,6 +10,7 @@ teardown() { rm -rf /home/dokku/$TEST_APP/tls /home/dokku/tls destroy_app disable_tls_wildcard + dokku config:unset --global DOKKU_RM_CONTAINER } assert_urls() { @@ -42,6 +43,7 @@ build_nginx_config() { echo "status: "$status assert_success sleep 5 # wait for dokku cleanup to happen in the background + run bash -c "docker ps -a -f 'status=exited' --no-trunc=false | grep '/exec hostname'" echo "output: "$output echo "status: "$status @@ -52,6 +54,57 @@ build_nginx_config() { assert_output "" } +@test "(core) run (with DOKKU_RM_CONTAINER/--rm-container)" { + deploy_app + + run bash -c "dokku --rm-container run $TEST_APP hostname" + echo "output: "$output + echo "status: "$status + assert_success + run bash -c "docker ps -a -f 'status=exited' --no-trunc=false | grep '/exec hostname'" + echo "output: "$output + echo "status: "$status + assert_failure + + run bash -c "dokku config:set --no-restart $TEST_APP DOKKU_RM_CONTAINER=1" + echo "output: "$output + echo "status: "$status + assert_success + + run bash -c "dokku --rm-container run $TEST_APP hostname" + echo "output: "$output + echo "status: "$status + assert_success + run bash -c "docker ps -a -f 'status=exited' --no-trunc=false | grep '/exec hostname'" + echo "output: "$output + echo "status: "$status + assert_failure + + run bash -c "dokku config:unset --no-restart $TEST_APP DOKKU_RM_CONTAINER" + echo "output: "$output + echo "status: "$status + assert_success + + run bash -c "dokku config:set --global DOKKU_RM_CONTAINER=1" + echo "output: "$output + echo "status: "$status + assert_success + + run bash -c "dokku --rm-container run $TEST_APP hostname" + echo "output: "$output + echo "status: "$status + assert_success + run bash -c "docker ps -a -f 'status=exited' --no-trunc=false | grep '/exec hostname'" + echo "output: "$output + echo "status: "$status + assert_failure + + run bash -c "dokku config:unset --global DOKKU_RM_CONTAINER" + echo "output: "$output + echo "status: "$status + assert_success +} + @test "(core) run (with tty)" { deploy_app run /bin/bash -c "dokku run $TEST_APP ls /app/package.json" @@ -67,4 +120,3 @@ build_nginx_config() { echo "status: "$status assert_success } -