refactor: move run command to it's own plugin
This commit is contained in:
1 parent
bd3f753d85
commit
dbc3d82017
11 files changed
+113
-33
No files matched your search
@@ -141,7 +141,7 @@ execute_dokku_cmd() {
|
|||||||
nginx | nginx:*)
|
nginx | nginx:*)
|
||||||
local PLUGIN_NAME=${PLUGIN_NAME/nginx/nginx-vhosts}
|
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"
|
local PLUGIN_NAME="00_dokku-standard"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
#!/usr/bin/env bash
|
#!/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"
|
source "$PLUGIN_AVAILABLE_PATH/00_dokku-standard/help-functions"
|
||||||
set -eo pipefail
|
set -eo pipefail
|
||||||
[[ $DOKKU_TRACE ]] && set -x
|
[[ $DOKKU_TRACE ]] && set -x
|
||||||
|
|
||||||
case "$1" in
|
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 "$@"
|
cmd-standard-help "$@"
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ fn-help-content() {
|
|||||||
declare desc="return help content"
|
declare desc="return help content"
|
||||||
cat <<help_content
|
cat <<help_content
|
||||||
cleanup [<app>], Cleans up exited/dead Docker containers and removes dangling images
|
cleanup [<app>], Cleans up exited/dead Docker containers and removes dangling images
|
||||||
run [--env KEY=VALUE] <app> <cmd>, Run a command in a new container using the current application image
|
|
||||||
url <app>, Show the first URL for an application (compatibility)
|
url <app>, Show the first URL for an application (compatibility)
|
||||||
urls <app>, Show all URLs for an application
|
urls <app>, Show all URLs for an application
|
||||||
version , Print dokku's version
|
version , Print dokku's version
|
||||||
|
|||||||
Executable
+16
@@ -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
|
||||||
Executable
+32
@@ -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 <<help_desc
|
||||||
|
$plugin_name, $plugin_description
|
||||||
|
help_desc
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
fn-help-content() {
|
||||||
|
declare desc="return help content"
|
||||||
|
cat <<help_content
|
||||||
|
run [--env KEY=VALUE] <app> <cmd>, Run a command in a new container using the current application image
|
||||||
|
help_content
|
||||||
|
}
|
||||||
@@ -1,12 +1,11 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -eo pipefail
|
set -eo pipefail
|
||||||
[[ $DOKKU_TRACE ]] && set -x
|
|
||||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
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=""
|
declare APP=""
|
||||||
local SCHEDULER_ID
|
local SCHEDULER_ID
|
||||||
declare -a RUN_ENV
|
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[@]}" "$@"
|
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 "$@"
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
[plugin]
|
||||||
|
description = "dokku core run plugin"
|
||||||
|
version = "0.24.10"
|
||||||
|
[plugin.config]
|
||||||
Executable
+6
@@ -0,0 +1,6 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -eo pipefail
|
||||||
|
source "$PLUGIN_AVAILABLE_PATH/run/internal-functions"
|
||||||
|
[[ $DOKKU_TRACE ]] && set -x
|
||||||
|
|
||||||
|
cmd-run "$@"
|
||||||
@@ -20,26 +20,6 @@ teardown() {
|
|||||||
assert_output_contains "Cleans up exited/dead Docker containers and removes dangling image"
|
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" {
|
@test "(core) unknown command" {
|
||||||
run /bin/bash -c "dokku fakecommand"
|
run /bin/bash -c "dokku fakecommand"
|
||||||
echo "output: $output"
|
echo "output: $output"
|
||||||
|
|||||||
@@ -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
|
||||||
|
}
|
||||||
@@ -5,14 +5,11 @@ load test_helper
|
|||||||
setup() {
|
setup() {
|
||||||
global_setup
|
global_setup
|
||||||
create_app
|
create_app
|
||||||
DOCKERFILE="$BATS_TMPDIR/Dockerfile"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
teardown() {
|
teardown() {
|
||||||
rm -rf /home/dokku/$TEST_APP/tls
|
|
||||||
destroy_app
|
destroy_app
|
||||||
dokku config:unset --global DOKKU_RM_CONTAINER
|
dokku config:unset --global DOKKU_RM_CONTAINER
|
||||||
rm -f "$DOCKERFILE"
|
|
||||||
global_teardown
|
global_teardown
|
||||||
}
|
}
|
||||||
|
|
||||||
Reference in new issue
Block a user