feat: add ability to list one-off dynos

This commit is contained in:
Jose Diaz-Gonzalez
2021-07-27 02:54:52 -04:00
parent 3d913d89f6
commit 5a1a30efeb
6 changed files with 58 additions and 2 deletions

View File

@@ -3,6 +3,7 @@
```
run [-e|--env KEY=VALUE] [--no-tty] <app> <cmd> # Run a command in a new container using the current application image
run:detached [-e|-env KEY=VALUE] [--no-tty] <app> <cmd> # Run a command in a new detached container using the current application image
run:list [<app>] # 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.

View File

@@ -0,0 +1 @@
hook

View File

@@ -27,7 +27,8 @@ help_desc
fn-help-content() {
declare desc="return help content"
cat <<help_content
run [-e|--env KEY=VALUE] [--no-tty] <app> <cmd>, Run a command in a new container using the current application image
run:detached [-e|-env KEY=VALUE] [--no-tty] <app> <cmd>, Run a command in a new detached container using the current application image
run [-e|--env KEY=VALUE] [--no-tty] <app> <cmd>, Run a command in a new container using the current app image
run:detached [-e|-env KEY=VALUE] [--no-tty] <app> <cmd>, Run a command in a new detached container using the current app image
run:list <app>, List all run containers for an app
help_content
}

View File

@@ -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"
}

6
plugins/run/subcommands/list Executable file
View File

@@ -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 "$@"

View File

@@ -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 "$@"