From f1dd722971b87062f6c78257a8f5e945bed5143a Mon Sep 17 00:00:00 2001 From: Jody McIntyre Date: Thu, 3 Oct 2019 14:55:28 -0400 Subject: [PATCH 1/2] Update DOKKU_SCALE from Procfile during ps:scale This is needed so that we report on processes added to an app's Procfile. --- plugins/ps/functions | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/plugins/ps/functions b/plugins/ps/functions index 2272506c5..8d097bb17 100755 --- a/plugins/ps/functions +++ b/plugins/ps/functions @@ -194,7 +194,17 @@ ps_scale() { local DOKKU_PROCFILE="$DOKKU_ROOT/$APP/DOKKU_PROCFILE" shift 1 - [[ ! -e $DOKKU_SCALE_FILE ]] && generate_scale_file "$APP" "$IMAGE_TAG" >/dev/null 2>&1 + # shellcheck disable=SC2015 + [[ ! -e $DOKKU_PROCFILE ]] && extract_procfile "$APP" "$IMAGE_TAG" >/dev/null 2>&1 || true + if [[ ! -e $DOKKU_SCALE_FILE ]] ; then + generate_scale_file "$APP" "$IMAGE_TAG" >/dev/null 2>&1 + elif [[ -e $DOKKU_PROCFILE ]] ; then + for PROC_NAME in $(procfile-util list --procfile "$DOKKU_PROCFILE"); do + if ! grep -qE "^${PROC_NAME}=" "$DOKKU_SCALE_FILE"; then + echo "$PROC_NAME=0" >> "$DOKKU_SCALE_FILE" + fi + done + fi if [[ -z "$@" ]]; then dokku_log_info1_quiet "Scaling for $APP" dokku_col_log_msg_quiet "proctype" "qty" From 592b10122d652fee0c4e04e87b9fed6d390d55bf Mon Sep 17 00:00:00 2001 From: Jody McIntyre Date: Thu, 3 Oct 2019 17:48:20 -0400 Subject: [PATCH 2/2] Add test of DOKKU_SCALE update --- tests/unit/10_ps-general.bats | 25 +++++++++++++++++++++++++ tests/unit/test_helper.bash | 4 ++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/tests/unit/10_ps-general.bats b/tests/unit/10_ps-general.bats index fe585de35..86d3a08c7 100644 --- a/tests/unit/10_ps-general.bats +++ b/tests/unit/10_ps-general.bats @@ -41,6 +41,31 @@ EOF assert_output "node worker.js" } +@test "(ps:scale) update DOKKU_SCALE from Procfile" { + local TMP=$(mktemp -d "/tmp/dokku.me.XXXXX") + trap 'popd &>/dev/null || true; rm -rf "$TMP"' INT TERM + + CUSTOM_TMP="$TMP" deploy_app nodejs-express + + run /bin/bash -c "dokku --quiet ps:scale $TEST_APP" + output=$(echo "$output" | tr -s " ") + echo "output: ($output)" + assert_output $'cron: 0 \ncustom: 0 \nrelease: 0 \nweb: 1 \nworker: 0 ' + + pushd $TMP + echo scaletest: sleep infinity >> Procfile + git commit Procfile -m 'Add scaletest process' + git push target master:master + + run /bin/bash -c "dokku --quiet ps:scale $TEST_APP" + output=$(echo "$output" | tr -s " ") + echo "output: ($output)" + assert_output $'cron: 0 \ncustom: 0 \nrelease: 0 \nweb: 1 \nworker: 0 \nscaletest: 0 ' + + popd + rm -rf "$TMP" +} + @test "(ps:restart-policy) default policy" { run /bin/bash -c "dokku --quiet ps:restart-policy $TEST_APP" echo "output: $output" diff --git a/tests/unit/test_helper.bash b/tests/unit/test_helper.bash index 5b79d3426..7381ed9d1 100644 --- a/tests/unit/test_helper.bash +++ b/tests/unit/test_helper.bash @@ -222,7 +222,7 @@ deploy_app() { local APP_TYPE=${APP_TYPE:="nodejs-express"} local GIT_REMOTE=${GIT_REMOTE:="dokku@dokku.me:$TEST_APP"} local GIT_REMOTE_BRANCH=${GIT_REMOTE_BRANCH:="master"} - local TMP=$(mktemp -d "/tmp/dokku.me.XXXXX") + local TMP=${CUSTOM_TMP:=$(mktemp -d "/tmp/dokku.me.XXXXX")} rmdir "$TMP" && cp -r "${BATS_TEST_DIRNAME}/../../tests/apps/$APP_TYPE" "$TMP" @@ -230,7 +230,7 @@ deploy_app() { [[ -n "$CUSTOM_TEMPLATE" ]] && $CUSTOM_TEMPLATE $TEST_APP $TMP/$CUSTOM_PATH pushd "$TMP" &>/dev/null || exit 1 - trap 'popd &>/dev/null || true; rm -rf "$TMP"' RETURN INT TERM + [[ -z "$CUSTOM_TMP" ]] && trap 'popd &>/dev/null || true; rm -rf "$TMP"' RETURN INT TERM git init git config user.email "robot@example.com"