From e64daa18cf40fce9de50e79fd5e13a39ed89b525 Mon Sep 17 00:00:00 2001 From: Pascal Widdershoven Date: Wed, 23 Mar 2016 21:06:20 +0100 Subject: [PATCH 1/4] First stab at `dokku run` Procfile shorthand --- docs/deployment/one-off-processes.md | 11 +++++++++++ plugins/00_dokku-standard/subcommands/run | 13 +++++++++++++ tests/apps/nodejs-express/Procfile | 1 + tests/unit/30_core_1.bats | 10 ++++++++++ 4 files changed, 35 insertions(+) diff --git a/docs/deployment/one-off-processes.md b/docs/deployment/one-off-processes.md index 5e591353e..e9965ec3c 100644 --- a/docs/deployment/one-off-processes.md +++ b/docs/deployment/one-off-processes.md @@ -15,6 +15,17 @@ The `run` command can be used to run a one-off process for a specific command. T dokku run node-js-app ls -lah ``` +The `run` command can also be used to run a command defined in your Procfile: + +``` +console: bundle exec racksh +``` + +```shell +# runs `bundle exec racksh` in the `/app` directory of the application `my-app` +dokku run my-app console +``` + If you want to remove the container after a command has started, you can run the following command: ```shell diff --git a/plugins/00_dokku-standard/subcommands/run b/plugins/00_dokku-standard/subcommands/run index ff2ca1588..8eac6c55d 100755 --- a/plugins/00_dokku-standard/subcommands/run +++ b/plugins/00_dokku-standard/subcommands/run @@ -1,6 +1,7 @@ #!/usr/bin/env bash set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/ps/functions" source "$PLUGIN_AVAILABLE_PATH/config/functions" dokku_run_cmd() { @@ -23,6 +24,18 @@ dokku_run_cmd() { [[ "$DOKKU_RM_CONTAINER" ]] && local DOKKU_RUN_OPTS="--rm" has_tty && local DOKKU_RUN_OPTS+=" -i -t" is_image_herokuish_based "$IMAGE" && local EXEC_CMD="/exec" + + # TODO: should we cleanup the procfile after run? + extract_procfile "$APP" + + POTENTIAL_PROCFILE_KEY="$1" + PROC_CMD=$(get_cmd_from_procfile "$APP" "$POTENTIAL_PROCFILE_KEY" || echo '') + + if [ ! -z "$PROC_CMD" ]; then + dokku_log_info1 "Found '$POTENTIAL_PROCFILE_KEY' in Procfile, running that command" + set -- "$PROC_CMD" "${@:2}" + fi + # shellcheck disable=SC2086 docker run $DOKKU_GLOBAL_RUN_ARGS $DOKKU_RUN_OPTS $DOCKER_ARGS $IMAGE $EXEC_CMD "$@" } diff --git a/tests/apps/nodejs-express/Procfile b/tests/apps/nodejs-express/Procfile index 312461ac9..2dfa137ec 100644 --- a/tests/apps/nodejs-express/Procfile +++ b/tests/apps/nodejs-express/Procfile @@ -6,6 +6,7 @@ cron: node worker.js web: node web.js worker: node worker.js +console: bash # Old version with separate processes (use this if you have issues with the threaded version) diff --git a/tests/unit/30_core_1.bats b/tests/unit/30_core_1.bats index 42f6e0122..18bd52ef2 100644 --- a/tests/unit/30_core_1.bats +++ b/tests/unit/30_core_1.bats @@ -128,6 +128,16 @@ build_nginx_config() { assert_success } +@test "(core) run command from Procfile" { + deploy_app + run /bin/bash -c "dokku run $TEST_APP console -c 'echo hi' | tail -n 1" + echo "output: "$output + echo "status: "$status + + assert_success + assert_output "hi" +} + @test "(core) port exposure (dockerfile raw port)" { source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" cat< $DOCKERFILE From 6548cc4477ad30215de62af3a30028dac982d58c Mon Sep 17 00:00:00 2001 From: Pascal Widdershoven Date: Thu, 24 Mar 2016 07:34:43 +0100 Subject: [PATCH 2/4] Update test to not depend on passing named arguments via Herokuish There may be a bug in Herokuish that messes up with quoted named arguments, see discussion in https://github.com/dokku/dokku/pull/2018 --- tests/apps/nodejs-express/Procfile | 2 +- tests/unit/30_core_1.bats | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/apps/nodejs-express/Procfile b/tests/apps/nodejs-express/Procfile index 2dfa137ec..6d278657f 100644 --- a/tests/apps/nodejs-express/Procfile +++ b/tests/apps/nodejs-express/Procfile @@ -6,7 +6,7 @@ cron: node worker.js web: node web.js worker: node worker.js -console: bash +custom: echo -n # Old version with separate processes (use this if you have issues with the threaded version) diff --git a/tests/unit/30_core_1.bats b/tests/unit/30_core_1.bats index 18bd52ef2..c6f2bb794 100644 --- a/tests/unit/30_core_1.bats +++ b/tests/unit/30_core_1.bats @@ -130,12 +130,12 @@ build_nginx_config() { @test "(core) run command from Procfile" { deploy_app - run /bin/bash -c "dokku run $TEST_APP console -c 'echo hi' | tail -n 1" + run /bin/bash -c "dokku run $TEST_APP custom 'hi dokku' | tail -n 1" echo "output: "$output echo "status: "$status assert_success - assert_output "hi" + assert_output 'hi dokku' } @test "(core) port exposure (dockerfile raw port)" { From 5bc3e14eb432f778db783ff9602b492a939aa284 Mon Sep 17 00:00:00 2001 From: Pascal Widdershoven Date: Thu, 24 Mar 2016 07:36:48 +0100 Subject: [PATCH 3/4] Silence extract_profile logging output in `dokku run` --- plugins/00_dokku-standard/subcommands/run | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/00_dokku-standard/subcommands/run b/plugins/00_dokku-standard/subcommands/run index 8eac6c55d..bbf826495 100755 --- a/plugins/00_dokku-standard/subcommands/run +++ b/plugins/00_dokku-standard/subcommands/run @@ -26,7 +26,7 @@ dokku_run_cmd() { is_image_herokuish_based "$IMAGE" && local EXEC_CMD="/exec" # TODO: should we cleanup the procfile after run? - extract_procfile "$APP" + DOKKU_QUIET_OUTPUT=1 extract_procfile "$APP" POTENTIAL_PROCFILE_KEY="$1" PROC_CMD=$(get_cmd_from_procfile "$APP" "$POTENTIAL_PROCFILE_KEY" || echo '') From f073ebe4cdaad196d71787f135c578c57e30da8d Mon Sep 17 00:00:00 2001 From: Pascal Widdershoven Date: Thu, 24 Mar 2016 08:45:40 +0100 Subject: [PATCH 4/4] Cleanup Procfile after using it in `dokku run` --- plugins/00_dokku-standard/subcommands/run | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/00_dokku-standard/subcommands/run b/plugins/00_dokku-standard/subcommands/run index bbf826495..ddfdcb2a3 100755 --- a/plugins/00_dokku-standard/subcommands/run +++ b/plugins/00_dokku-standard/subcommands/run @@ -25,11 +25,11 @@ dokku_run_cmd() { has_tty && local DOKKU_RUN_OPTS+=" -i -t" is_image_herokuish_based "$IMAGE" && local EXEC_CMD="/exec" - # TODO: should we cleanup the procfile after run? DOKKU_QUIET_OUTPUT=1 extract_procfile "$APP" POTENTIAL_PROCFILE_KEY="$1" PROC_CMD=$(get_cmd_from_procfile "$APP" "$POTENTIAL_PROCFILE_KEY" || echo '') + remove_procfile "$APP" if [ ! -z "$PROC_CMD" ]; then dokku_log_info1 "Found '$POTENTIAL_PROCFILE_KEY' in Procfile, running that command"