From 5a1a30efebacb533af0634bccb56639b83f5af4d Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Tue, 27 Jul 2021 02:54:52 -0400 Subject: [PATCH] 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 "$@"