From c4c6ac5617abcb5c8d82d8d2550ded7704e3db41 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Wed, 10 Aug 2022 21:27:25 -0400 Subject: [PATCH 1/5] feat: add the ability to disable the init process This allows projects using s6 overlay - in particular linxserver images - the ability to disable --init flag injection. Closes #5287 --- docs/deployment/schedulers/docker-local.md | 14 ++++++++++++++ .../bin/scheduler-deploy-process | 1 + .../bin/scheduler-deploy-process-container | 4 +++- plugins/scheduler-docker-local/internal-functions | 1 + plugins/scheduler-docker-local/subcommands/set | 4 ++-- 5 files changed, 21 insertions(+), 3 deletions(-) diff --git a/docs/deployment/schedulers/docker-local.md b/docs/deployment/schedulers/docker-local.md index 5d50da590..da9039a79 100644 --- a/docs/deployment/schedulers/docker-local.md +++ b/docs/deployment/schedulers/docker-local.md @@ -37,6 +37,20 @@ Once set, you may re-enable it by setting a blank value for `disable-chown`: dokku scheduler-docker-local:set node-js-app disable-chown ``` +### Disabling the init process + +The `scheduler-docker-local` injects an init process by default via the `--init`. For some apps - such as those where the built docker image uses S6 as the init - this may be undesirable and cause issues with process starts. You may disable this by running the following `scheduler-docker-local:set` command for your application: + +```shell +dokku scheduler-docker-local:set node-js-app init-process false +``` + +Once set, you may re-enable it by setting a blank value for `init-process`: + +```shell +dokku scheduler-docker-local:set node-js-app init-process +``` + ### Deploying Process Types in Parallel > New as of 0.25.5 diff --git a/plugins/scheduler-docker-local/bin/scheduler-deploy-process b/plugins/scheduler-docker-local/bin/scheduler-deploy-process index 208b337ff..68b0eac5d 100755 --- a/plugins/scheduler-docker-local/bin/scheduler-deploy-process +++ b/plugins/scheduler-docker-local/bin/scheduler-deploy-process @@ -35,6 +35,7 @@ main() { CONTAINER_INDEX=$((CONTAINER_INDEX + 1)) done + INJECT_INIT_FLAG="$(fn-plugin-property-get "scheduler-docker-local" "$APP" "init-process" "true")" PARALLEL_DEPLOY_COUNT="$(plugn trigger "app-json-process-deploy-parallelism" "$APP" "$PROC_TYPE")" DOKKU_CHECKS_DISABLED="$DOKKU_CHECKS_DISABLED" parallel --will-cite --halt soon,fail=1 --jobs "$PARALLEL_DEPLOY_COUNT" --ungroup <"$PROCESS_TMP_FILE" diff --git a/plugins/scheduler-docker-local/bin/scheduler-deploy-process-container b/plugins/scheduler-docker-local/bin/scheduler-deploy-process-container index 2804678c6..bfa442dc6 100755 --- a/plugins/scheduler-docker-local/bin/scheduler-deploy-process-container +++ b/plugins/scheduler-docker-local/bin/scheduler-deploy-process-container @@ -19,7 +19,9 @@ main() { DOCKER_ARGS+=" --label=com.dokku.process-type=$PROC_TYPE --label=com.dokku.dyno=$DYNO" DOCKER_ARGS+=" --env=DYNO=$DYNO" DOCKER_ARGS+=" --name=$APP.$DYNO.upcoming-$RANDOM" - DOCKER_ARGS+=" --init" + if [[ "$INJECT_INIT_FLAG" == "false" ]]; then + DOCKER_ARGS+=" --init" + fi DOCKER_ARGS+=" $DOCKER_RUN_LABEL_ARGS $DOKKU_GLOBAL_RUN_ARGS " DOCKER_ARGS+=$(: | plugn trigger docker-args-process-deploy "$APP" "$IMAGE_SOURCE_TYPE" "$IMAGE_TAG" "$PROC_TYPE" "$CONTAINER_INDEX") [[ "$DOKKU_TRACE" ]] && DOCKER_ARGS+=" --env=TRACE=true" diff --git a/plugins/scheduler-docker-local/internal-functions b/plugins/scheduler-docker-local/internal-functions index b841d4582..1a44deae9 100755 --- a/plugins/scheduler-docker-local/internal-functions +++ b/plugins/scheduler-docker-local/internal-functions @@ -37,6 +37,7 @@ cmd-scheduler-docker-local-report-single() { verify_app_name "$APP" local flag_map=( "--scheduler-docker-local-disable-chown: $(fn-plugin-property-get "scheduler-docker-local" "$APP" "disable-chown" "")" + "--scheduler-docker-local-init-process: $(fn-plugin-property-get "scheduler-docker-local" "$APP" "init-process" "true")" "--scheduler-docker-local-parallel-schedule-count: $(fn-plugin-property-get "scheduler-docker-local" "$APP" "parallel-schedule-count" "")" ) diff --git a/plugins/scheduler-docker-local/subcommands/set b/plugins/scheduler-docker-local/subcommands/set index dcb1f7f91..8f2230126 100755 --- a/plugins/scheduler-docker-local/subcommands/set +++ b/plugins/scheduler-docker-local/subcommands/set @@ -9,13 +9,13 @@ cmd-scheduler-docker-local-set() { declare cmd="scheduler-docker-local:set" [[ "$1" == "$cmd" ]] && shift 1 declare APP="$1" KEY="$2" VALUE="$3" - local VALID_KEYS=("disable-chown" "parallel-schedule-count") + local VALID_KEYS=("disable-chown" "init-process" "parallel-schedule-count") verify_app_name "$APP" [[ -z "$KEY" ]] && dokku_log_fail "No key specified" if ! fn-in-array "$KEY" "${VALID_KEYS[@]}"; then - dokku_log_fail "Invalid key specified, valid keys include: disable-chown, parallel-schedule-count" + dokku_log_fail "Invalid key specified, valid keys include: disable-chown, init-process, parallel-schedule-count" fi if [[ -n "$VALUE" ]]; then From 293ead4f356bc14b3e4ad6ff40c3a0efb79becb8 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Wed, 10 Aug 2022 21:31:57 -0400 Subject: [PATCH 2/5] feat: force-disable the --init flag for linuxserver images All linuxserver images uses S6, and there are enough of them that this makes sense to autodetect on behalf of users. --- docs/deployment/schedulers/docker-local.md | 2 ++ .../scheduler-docker-local/bin/scheduler-deploy-process | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/docs/deployment/schedulers/docker-local.md b/docs/deployment/schedulers/docker-local.md index da9039a79..b4f9359d4 100644 --- a/docs/deployment/schedulers/docker-local.md +++ b/docs/deployment/schedulers/docker-local.md @@ -51,6 +51,8 @@ Once set, you may re-enable it by setting a blank value for `init-process`: dokku scheduler-docker-local:set node-js-app init-process ``` +All image containers with the label `org.opencontainers.image.vendor=linuxserver.io` will have the automatic init process injection force-disabled without further intervention. + ### Deploying Process Types in Parallel > New as of 0.25.5 diff --git a/plugins/scheduler-docker-local/bin/scheduler-deploy-process b/plugins/scheduler-docker-local/bin/scheduler-deploy-process index 68b0eac5d..3d946b0e5 100755 --- a/plugins/scheduler-docker-local/bin/scheduler-deploy-process +++ b/plugins/scheduler-docker-local/bin/scheduler-deploy-process @@ -7,6 +7,7 @@ source "$PLUGIN_AVAILABLE_PATH/checks/functions" main() { declare APP="$1" IMAGE_SOURCE_TYPE="$2" IMAGE="$3" IMAGE_TAG="$4" PROC_TYPE="$5" PROC_COUNT="$6" local CONTAINER_INDEX=1 + local image_vendor dokku_log_info1 "Deploying $PROC_TYPE (count=$PROC_COUNT)" DOKKU_CHECKS_DISABLED="$(is_app_proctype_checks_disabled "$APP" "$PROC_TYPE")" @@ -36,6 +37,12 @@ main() { done INJECT_INIT_FLAG="$(fn-plugin-property-get "scheduler-docker-local" "$APP" "init-process" "true")" + # special-case linuxserver.io images as those always use an s6-overlay + image_vendor="$("$DOCKER_BIN" image inspect --format '{{ index .Config.Labels "org.opencontainers.image.vendor" }}' "$IMAGE")" + if [[ "$image_vendor" == "linuxserver.io" ]]; then + INJECT_INIT_FLAG="false" + fi + PARALLEL_DEPLOY_COUNT="$(plugn trigger "app-json-process-deploy-parallelism" "$APP" "$PROC_TYPE")" DOKKU_CHECKS_DISABLED="$DOKKU_CHECKS_DISABLED" parallel --will-cite --halt soon,fail=1 --jobs "$PARALLEL_DEPLOY_COUNT" --ungroup <"$PROCESS_TMP_FILE" From 045825857a68689ccab4e8addabb4c91ad9f417a Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Thu, 11 Aug 2022 11:51:31 -0400 Subject: [PATCH 3/5] fix: add missing source and respect any user settings for init-process property --- .../bin/scheduler-deploy-process | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/plugins/scheduler-docker-local/bin/scheduler-deploy-process b/plugins/scheduler-docker-local/bin/scheduler-deploy-process index 3d946b0e5..f3e5bf821 100755 --- a/plugins/scheduler-docker-local/bin/scheduler-deploy-process +++ b/plugins/scheduler-docker-local/bin/scheduler-deploy-process @@ -2,6 +2,7 @@ set -eo pipefail [[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/common/property-functions" source "$PLUGIN_AVAILABLE_PATH/checks/functions" main() { @@ -36,11 +37,15 @@ main() { CONTAINER_INDEX=$((CONTAINER_INDEX + 1)) done - INJECT_INIT_FLAG="$(fn-plugin-property-get "scheduler-docker-local" "$APP" "init-process" "true")" + INJECT_INIT_FLAG="$(fn-plugin-property-get "scheduler-docker-local" "$APP" "init-process" "")" + if [[ -z "$INJECT_INIT_FLAG" ]]; then # special-case linuxserver.io images as those always use an s6-overlay - image_vendor="$("$DOCKER_BIN" image inspect --format '{{ index .Config.Labels "org.opencontainers.image.vendor" }}' "$IMAGE")" - if [[ "$image_vendor" == "linuxserver.io" ]]; then - INJECT_INIT_FLAG="false" + image_vendor="$("$DOCKER_BIN" image inspect --format '{{ index .Config.Labels "org.opencontainers.image.vendor" }}' "$IMAGE")" + if [[ "$image_vendor" == "linuxserver.io" ]]; then + INJECT_INIT_FLAG="false" + else + INJECT_INIT_FLAG="true" + fi fi PARALLEL_DEPLOY_COUNT="$(plugn trigger "app-json-process-deploy-parallelism" "$APP" "$PROC_TYPE")" From bc4eaa002f2d87b1b8be1b1e58a3dd91bee367d6 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Thu, 11 Aug 2022 13:07:00 -0400 Subject: [PATCH 4/5] fix: correct shfmt issue --- plugins/scheduler-docker-local/bin/scheduler-deploy-process | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/scheduler-docker-local/bin/scheduler-deploy-process b/plugins/scheduler-docker-local/bin/scheduler-deploy-process index f3e5bf821..d70154f89 100755 --- a/plugins/scheduler-docker-local/bin/scheduler-deploy-process +++ b/plugins/scheduler-docker-local/bin/scheduler-deploy-process @@ -39,7 +39,7 @@ main() { INJECT_INIT_FLAG="$(fn-plugin-property-get "scheduler-docker-local" "$APP" "init-process" "")" if [[ -z "$INJECT_INIT_FLAG" ]]; then - # special-case linuxserver.io images as those always use an s6-overlay + # special-case linuxserver.io images as those always use an s6-overlay image_vendor="$("$DOCKER_BIN" image inspect --format '{{ index .Config.Labels "org.opencontainers.image.vendor" }}' "$IMAGE")" if [[ "$image_vendor" == "linuxserver.io" ]]; then INJECT_INIT_FLAG="false" From f09b9609972cf5db905876b4772f07f7c29e4d9e Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sun, 14 Aug 2022 13:45:41 -0400 Subject: [PATCH 5/5] tests: add a unit test for the init-process option --- .../bin/scheduler-deploy-process | 2 +- .../bin/scheduler-deploy-process-container | 2 +- tests/unit/scheduler-docker-local.bats | 46 +++++++++++++++++++ 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/plugins/scheduler-docker-local/bin/scheduler-deploy-process b/plugins/scheduler-docker-local/bin/scheduler-deploy-process index d70154f89..32f86f263 100755 --- a/plugins/scheduler-docker-local/bin/scheduler-deploy-process +++ b/plugins/scheduler-docker-local/bin/scheduler-deploy-process @@ -49,7 +49,7 @@ main() { fi PARALLEL_DEPLOY_COUNT="$(plugn trigger "app-json-process-deploy-parallelism" "$APP" "$PROC_TYPE")" - DOKKU_CHECKS_DISABLED="$DOKKU_CHECKS_DISABLED" parallel --will-cite --halt soon,fail=1 --jobs "$PARALLEL_DEPLOY_COUNT" --ungroup <"$PROCESS_TMP_FILE" + DOKKU_CHECKS_DISABLED="$DOKKU_CHECKS_DISABLED" INJECT_INIT_FLAG="$INJECT_INIT_FLAG" parallel --will-cite --halt soon,fail=1 --jobs "$PARALLEL_DEPLOY_COUNT" --ungroup <"$PROCESS_TMP_FILE" # cleanup when we scale down if [[ "$PROC_COUNT" == 0 ]]; then diff --git a/plugins/scheduler-docker-local/bin/scheduler-deploy-process-container b/plugins/scheduler-docker-local/bin/scheduler-deploy-process-container index bfa442dc6..772ee88c5 100755 --- a/plugins/scheduler-docker-local/bin/scheduler-deploy-process-container +++ b/plugins/scheduler-docker-local/bin/scheduler-deploy-process-container @@ -19,7 +19,7 @@ main() { DOCKER_ARGS+=" --label=com.dokku.process-type=$PROC_TYPE --label=com.dokku.dyno=$DYNO" DOCKER_ARGS+=" --env=DYNO=$DYNO" DOCKER_ARGS+=" --name=$APP.$DYNO.upcoming-$RANDOM" - if [[ "$INJECT_INIT_FLAG" == "false" ]]; then + if [[ "$INJECT_INIT_FLAG" == "true" ]]; then DOCKER_ARGS+=" --init" fi DOCKER_ARGS+=" $DOCKER_RUN_LABEL_ARGS $DOKKU_GLOBAL_RUN_ARGS " diff --git a/tests/unit/scheduler-docker-local.bats b/tests/unit/scheduler-docker-local.bats index 0fbba8dc1..42c906634 100644 --- a/tests/unit/scheduler-docker-local.bats +++ b/tests/unit/scheduler-docker-local.bats @@ -55,3 +55,49 @@ teardown() { assert_output "Host(\`$TEST_APP.dokku.me\`)" assert_success } + +@test "(scheduler-docker-local) init-process" { + run create_app + echo "output: $output" + echo "status: $status" + assert_success + + run deploy_app + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "docker inspect --format '{{.HostConfig.Init}}' $TEST_APP.web.1" + echo "output: $output" + echo "status: $status" + assert_success + assert_output "true" + + run /bin/bash -c "docker exec $TEST_APP.web.1 ps auxf" + echo "output: $output" + echo "status: $status" + assert_success + assert_output_contains "docker-init" + + run /bin/bash -c "dokku scheduler-docker-local:set $TEST_APP init-process false" + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "dokku ps:rebuild $TEST_APP" + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "docker inspect --format '{{.HostConfig.Init}}' $TEST_APP.web.1" + echo "output: $output" + echo "status: $status" + assert_success + assert_output "" + + run /bin/bash -c "docker exec $TEST_APP.web.1 ps auxf" + echo "output: $output" + echo "status: $status" + assert_success + assert_output_contains "docker-init" 0 +}