From dbc3d8201773805d3203b74a6e769e36f99f48d9 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Tue, 27 Jul 2021 01:37:51 -0400 Subject: [PATCH 01/12] refactor: move run command to it's own plugin --- dokku | 2 +- plugins/00_dokku-standard/commands | 4 +- plugins/00_dokku-standard/help-functions | 1 - plugins/run/commands | 16 ++++++++ plugins/run/help-functions | 32 +++++++++++++++ .../run => run/internal-functions} | 17 +++++--- plugins/run/plugin.toml | 4 ++ plugins/run/subcommands/default | 6 +++ tests/unit/core_2.bats | 20 --------- tests/unit/run_1.bats | 41 +++++++++++++++++++ tests/unit/{core_3.bats => run_2.bats} | 3 -- 11 files changed, 113 insertions(+), 33 deletions(-) create mode 100755 plugins/run/commands create mode 100755 plugins/run/help-functions rename plugins/{00_dokku-standard/subcommands/run => run/internal-functions} (94%) create mode 100644 plugins/run/plugin.toml create mode 100755 plugins/run/subcommands/default create mode 100644 tests/unit/run_1.bats rename tests/unit/{core_3.bats => run_2.bats} (96%) diff --git a/dokku b/dokku index 59b712280..c90749787 100755 --- a/dokku +++ b/dokku @@ -141,7 +141,7 @@ execute_dokku_cmd() { nginx | nginx:*) local PLUGIN_NAME=${PLUGIN_NAME/nginx/nginx-vhosts} ;; - deploy | run | cleanup | url | urls | report) + deploy | cleanup | url | urls | report) local PLUGIN_NAME="00_dokku-standard" ;; esac diff --git a/plugins/00_dokku-standard/commands b/plugins/00_dokku-standard/commands index 56b37905c..ace188e6d 100755 --- a/plugins/00_dokku-standard/commands +++ b/plugins/00_dokku-standard/commands @@ -1,11 +1,11 @@ #!/usr/bin/env bash -[[ " help help:help cleanup:help run:help url:help urls:help version:help " == *" $1 "* ]] || exit "$DOKKU_NOT_IMPLEMENTED_EXIT" +[[ " help help:help cleanup:help url:help urls:help version:help " == *" $1 "* ]] || exit "$DOKKU_NOT_IMPLEMENTED_EXIT" source "$PLUGIN_AVAILABLE_PATH/00_dokku-standard/help-functions" set -eo pipefail [[ $DOKKU_TRACE ]] && set -x case "$1" in - help | cleanup:help | run:help | url:help | urls:help | version:help) + help | cleanup:help | url:help | urls:help | version:help) cmd-standard-help "$@" ;; diff --git a/plugins/00_dokku-standard/help-functions b/plugins/00_dokku-standard/help-functions index 2c8bceef3..7f9f22b54 100755 --- a/plugins/00_dokku-standard/help-functions +++ b/plugins/00_dokku-standard/help-functions @@ -18,7 +18,6 @@ fn-help-content() { declare desc="return help content" cat <], Cleans up exited/dead Docker containers and removes dangling images - run [--env KEY=VALUE] , Run a command in a new container using the current application image url , Show the first URL for an application (compatibility) urls , Show all URLs for an application version , Print dokku's version diff --git a/plugins/run/commands b/plugins/run/commands new file mode 100755 index 000000000..3096db561 --- /dev/null +++ b/plugins/run/commands @@ -0,0 +1,16 @@ +#!/usr/bin/env bash +[[ " help run:help " == *" $1 "* ]] || exit "$DOKKU_NOT_IMPLEMENTED_EXIT" +source "$PLUGIN_AVAILABLE_PATH/run/help-functions" +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x + +case "$1" in + help | run:help) + cmd-run-help "$@" + ;; + + *) + exit "$DOKKU_NOT_IMPLEMENTED_EXIT" + ;; + +esac diff --git a/plugins/run/help-functions b/plugins/run/help-functions new file mode 100755 index 000000000..12db5bc05 --- /dev/null +++ b/plugins/run/help-functions @@ -0,0 +1,32 @@ +#!/usr/bin/env bash +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x + +cmd-run-help() { + declare desc="help command" + declare CMD="$1" + local plugin_name="run" + local plugin_description="Run a one-off process inside a container" + + if [[ "$CMD" == "${plugin_name}:help" ]]; then + echo -e "Usage: dokku ${plugin_name}[:COMMAND]" + echo '' + echo "$plugin_description" + echo '' + echo 'Additional commands:' + fn-help-content | sort | column -c2 -t -s, + elif [[ $(ps -o command= $PPID) == *"--all"* ]]; then + fn-help-content + else + cat < , Run a command in a new container using the current application image +help_content +} diff --git a/plugins/00_dokku-standard/subcommands/run b/plugins/run/internal-functions similarity index 94% rename from plugins/00_dokku-standard/subcommands/run rename to plugins/run/internal-functions index 0cfd97888..814ce6cf5 100755 --- a/plugins/00_dokku-standard/subcommands/run +++ b/plugins/run/internal-functions @@ -1,12 +1,11 @@ #!/usr/bin/env bash set -eo pipefail -[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" +[[ $DOKKU_TRACE ]] && set -x + +fn-run() { + declare desc="runs command in container" -cmd-run() { - declare desc="runs command in container based on app image" - declare cmd="run" - [[ "$1" == "$cmd" ]] && shift 1 declare APP="" local SCHEDULER_ID declare -a RUN_ENV @@ -53,4 +52,10 @@ cmd-run() { DOKKU_CRON_ID="$CRON_ID" plugn trigger scheduler-run "$DOKKU_SCHEDULER" "$APP" "${#RUN_ENV[@]}" "${RUN_ENV[@]}" "$@" } -cmd-run "$@" +cmd-run() { + declare desc="runs command in container based on app image" + declare cmd="run" + [[ "$1" == "$cmd" ]] && shift 1 + + fn-run "$@" +} diff --git a/plugins/run/plugin.toml b/plugins/run/plugin.toml new file mode 100644 index 000000000..3ded5e429 --- /dev/null +++ b/plugins/run/plugin.toml @@ -0,0 +1,4 @@ +[plugin] +description = "dokku core run plugin" +version = "0.24.10" +[plugin.config] diff --git a/plugins/run/subcommands/default b/plugins/run/subcommands/default new file mode 100755 index 000000000..66d4a5dd7 --- /dev/null +++ b/plugins/run/subcommands/default @@ -0,0 +1,6 @@ +#!/usr/bin/env bash +set -eo pipefail +source "$PLUGIN_AVAILABLE_PATH/run/internal-functions" +[[ $DOKKU_TRACE ]] && set -x + +cmd-run "$@" diff --git a/tests/unit/core_2.bats b/tests/unit/core_2.bats index 57dfe1fad..ab699655d 100644 --- a/tests/unit/core_2.bats +++ b/tests/unit/core_2.bats @@ -20,26 +20,6 @@ teardown() { assert_output_contains "Cleans up exited/dead Docker containers and removes dangling image" } -@test "(core) run (with --options)" { - deploy_app - run /bin/bash -c "dokku --force --quiet run $TEST_APP python -V" - echo "output: $output" - echo "status: $status" - assert_success -} - -@test "(core) run (with --env / -e)" { - deploy_app - run /bin/bash -c "dokku run --env TEST=testvalue -e TEST2=testvalue2 $TEST_APP env | grep -E '^TEST=testvalue'" - echo "output: $output" - echo "status: $status" - - run /bin/bash -c "dokku run --env TEST=testvalue -e TEST2=testvalue2 $TEST_APP env | grep -E '^TEST2=testvalue2'" - echo "output: $output" - echo "status: $status" - assert_success -} - @test "(core) unknown command" { run /bin/bash -c "dokku fakecommand" echo "output: $output" diff --git a/tests/unit/run_1.bats b/tests/unit/run_1.bats new file mode 100644 index 000000000..7dd8fe9b2 --- /dev/null +++ b/tests/unit/run_1.bats @@ -0,0 +1,41 @@ +#!/usr/bin/env bats + +load test_helper + +setup() { + global_setup + create_app +} + +teardown() { + destroy_app + dokku config:unset --global DOKKU_RM_CONTAINER + global_teardown +} + +@test "(run) run:help" { + run /bin/bash -c "dokku run:help" + echo "output: $output" + echo "status: $status" + assert_output_contains "Run a one-off process inside a container" +} + +@test "(run) run (with --options)" { + deploy_app + run /bin/bash -c "dokku --force --quiet run $TEST_APP python -V" + echo "output: $output" + echo "status: $status" + assert_success +} + +@test "(run) run (with --env / -e)" { + deploy_app + run /bin/bash -c "dokku run --env TEST=testvalue -e TEST2=testvalue2 $TEST_APP env | grep -E '^TEST=testvalue'" + echo "output: $output" + echo "status: $status" + + run /bin/bash -c "dokku run --env TEST=testvalue -e TEST2=testvalue2 $TEST_APP env | grep -E '^TEST2=testvalue2'" + echo "output: $output" + echo "status: $status" + assert_success +} diff --git a/tests/unit/core_3.bats b/tests/unit/run_2.bats similarity index 96% rename from tests/unit/core_3.bats rename to tests/unit/run_2.bats index 66c271d3f..f063edfe5 100644 --- a/tests/unit/core_3.bats +++ b/tests/unit/run_2.bats @@ -5,14 +5,11 @@ load test_helper setup() { global_setup create_app - DOCKERFILE="$BATS_TMPDIR/Dockerfile" } teardown() { - rm -rf /home/dokku/$TEST_APP/tls destroy_app dokku config:unset --global DOKKU_RM_CONTAINER - rm -f "$DOCKERFILE" global_teardown } From 618158a0f321eacf7adb876f59a588b59de3f5dd Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Tue, 27 Jul 2021 01:55:16 -0400 Subject: [PATCH 02/12] refactor: deprecate the --rm and --rm-container flags These flags are not commonly invoked by users, causing issues when cleaning up old containers. Rather than instruct users to use some random flag, just change the default to what is likely to be more common. --- docs/appendices/0.25.0-migration-guide.md | 3 ++ docs/configuration/environment-variables.md | 2 +- docs/deployment/remote-commands.md | 1 - docs/processes/one-off-tasks.md | 19 +-------- dokku | 2 +- plugins/common/functions | 2 +- plugins/cron/functions.go | 2 +- plugins/run/internal-functions | 1 + tests/unit/app-json-2.bats | 2 +- tests/unit/app-json.bats | 4 +- tests/unit/core_1.bats | 1 - tests/unit/ps-general.bats | 8 ++-- tests/unit/run_1.bats | 1 - tests/unit/run_2.bats | 44 ++------------------- 14 files changed, 19 insertions(+), 73 deletions(-) diff --git a/docs/appendices/0.25.0-migration-guide.md b/docs/appendices/0.25.0-migration-guide.md index 1e75ddbf8..f94cea26c 100644 --- a/docs/appendices/0.25.0-migration-guide.md +++ b/docs/appendices/0.25.0-migration-guide.md @@ -3,7 +3,10 @@ ## Changes - The network plugin can now set an `initial-network` for all containers on creation. This is a replacement for specifying the `--network` flag via the `docker-options` plugin. Please see the [network documentation](/docs/networking/network.md#attaching-an-app-to-a-network) for more information. +- The `dokku run` command now always removes the ephemeral container on exit. Users that need a persistent container should instead specify a `console` process type in their `Procfile` specifying an available shell (usually either `bash` or `sh`) and scale that container appropriately. + ## Deprecations - In previous versions of Dokku, the only way to specify a custom `Dockerfile` was to use the `docker-options` plugin to set the `--file` flag for a docker build. As of 0.25.0, the `builder-dockerfile:set` command should be used instead, as outlined in the [docs here](/docs/deployment/builders/dockerfiles.md#changingthe-dockerfile-location). Usage of the old method should be migrated to the new method. +- The `--rm` and ``--rm-container` flags may be specified but no longer have any effect on `dokku run`. diff --git a/docs/configuration/environment-variables.md b/docs/configuration/environment-variables.md index 70d5b6227..09a4473e2 100644 --- a/docs/configuration/environment-variables.md +++ b/docs/configuration/environment-variables.md @@ -94,7 +94,7 @@ The following config variables have special meanings and can be set in a variety | `DOKKU_CHECKS_URL` | `https://dokku.com/docs/deployment/zero-downtime-deploys/` | `/etc/environment`
`~dokku/.dokkurc`
`~dokku/.dokkurc/*` | Url displayed during deployment when no CHECKS file exists. | | `DOKKU_DETACH_CONTAINER` | none | `--detach` flag | Whether to detach a container started via `dokku run`. | | `DOKKU_QUIET_OUTPUT` | none | `--quiet` flag | Silences certain header output for `dokku` commands. | -| `DOKKU_RM_CONTAINER` | none | `dokku config:set`
`--rm-container` flag
`--rm` flag | Whether to keep `dokku run` containers around or not. | +| `DOKKU_RM_CONTAINER` | none | `dokku config:set`
| Deprecated: Whether to keep `dokku run` containers around or not. | | `DOKKU_TRACE` | none | `dokku trace:on`
`dokku trace:off`
`--trace` flag | Turn on very verbose debugging. | | `DOKKU_APP_PROXY_TYPE` | `nginx` | `dokku proxy:set` | | | `DOKKU_APP_RESTORE` | `1` | `dokku config:set`
`dokku ps:stop` | | diff --git a/docs/deployment/remote-commands.md b/docs/deployment/remote-commands.md index 33a912cae..0ad87480c 100644 --- a/docs/deployment/remote-commands.md +++ b/docs/deployment/remote-commands.md @@ -17,7 +17,6 @@ in order to avoid SSH interpretting Dokku arguments for itself. ``` --quiet suppress output headers --trace enable DOKKU_TRACE for current execution only ---rm|--rm-container remove docker container after successful dokku run --force force flag. currently used in apps:destroy and other ":destroy" commands ``` diff --git a/docs/processes/one-off-tasks.md b/docs/processes/one-off-tasks.md index d2dd02ac8..c4e5483d5 100644 --- a/docs/processes/one-off-tasks.md +++ b/docs/processes/one-off-tasks.md @@ -8,7 +8,7 @@ Sometimes it is necessary to run a one-off command under an application. Dokku m ## Usage -The `run` command can be used to run a one-off process for a specific command. This will start a new container and run the desired command within that container. Note that this container image will be stay around even after command completes. The container image will be the same container image as was used to start the currently deployed application. +The `run` command can be used to run a one-off process for a specific command. This will start a new container and run the desired command within that container. This contianer will be removed after the process exits. The container image will be the same container image as was used to start the currently deployed application. ```shell # runs `ls -lah` in the `/app` directory of the application `node-js-app` @@ -29,23 +29,6 @@ console: bundle exec racksh dokku run my-app console ``` -If the container running the command should be removed after exit, the `--rm-container` or `--rm` global flags can be specified to remove the containers automatically: - -```shell -dokku --rm-container run node-js-app ls -lah -dokku --rm run node-js-app ls -lah -``` - -Alternatively, a global property can be set to always remove `run` containers. - -```shell -# don't keep `run` containers around -dokku config:set --global DOKKU_RM_CONTAINER=1 - -# revert the above setting and keep containers around -dokku config:unset --global DOKKU_RM_CONTAINER -``` - Containers may have specific labels attached. In order to avoid issues with dokku internals, do not use any labels beginning with either `com.dokku` or `org.label-schema`. ```shell diff --git a/dokku b/dokku index c90749787..4d1ee02df 100755 --- a/dokku +++ b/dokku @@ -207,7 +207,7 @@ case "$1" in done # New lines are blank echos for readability - dokku_log_quiet "Usage: dokku [--quiet|--trace|--rm-container|--rm|--force] COMMAND [command-specific-options]" + dokku_log_quiet "Usage: dokku [--quiet|--trace|--force] COMMAND [command-specific-options]" dokku_log_quiet "" dokku_log_quiet "Primary help options, type \"dokku COMMAND:help\" for more details, or dokku help --all to see all commands." dokku_log_quiet "" diff --git a/plugins/common/functions b/plugins/common/functions index 01353900a..bfe8c2757 100755 --- a/plugins/common/functions +++ b/plugins/common/functions @@ -439,7 +439,7 @@ parse_args() { export DOKKU_TRACE=1 ;; --rm-container | --rm) - export DOKKU_RM_CONTAINER=1 + dokku_log_warn_quiet "Deprecated: all run containers are now removed on exit by default" ;; --force) export DOKKU_APPS_FORCE_DELETE=1 diff --git a/plugins/cron/functions.go b/plugins/cron/functions.go index 4ce0c349c..f09192b3f 100644 --- a/plugins/cron/functions.go +++ b/plugins/cron/functions.go @@ -33,7 +33,7 @@ func (t templateCommand) CronCommand() string { return t.AltCommand } - return fmt.Sprintf("dokku --rm run --cron-id %s %s %s", t.ID, t.App, t.Command) + return fmt.Sprintf("dokku run --cron-id %s %s %s", t.ID, t.App, t.Command) } func fetchCronEntries(appName string) ([]templateCommand, error) { diff --git a/plugins/run/internal-functions b/plugins/run/internal-functions index 814ce6cf5..977a23903 100755 --- a/plugins/run/internal-functions +++ b/plugins/run/internal-functions @@ -57,5 +57,6 @@ cmd-run() { declare cmd="run" [[ "$1" == "$cmd" ]] && shift 1 + export DOKKU_RM_CONTAINER=1 fn-run "$@" } diff --git a/tests/unit/app-json-2.bats b/tests/unit/app-json-2.bats index 88efdded1..c3fdd2d67 100644 --- a/tests/unit/app-json-2.bats +++ b/tests/unit/app-json-2.bats @@ -60,7 +60,7 @@ teardown() { assert_output_contains "entrypoint script started with arguments touch /app/predeploy.test" assert_success - run /bin/bash -c "dokku --rm run $TEST_APP ls /app/predeploy.test" + run /bin/bash -c "dokku run $TEST_APP ls /app/predeploy.test" echo "output: $output" echo "status: $status" assert_success diff --git a/tests/unit/app-json.bats b/tests/unit/app-json.bats index 09aa65597..39f406bd9 100644 --- a/tests/unit/app-json.bats +++ b/tests/unit/app-json.bats @@ -31,12 +31,12 @@ teardown() { assert_success assert_output '["/start","web"]' - run /bin/bash -c "dokku --rm run $TEST_APP ls /app/prebuild.test" + run /bin/bash -c "dokku run $TEST_APP ls /app/prebuild.test" echo "output: $output" echo "status: $status" assert_failure - run /bin/bash -c "dokku --rm run $TEST_APP ls /app/predeploy.test" + run /bin/bash -c "dokku run $TEST_APP ls /app/predeploy.test" echo "output: $output" echo "status: $status" assert_success diff --git a/tests/unit/core_1.bats b/tests/unit/core_1.bats index fdaa43765..c0d07f053 100644 --- a/tests/unit/core_1.bats +++ b/tests/unit/core_1.bats @@ -11,7 +11,6 @@ setup() { teardown() { rm -rf /home/dokku/$TEST_APP/tls destroy_app - dokku config:unset --global DOKKU_RM_CONTAINER rm -f "$DOCKERFILE" global_teardown } diff --git a/tests/unit/ps-general.bats b/tests/unit/ps-general.bats index 0fed2d3fc..cd237b151 100644 --- a/tests/unit/ps-general.bats +++ b/tests/unit/ps-general.bats @@ -175,24 +175,24 @@ EOF assert_success assert_output "true" - run /bin/bash -c "dokku --rm run $TEST_APP console" + run /bin/bash -c "dokku run $TEST_APP console" echo "output: $output" echo "status: $status" assert_success assert_output_contains "Hello world!" - run /bin/bash -c "dokku --rm run $TEST_APP printenv FOO" + run /bin/bash -c "dokku run $TEST_APP printenv FOO" echo "output: $output" echo "status: $status" assert_failure - run /bin/bash -c "dokku --rm config:set $TEST_APP FOO=bar" + run /bin/bash -c "dokku config:set $TEST_APP FOO=bar" echo "output: $output" echo "status: $status" assert_success assert_output_contains "Releasing $TEST_APP" - run /bin/bash -c "dokku --rm run $TEST_APP printenv FOO" + run /bin/bash -c "dokku run $TEST_APP printenv FOO" echo "output: $output" echo "status: $status" assert_success diff --git a/tests/unit/run_1.bats b/tests/unit/run_1.bats index 7dd8fe9b2..2b16b4943 100644 --- a/tests/unit/run_1.bats +++ b/tests/unit/run_1.bats @@ -9,7 +9,6 @@ setup() { teardown() { destroy_app - dokku config:unset --global DOKKU_RM_CONTAINER global_teardown } diff --git a/tests/unit/run_2.bats b/tests/unit/run_2.bats index f063edfe5..25994fcd5 100644 --- a/tests/unit/run_2.bats +++ b/tests/unit/run_2.bats @@ -9,59 +9,21 @@ setup() { teardown() { destroy_app - dokku config:unset --global DOKKU_RM_CONTAINER global_teardown } -@test "(core) run (with DOKKU_RM_CONTAINER/--rm-container)" { +@test "(core) run" { deploy_app - run /bin/bash -c "dokku --rm-container run $TEST_APP echo $TEST_APP" + run /bin/bash -c "dokku run $TEST_APP echo $TEST_APP" echo "output: $output" echo "status: $status" assert_success + run /bin/bash -c "docker ps -a -f 'status=exited' --no-trunc=true | grep \"/exec echo $TEST_APP\"" echo "output: $output" echo "status: $status" assert_failure - - run /bin/bash -c "dokku config:set --no-restart $TEST_APP DOKKU_RM_CONTAINER=1" - echo "output: $output" - echo "status: $status" - assert_success - - run /bin/bash -c "dokku --rm-container run $TEST_APP echo $TEST_APP" - echo "output: $output" - echo "status: $status" - assert_success - run /bin/bash -c "docker ps -a -f 'status=exited' --no-trunc=true | grep \"/exec echo $TEST_APP\"" - echo "output: $output" - echo "status: $status" - assert_failure - - run /bin/bash -c "dokku config:unset --no-restart $TEST_APP DOKKU_RM_CONTAINER" - echo "output: $output" - echo "status: $status" - assert_success - - run /bin/bash -c "dokku config:set --global DOKKU_RM_CONTAINER=1" - echo "output: $output" - echo "status: $status" - assert_success - - run /bin/bash -c "dokku --rm-container run $TEST_APP echo $TEST_APP" - echo "output: $output" - echo "status: $status" - assert_success - run /bin/bash -c "docker ps -a -f 'status=exited' --no-trunc=true | grep \"/exec echo $TEST_APP\"" - echo "output: $output" - echo "status: $status" - assert_failure - - run /bin/bash -c "dokku config:unset --global DOKKU_RM_CONTAINER" - echo "output: $output" - echo "status: $status" - assert_success } @test "(core) run (detached)" { From 350a84d253fcaf8262f526fe9353a20692c0e229 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Tue, 27 Jul 2021 02:11:43 -0400 Subject: [PATCH 03/12] refactor: deprecate the --detach flag in favor of run:detached --- docs/appendices/0.25.0-migration-guide.md | 2 +- docs/configuration/environment-variables.md | 8 ++++---- docs/processes/one-off-tasks.md | 14 ++++++++++---- plugins/common/functions | 1 + plugins/run/help-functions | 1 + plugins/run/internal-functions | 10 ++++++++++ plugins/run/subcommands/detached | 6 ++++++ tests/unit/run_2.bats | 4 ++-- 8 files changed, 35 insertions(+), 11 deletions(-) create mode 100755 plugins/run/subcommands/detached diff --git a/docs/appendices/0.25.0-migration-guide.md b/docs/appendices/0.25.0-migration-guide.md index f94cea26c..ac70f9252 100644 --- a/docs/appendices/0.25.0-migration-guide.md +++ b/docs/appendices/0.25.0-migration-guide.md @@ -5,8 +5,8 @@ - The network plugin can now set an `initial-network` for all containers on creation. This is a replacement for specifying the `--network` flag via the `docker-options` plugin. Please see the [network documentation](/docs/networking/network.md#attaching-an-app-to-a-network) for more information. - The `dokku run` command now always removes the ephemeral container on exit. Users that need a persistent container should instead specify a `console` process type in their `Procfile` specifying an available shell (usually either `bash` or `sh`) and scale that container appropriately. - ## Deprecations - In previous versions of Dokku, the only way to specify a custom `Dockerfile` was to use the `docker-options` plugin to set the `--file` flag for a docker build. As of 0.25.0, the `builder-dockerfile:set` command should be used instead, as outlined in the [docs here](/docs/deployment/builders/dockerfiles.md#changingthe-dockerfile-location). Usage of the old method should be migrated to the new method. - The `--rm` and ``--rm-container` flags may be specified but no longer have any effect on `dokku run`. +- The `--detach` flag is deprecated in favor of the `run:detached` command. diff --git a/docs/configuration/environment-variables.md b/docs/configuration/environment-variables.md index 09a4473e2..2914a6d03 100644 --- a/docs/configuration/environment-variables.md +++ b/docs/configuration/environment-variables.md @@ -91,11 +91,11 @@ The following config variables have special meanings and can be set in a variety | `DOKKU_EVENTS_LOGFILE` | `$DOKKU_LOGS_DIR/events.log` | `/etc/environment`
`~dokku/.dokkurc`
`~dokku/.dokkurc/*` | Where the events log file is written to. | | `DOKKU_APP_NAME` | none | `--app APP` flag | Name of application to work on. Respected by core plugins. | | `DOKKU_APPS_FORCE_DELETE` | none | `--force` flag | Whether to force delete an application. Also used by other plugins for destructive actions. | -| `DOKKU_CHECKS_URL` | `https://dokku.com/docs/deployment/zero-downtime-deploys/` | `/etc/environment`
`~dokku/.dokkurc`
`~dokku/.dokkurc/*` | Url displayed during deployment when no CHECKS file exists. | -| `DOKKU_DETACH_CONTAINER` | none | `--detach` flag | Whether to detach a container started via `dokku run`. | +| `DOKKU_CHECKS_URL` | `https://dokku.com/docs/deployment/zero-downtime-deploys/` | `/etc/environment`
`~dokku/.dokkurc`
`~dokku/.dokkurc/*` | Url displayed during deployment when no CHECKS file exists. | +| `DOKKU_DETACH_CONTAINER` | none | `--detach` flag | Deprecated: Whether to detach a container started via `dokku run`. | | `DOKKU_QUIET_OUTPUT` | none | `--quiet` flag | Silences certain header output for `dokku` commands. | -| `DOKKU_RM_CONTAINER` | none | `dokku config:set`
| Deprecated: Whether to keep `dokku run` containers around or not. | -| `DOKKU_TRACE` | none | `dokku trace:on`
`dokku trace:off`
`--trace` flag | Turn on very verbose debugging. | +| `DOKKU_RM_CONTAINER` | none | `dokku config:set`
| Deprecated: Whether to keep `dokku run` containers around or not. | +| `DOKKU_TRACE` | none | `dokku trace:on`
`dokku trace:off`
`--trace` flag | Turn on very verbose debugging. | | `DOKKU_APP_PROXY_TYPE` | `nginx` | `dokku proxy:set` | | | `DOKKU_APP_RESTORE` | `1` | `dokku config:set`
`dokku ps:stop` | | | `DOKKU_APP_SHELL` | `/bin/bash` | `dokku config:set` | Allows users to change the default shell used by Dokku for `dokku enter` and execution of deployment tasks. | diff --git a/docs/processes/one-off-tasks.md b/docs/processes/one-off-tasks.md index c4e5483d5..bc586fbdd 100644 --- a/docs/processes/one-off-tasks.md +++ b/docs/processes/one-off-tasks.md @@ -8,6 +8,8 @@ Sometimes it is necessary to run a one-off command under an application. Dokku m ## Usage +### Running a one-off command + The `run` command can be used to run a one-off process for a specific command. This will start a new container and run the desired command within that container. This contianer will be removed after the process exits. The container image will be the same container image as was used to start the currently deployed application. ```shell @@ -18,6 +20,8 @@ dokku run node-js-app ls -lah dokku run --env "NODE_ENV=development" --env "PATH=/custom/path" node-js-app npm run mytask ``` +#### Running Procfile commands + The `run` command can also be used to run a command defined in the app `Procfile`: ``` @@ -29,17 +33,19 @@ console: bundle exec racksh dokku run my-app console ``` +#### Specifying container labels + Containers may have specific labels attached. In order to avoid issues with dokku internals, do not use any labels beginning with either `com.dokku` or `org.label-schema`. ```shell dokku --label=com.example.test-label=value run node-js-app ls -lah ``` -Finally, a container can be run in "detached" mode via the `--detach` Dokku flag. Running a process in detached mode will immediately return a `CONTAINER_ID`. It is up to the user to then further manage this container in whatever manner they see fit, as Dokku will *not* automatically terminate the container. +### Running a detached container + +Finally, a container can be run in "detached" mode via the `run:detached` Dokku command. Running a process in detached mode will immediately return a `CONTAINER_ID`. It is up to the user to then further manage this container in whatever manner they see fit, as Dokku will *not* automatically terminate the container. ```shell -dokku --detach run node-js-app ls -lah +dokku run:detached node-js-app ls -lah # returns the ID of the new container ``` - -> Note that the `--rm-container` or `--rm` flags cannot be used when running containers in detached mode, and attempting to do so will result in the `--detach` flag being ignored. diff --git a/plugins/common/functions b/plugins/common/functions index bfe8c2757..938c56d4c 100755 --- a/plugins/common/functions +++ b/plugins/common/functions @@ -433,6 +433,7 @@ parse_args() { export DOKKU_QUIET_OUTPUT=1 ;; --detach) + dokku_log_warn_quiet "Deprecated: use run:detached instead of using the --detach flag" export DOKKU_DETACH_CONTAINER=1 ;; --trace) diff --git a/plugins/run/help-functions b/plugins/run/help-functions index 12db5bc05..0c1671720 100755 --- a/plugins/run/help-functions +++ b/plugins/run/help-functions @@ -28,5 +28,6 @@ fn-help-content() { declare desc="return help content" cat < , Run a command in a new container using the current application image + run:detached [--env KEY=VALUE] , Run a command in a new detached container using the current application image help_content } diff --git a/plugins/run/internal-functions b/plugins/run/internal-functions index 977a23903..8ebc6cc90 100755 --- a/plugins/run/internal-functions +++ b/plugins/run/internal-functions @@ -60,3 +60,13 @@ cmd-run() { export DOKKU_RM_CONTAINER=1 fn-run "$@" } + +cmd-run-detached() { + declare desc="run a detached container" + declare cmd="run:detached" + [[ "$1" == "$cmd" ]] && shift 1 + + export DOKKU_DETACH_CONTAINER=1 + export DOKKU_RM_CONTAINER=1 + fn-run "$@" +} diff --git a/plugins/run/subcommands/detached b/plugins/run/subcommands/detached new file mode 100755 index 000000000..637af4a18 --- /dev/null +++ b/plugins/run/subcommands/detached @@ -0,0 +1,6 @@ +#!/usr/bin/env bash +set -eo pipefail +source "$PLUGIN_AVAILABLE_PATH/run/internal-functions" +[[ $DOKKU_TRACE ]] && set -x + +cmd-run-detached "$@" diff --git a/tests/unit/run_2.bats b/tests/unit/run_2.bats index 25994fcd5..0be97ab67 100644 --- a/tests/unit/run_2.bats +++ b/tests/unit/run_2.bats @@ -26,10 +26,10 @@ teardown() { assert_failure } -@test "(core) run (detached)" { +@test "(core) run:detached" { deploy_app - RANDOM_RUN_CID="$(dokku --label=com.dokku.test-label=value --detach run $TEST_APP sleep 300)" + RANDOM_RUN_CID="$(dokku --label=com.dokku.test-label=value run:detached $TEST_APP sleep 300)" run /bin/bash -c "docker inspect -f '{{ .State.Status }}' $RANDOM_RUN_CID" echo "output: $output" echo "status: $status" From 61d4b478ce9d96fb6396d714437b5daa978192a1 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Tue, 27 Jul 2021 02:26:15 -0400 Subject: [PATCH 04/12] feat: add --no-tty flag to `run` and `run:detached` commands --- docs/processes/one-off-tasks.md | 8 ++++++++ plugins/common/functions | 4 ++++ plugins/run/internal-functions | 5 +++++ 3 files changed, 17 insertions(+) diff --git a/docs/processes/one-off-tasks.md b/docs/processes/one-off-tasks.md index bc586fbdd..1cc23981e 100644 --- a/docs/processes/one-off-tasks.md +++ b/docs/processes/one-off-tasks.md @@ -41,6 +41,14 @@ Containers may have specific labels attached. In order to avoid issues with dokk dokku --label=com.example.test-label=value run node-js-app ls -lah ``` +#### Disabling TTY + +One-off containers default to interactive mode where possible. To disable this behavior, specify the `--no-tty` flag: + +```shell +dokku run --no-tty node-js-app ls -lah +``` + ### Running a detached container Finally, a container can be run in "detached" mode via the `run:detached` Dokku command. Running a process in detached mode will immediately return a `CONTAINER_ID`. It is up to the user to then further manage this container in whatever manner they see fit, as Dokku will *not* automatically terminate the container. diff --git a/plugins/common/functions b/plugins/common/functions index 938c56d4c..89901ec0e 100755 --- a/plugins/common/functions +++ b/plugins/common/functions @@ -4,6 +4,10 @@ set -eo pipefail has_tty() { declare desc="return 0 if we have a tty" + if [[ "$DOKKU_DISABLE_TTY" == "true" ]]; then + return 1 + fi + if [[ "$(LC_ALL=C /usr/bin/tty || true)" == "not a tty" ]]; then return 1 else diff --git a/plugins/run/internal-functions b/plugins/run/internal-functions index 8ebc6cc90..8a22ad8cf 100755 --- a/plugins/run/internal-functions +++ b/plugins/run/internal-functions @@ -17,6 +17,10 @@ fn-run() { SCHEDULER_ID+=("$arg") shift ;; + --no-tty) + export DOKKU_DISABLE_TTY=true + shift + ;; --cron-id) if [[ ! $2 ]]; then dokku_log_warn "expected $1 to have an argument" @@ -67,6 +71,7 @@ cmd-run-detached() { [[ "$1" == "$cmd" ]] && shift 1 export DOKKU_DETACH_CONTAINER=1 + export DOKKU_DISABLE_TTY=true export DOKKU_RM_CONTAINER=1 fn-run "$@" } From 1c6f847c55b64ca7d61eeb53adf2d475d5d38da3 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Tue, 27 Jul 2021 02:27:53 -0400 Subject: [PATCH 05/12] docs: update help output --- docs/processes/one-off-tasks.md | 2 +- plugins/run/help-functions | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/processes/one-off-tasks.md b/docs/processes/one-off-tasks.md index 1cc23981e..c303f6f02 100644 --- a/docs/processes/one-off-tasks.md +++ b/docs/processes/one-off-tasks.md @@ -1,7 +1,7 @@ # One-off Tasks ``` -run [ --env KEY=VALUE | -e KEY=VALUE ] # Run a command in a new container using the current application image +run [-e|--env KEY=VALUE] [--no-tty] # Run a command in a new container using the current application image ``` Sometimes it is necessary to run a one-off command under an application. Dokku makes it easy to run a fresh container via the `run` command. diff --git a/plugins/run/help-functions b/plugins/run/help-functions index 0c1671720..83fd875ae 100755 --- a/plugins/run/help-functions +++ b/plugins/run/help-functions @@ -27,7 +27,7 @@ help_desc fn-help-content() { declare desc="return help content" cat < , Run a command in a new container using the current application image - run:detached [--env KEY=VALUE] , Run a command in a new detached container using the current application image + run [-e|--env KEY=VALUE] [--no-tty] , Run a command in a new container using the current application image + run:detached [-e|-env KEY=VALUE] [--no-tty] , Run a command in a new detached container using the current application image help_content } From e0453dbc157f2e998fcdc9be716d4e518a955e8b Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Tue, 27 Jul 2021 02:30:50 -0400 Subject: [PATCH 06/12] refactor: use `cron` as the dyno type for one-off commands when running cron tasks --- plugins/scheduler-docker-local/scheduler-run | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/plugins/scheduler-docker-local/scheduler-run b/plugins/scheduler-docker-local/scheduler-run index 81cc35edd..2cbbb872c 100755 --- a/plugins/scheduler-docker-local/scheduler-run +++ b/plugins/scheduler-docker-local/scheduler-run @@ -31,15 +31,17 @@ trigger-scheduler-docker-local-scheduler-run() { local DOCKER_ARGS=$(: | plugn trigger docker-args-run "$APP" "$IMAGE_TAG") [[ "$DOKKU_TRACE" ]] && DOCKER_ARGS+=" -e TRACE=true " + local PROCESS_TYPE=run + if [[ -n "$DOKKU_CRON_ID" ]]; then + PROCESS_TYPE=cron + DOCKER_ARGS+=" --label=com.dokku.cron-id=$DOKKU_CRON_ID" + fi + local DYNO_NUMBER="$RANDOM" local IMAGE_SOURCE_TYPE="dockerfile" is_image_herokuish_based "$IMAGE" "$APP" && IMAGE_SOURCE_TYPE="herokuish" DOCKER_ARGS+=$(: | plugn trigger docker-args-process-run "$APP" "$IMAGE_SOURCE_TYPE" "$IMAGE_TAG") - DOCKER_ARGS+=" -e DYNO=run.$DYNO_NUMBER --name $APP.run.$DYNO_NUMBER" - - if [[ -n "$DOKKU_CRON_ID" ]]; then - DOCKER_ARGS+=" --label=com.dokku.cron-id=$DOKKU_CRON_ID" - fi + DOCKER_ARGS+=" -e DYNO=$PROCESS_TYPE.$DYNO_NUMBER --name $APP.$PROCESS_TYPE.$DYNO_NUMBER" declare -a ARG_ARRAY eval "ARG_ARRAY=($DOCKER_ARGS)" @@ -75,7 +77,7 @@ trigger-scheduler-docker-local-scheduler-run() { fi # shellcheck disable=SC2086 - CONTAINER_ID="$("$DOCKER_BIN" container create --label=com.dokku.container-type=run "${DOCKER_RUN_LABEL_ARGS[@]}" $DOKKU_GLOBAL_RUN_ARGS "${DOCKER_ARGS_ARRAY[@]}" $IMAGE $EXEC_CMD "$@")" + CONTAINER_ID="$("$DOCKER_BIN" container create --label=com.dokku.container-type=$PROCESS_TYPE "${DOCKER_RUN_LABEL_ARGS[@]}" $DOKKU_GLOBAL_RUN_ARGS "${DOCKER_ARGS_ARRAY[@]}" $IMAGE $EXEC_CMD "$@")" plugn trigger post-container-create "app" "$CONTAINER_ID" "$APP" "run" declare -a DOCKER_START_ARGS_ARRAY From 3d913d89f62c95357962b847f21e99c348e2bc6c Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Tue, 27 Jul 2021 02:35:32 -0400 Subject: [PATCH 07/12] docs: add run:detached to documentation --- docs/processes/one-off-tasks.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/processes/one-off-tasks.md b/docs/processes/one-off-tasks.md index c303f6f02..cbc985db4 100644 --- a/docs/processes/one-off-tasks.md +++ b/docs/processes/one-off-tasks.md @@ -1,7 +1,8 @@ # One-off Tasks ``` -run [-e|--env KEY=VALUE] [--no-tty] # Run a command in a new container using the current application image +run [-e|--env KEY=VALUE] [--no-tty] # Run a command in a new container using the current application image +run:detached [-e|-env KEY=VALUE] [--no-tty] # Run a command in a new detached container using the current application image ``` Sometimes it is necessary to run a one-off command under an application. Dokku makes it easy to run a fresh container via the `run` command. From 5a1a30efebacb533af0634bccb56639b83f5af4d Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Tue, 27 Jul 2021 02:54:52 -0400 Subject: [PATCH 08/12] feat: add ability to list one-off dynos --- docs/processes/one-off-tasks.md | 17 +++++++++++++++ plugins/20_events/scheduler-run-list | 1 + plugins/run/help-functions | 5 +++-- plugins/run/internal-functions | 10 +++++++++ plugins/run/subcommands/list | 6 ++++++ .../scheduler-docker-local/scheduler-run-list | 21 +++++++++++++++++++ 6 files changed, 58 insertions(+), 2 deletions(-) create mode 120000 plugins/20_events/scheduler-run-list create mode 100755 plugins/run/subcommands/list create mode 100755 plugins/scheduler-docker-local/scheduler-run-list diff --git a/docs/processes/one-off-tasks.md b/docs/processes/one-off-tasks.md index cbc985db4..77ccd3ab3 100644 --- a/docs/processes/one-off-tasks.md +++ b/docs/processes/one-off-tasks.md @@ -3,6 +3,7 @@ ``` run [-e|--env KEY=VALUE] [--no-tty] # Run a command in a new container using the current application image run:detached [-e|-env KEY=VALUE] [--no-tty] # Run a command in a new detached container using the current application image +run:list [] # List all run containers for an app ``` Sometimes it is necessary to run a one-off command under an application. Dokku makes it easy to run a fresh container via the `run` command. @@ -58,3 +59,19 @@ Finally, a container can be run in "detached" mode via the `run:detached` Dokku dokku run:detached node-js-app ls -lah # returns the ID of the new container ``` + +### Listing one-off containers + +One-off containers for a given app can be listed via the `run:list` command: + +```shell +dokku run:list node-js-app +``` + +``` +=====> node-js-app run containers +NAMES COMMAND CREATED +node-js-app.run.28689 "/exec sleep 15" 2 seconds ago +``` + +> The `COMMAND` displayed will be what Docker executes and may not exactly match the command specified by a `dokku run` command. diff --git a/plugins/20_events/scheduler-run-list b/plugins/20_events/scheduler-run-list new file mode 120000 index 000000000..5178a749f --- /dev/null +++ b/plugins/20_events/scheduler-run-list @@ -0,0 +1 @@ +hook \ No newline at end of file diff --git a/plugins/run/help-functions b/plugins/run/help-functions index 83fd875ae..e8e41f6c4 100755 --- a/plugins/run/help-functions +++ b/plugins/run/help-functions @@ -27,7 +27,8 @@ help_desc fn-help-content() { declare desc="return help content" cat < , Run a command in a new container using the current application image - run:detached [-e|-env KEY=VALUE] [--no-tty] , Run a command in a new detached container using the current application image + run [-e|--env KEY=VALUE] [--no-tty] , Run a command in a new container using the current app image + run:detached [-e|-env KEY=VALUE] [--no-tty] , Run a command in a new detached container using the current app image + run:list , List all run containers for an app help_content } diff --git a/plugins/run/internal-functions b/plugins/run/internal-functions index 8a22ad8cf..0a624f811 100755 --- a/plugins/run/internal-functions +++ b/plugins/run/internal-functions @@ -75,3 +75,13 @@ cmd-run-detached() { export DOKKU_RM_CONTAINER=1 fn-run "$@" } + +cmd-run-list() { + declare desc="list all run containers for an app" + declare cmd="run:list" + [[ "$1" == "$cmd" ]] && shift 1 + declare APP="$1" + + local DOKKU_SCHEDULER=$(get_app_scheduler "$APP") + plugn trigger scheduler-run-list "$DOKKU_SCHEDULER" "$APP" +} diff --git a/plugins/run/subcommands/list b/plugins/run/subcommands/list new file mode 100755 index 000000000..d24947806 --- /dev/null +++ b/plugins/run/subcommands/list @@ -0,0 +1,6 @@ +#!/usr/bin/env bash +set -eo pipefail +source "$PLUGIN_AVAILABLE_PATH/run/internal-functions" +[[ $DOKKU_TRACE ]] && set -x + +cmd-run-list "$@" diff --git a/plugins/scheduler-docker-local/scheduler-run-list b/plugins/scheduler-docker-local/scheduler-run-list new file mode 100755 index 000000000..1bea78c9c --- /dev/null +++ b/plugins/scheduler-docker-local/scheduler-run-list @@ -0,0 +1,21 @@ +#!/usr/bin/env bash +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" +source "$PLUGIN_AVAILABLE_PATH/config/functions" + +trigger-scheduler-docker-local-scheduler-run() { + declare desc="runs command in container based on app image" + declare trigger="scheduler-run" + declare DOKKU_SCHEDULER="$1" APP="$2" + + verify_app_name "$APP" + if [[ "$DOKKU_SCHEDULER" != "docker-local" ]]; then + return + fi + + dokku_log_info2_quiet "$APP run containers" + docker ps --filter "label=com.dokku.app-name=$APP" --filter "label=com.dokku.container-type=run" --format "table {{.Names}}\t{{.Command}}\t{{.RunningFor}}" +} + +trigger-scheduler-docker-local-scheduler-run "$@" From a91a0f8abb787db56bb3a458d4a3eda72dc62149 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Tue, 27 Jul 2021 02:59:33 -0400 Subject: [PATCH 09/12] docs: application => app --- docs/processes/one-off-tasks.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/processes/one-off-tasks.md b/docs/processes/one-off-tasks.md index 77ccd3ab3..13ed5fb6e 100644 --- a/docs/processes/one-off-tasks.md +++ b/docs/processes/one-off-tasks.md @@ -1,21 +1,21 @@ # One-off Tasks ``` -run [-e|--env KEY=VALUE] [--no-tty] # Run a command in a new container using the current application image -run:detached [-e|-env KEY=VALUE] [--no-tty] # Run a command in a new detached container using the current application image +run [-e|--env KEY=VALUE] [--no-tty] # Run a command in a new container using the current app image +run:detached [-e|-env KEY=VALUE] [--no-tty] # Run a command in a new detached container using the current app image run:list [] # List all run containers for an app ``` -Sometimes it is necessary to run a one-off command under an application. Dokku makes it easy to run a fresh container via the `run` command. +Sometimes it is necessary to run a one-off command under an app. Dokku makes it easy to run a fresh container via the `run` command. ## Usage ### Running a one-off command -The `run` command can be used to run a one-off process for a specific command. This will start a new container and run the desired command within that container. This contianer will be removed after the process exits. The container image will be the same container image as was used to start the currently deployed application. +The `run` command can be used to run a one-off process for a specific command. This will start a new container and run the desired command within that container. This contianer will be removed after the process exits. The container image will be the same container image as was used to start the currently deployed app. ```shell -# runs `ls -lah` in the `/app` directory of the application `node-js-app` +# runs `ls -lah` in the `/app` directory of the app `node-js-app` dokku run node-js-app ls -lah # optionally, run can be passed custom environment variables @@ -31,7 +31,7 @@ console: bundle exec racksh ``` ```shell -# runs `bundle exec racksh` in the `/app` directory of the application `my-app` +# runs `bundle exec racksh` in the `/app` directory of the app `my-app` dokku run my-app console ``` From 86a2b7d2e329377f0b2f181b9a801ad98db62cbd Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Tue, 27 Jul 2021 03:03:18 -0400 Subject: [PATCH 10/12] docs: clarify when the cli changes were made --- docs/processes/one-off-tasks.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/docs/processes/one-off-tasks.md b/docs/processes/one-off-tasks.md index 13ed5fb6e..a028b1c82 100644 --- a/docs/processes/one-off-tasks.md +++ b/docs/processes/one-off-tasks.md @@ -12,7 +12,9 @@ Sometimes it is necessary to run a one-off command under an app. Dokku makes it ### Running a one-off command -The `run` command can be used to run a one-off process for a specific command. This will start a new container and run the desired command within that container. This contianer will be removed after the process exits. The container image will be the same container image as was used to start the currently deployed app. +The `run` command can be used to run a one-off process for a specific command. This will start a new container and run the desired command within that container. The container image will be the same container image as was used to start the currently deployed app. + +> New as of 0.25.0, this container will be removed after the process exits. ```shell # runs `ls -lah` in the `/app` directory of the app `node-js-app` @@ -45,6 +47,8 @@ dokku --label=com.example.test-label=value run node-js-app ls -lah #### Disabling TTY +> New as of 0.25.0 + One-off containers default to interactive mode where possible. To disable this behavior, specify the `--no-tty` flag: ```shell @@ -53,6 +57,8 @@ dokku run --no-tty node-js-app ls -lah ### Running a detached container +> New as of 0.25.0 + Finally, a container can be run in "detached" mode via the `run:detached` Dokku command. Running a process in detached mode will immediately return a `CONTAINER_ID`. It is up to the user to then further manage this container in whatever manner they see fit, as Dokku will *not* automatically terminate the container. ```shell @@ -62,6 +68,8 @@ dokku run:detached node-js-app ls -lah ### Listing one-off containers +> New as of 0.25.0 + One-off containers for a given app can be listed via the `run:list` command: ```shell From 14b511d673d74fc9cf8c0173e2fad41b8a6d9330 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Tue, 27 Jul 2021 13:16:33 -0400 Subject: [PATCH 11/12] fix: correct lint error --- plugins/common/functions | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/common/functions b/plugins/common/functions index 89901ec0e..8191c2773 100755 --- a/plugins/common/functions +++ b/plugins/common/functions @@ -4,7 +4,7 @@ set -eo pipefail has_tty() { declare desc="return 0 if we have a tty" - if [[ "$DOKKU_DISABLE_TTY" == "true" ]]; then + if [[ "$DOKKU_DISABLE_TTY" == "true" ]]; then return 1 fi From 1bdedf1e287754cf34ee48f09677956b3b1f9730 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Tue, 27 Jul 2021 13:26:37 -0400 Subject: [PATCH 12/12] tests: fix for instant run container removal --- tests/unit/core_1.bats | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/tests/unit/core_1.bats b/tests/unit/core_1.bats index c0d07f053..a712916b5 100644 --- a/tests/unit/core_1.bats +++ b/tests/unit/core_1.bats @@ -26,7 +26,7 @@ teardown() { run /bin/bash -c "docker ps -a -f 'status=exited' --no-trunc=true | grep \"/exec echo $TEST_APP\"" echo "output: $output" echo "status: $status" - assert_success + assert_failure RANDOM_RUN_CID="$(docker run -d gliderlabs/herokuish bash)" docker ps -a @@ -36,12 +36,6 @@ teardown() { assert_success sleep 5 # wait for dokku cleanup to happen in the background - docker ps -a - run /bin/bash -c "docker ps -a -f 'status=exited' --no-trunc=true | grep \"/exec echo $TEST_APP\"" - echo "output: $output" - echo "status: $status" - assert_failure - run /bin/bash -c "docker inspect $RANDOM_RUN_CID" echo "output: $output" echo "status: $status"