From 7349c30cd9e686926583cea6eb7b049939bd84d4 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Wed, 1 Aug 2018 02:00:32 -0400 Subject: [PATCH] feat: allow disabling chown for persistent storage in scheduler-docker-local Some systems - such as a mounted read-only CIFS filesystem - do not fully support chown, and chowning should be considered optional for cases when the host os has already taken care of permissioning. This commit allows users to disable chown by setting a property on the scheduler-docker-local plugin. --- docs/advanced-usage/persistent-storage.md | 6 +- .../advanced-usage/schedulers/docker-local.md | 23 +++++ plugins/scheduler-docker-local/commands | 14 +++ plugins/scheduler-docker-local/install | 3 + .../scheduler-docker-local/internal-functions | 89 +++++++++++++++++++ plugins/scheduler-docker-local/pre-deploy | 16 +++- plugins/scheduler-docker-local/report | 5 ++ .../subcommands/default | 5 ++ .../scheduler-docker-local/subcommands/report | 5 ++ .../scheduler-docker-local/subcommands/set | 37 ++++++++ 10 files changed, 196 insertions(+), 7 deletions(-) create mode 100755 plugins/scheduler-docker-local/commands create mode 100755 plugins/scheduler-docker-local/internal-functions create mode 100755 plugins/scheduler-docker-local/report create mode 100755 plugins/scheduler-docker-local/subcommands/default create mode 100755 plugins/scheduler-docker-local/subcommands/report create mode 100755 plugins/scheduler-docker-local/subcommands/set diff --git a/docs/advanced-usage/persistent-storage.md b/docs/advanced-usage/persistent-storage.md index 0627e89aa..bf3e68509 100644 --- a/docs/advanced-usage/persistent-storage.md +++ b/docs/advanced-usage/persistent-storage.md @@ -39,7 +39,7 @@ dokku storage:mount node-js-app /var/lib/dokku/data/storage/node-js-app:/storage Dokku will then mount the shared contents of `/var/lib/dokku/data/storage` to `/storage` inside the container. -Once you have mounted persistent storage, you will also need to restart the application. See the +Once you have mounted persistent storage, you will also need to restart the application. See the [process scaling documentation](/docs/deployment/process-management.md) for more information. ```shell @@ -132,7 +132,7 @@ Your app may have services that are running in memory and need to be backed up l By default, Dokku will only bind storage mounts during the deploy and run phases. Under certain conditions, one might want to bind a storage mount during the build phase. This can be accomplished by using the `docker-options` plugin directly. ```shell -dokku docker-options:add build "-v /tmp/python-test:/opt/test" +dokku docker-options:add node-js-app build "-v /tmp/python-test:/opt/test" ``` You cannot use mounted volumes during the build phase of a Dockerfile deploy. This is because Docker does not support volumes when executing `docker build`. @@ -147,4 +147,4 @@ By default, Dokku will execute your buildpack application processes as the `hero > NOTE: this user must exist in your herokuish image. -Additionally, Dokku will ensure your storage mounts are owned by either `herokuishuser` or the overridden value you have set in `DOKKU_APP_USER`. +Additionally, the default `docker-local` scheduler that comes with Dokku will ensure your storage mounts are owned by either `herokuishuser` or the overridden value you have set in `DOKKU_APP_USER`. See the [scheduler-docker-local documentation](/docs/advanced-usage/schedulers/docker-local.md#disabling-chown-of-persistent-storage) docs for more information. diff --git a/docs/advanced-usage/schedulers/docker-local.md b/docs/advanced-usage/schedulers/docker-local.md index 2f9ee476a..dfa97ef1f 100644 --- a/docs/advanced-usage/schedulers/docker-local.md +++ b/docs/advanced-usage/schedulers/docker-local.md @@ -1,5 +1,12 @@ # Docker Local Scheduler +> Subcommands new as of 0.12.12 + +``` +scheduler-docker-local:report [] [] # Displays a scheduler-docker-local report for one or more apps +scheduler-docker-local:set () # Set or clear a scheduler-docker-local property for an app +``` + > New as of 0.12.0 Dokku natively includes functionality to manage application lifecycles for a single server using the `scheduler-docker-local` plugin. It is the default scheduler, but as with all schedulers, it is set on a per-application basis. The scheduler can currently be overridden by running the following command: @@ -14,6 +21,22 @@ As it is the default, unsetting the `DOCKER_SCHEDULER` config variable is also a dokku config:unset node-js-app DOCKER_SCHEDULER ``` +## Usage + +### Disabling chown of persistent storage + +The `scheduler-docker-local` plugin will ensure your storage mounts are owned by either `herokuishuser` or the overridden value you have set in `DOKKU_APP_USER`. 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 DISABLE_CHOWN true +``` + +Once set, you may re-enable it by setting a blank value for `DISABLE_CHOWN`: + +```shell +dokku scheduler-docker-local:set node-js-app DISABLE_CHOWN +``` + ## Implemented Triggers This plugin implements various functionality through `plugn` triggers to integrate with Docker for running apps on a single server. The following functionality is supported by the `scheduler-docker-local` plugin. diff --git a/plugins/scheduler-docker-local/commands b/plugins/scheduler-docker-local/commands new file mode 100755 index 000000000..4b53ac6b8 --- /dev/null +++ b/plugins/scheduler-docker-local/commands @@ -0,0 +1,14 @@ +#!/usr/bin/env bash +set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +source "$PLUGIN_AVAILABLE_PATH/scheduler-docker-local/internal-functions" + +case "$1" in + help | scheduler-docker-local:help) + cmd-scheduler-docker-local-help "$@" + ;; + + *) + exit "$DOKKU_NOT_IMPLEMENTED_EXIT" + ;; + +esac diff --git a/plugins/scheduler-docker-local/install b/plugins/scheduler-docker-local/install index a6159c0b5..884c2cb3f 100755 --- a/plugins/scheduler-docker-local/install +++ b/plugins/scheduler-docker-local/install @@ -1,5 +1,6 @@ #!/usr/bin/env bash set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +source "$PLUGIN_CORE_AVAILABLE_PATH/common/property-functions" scheduler-docker-local-install() { declare desc="scheduler-docker-local install plugin trigger" @@ -7,6 +8,8 @@ scheduler-docker-local-install() { mkdir -p "${DOKKU_LIB_ROOT}/data/scheduler-docker-local" chown -R "${DOKKU_SYSTEM_USER}:${DOKKU_SYSTEM_GROUP}" "${DOKKU_LIB_ROOT}/data/scheduler-docker-local" + + fn-plugin-property-setup "scheduler-docker-local" } scheduler-docker-local-install "$@" diff --git a/plugins/scheduler-docker-local/internal-functions b/plugins/scheduler-docker-local/internal-functions new file mode 100755 index 000000000..23648c82e --- /dev/null +++ b/plugins/scheduler-docker-local/internal-functions @@ -0,0 +1,89 @@ +#!/usr/bin/env bash +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/common/property-functions" +set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x + +cmd-scheduler-docker-local-report() { + declare desc="displays a scheduler-docker-local report for one or more apps" + local cmd="scheduler-docker-local:report" + local INSTALLED_APPS=$(dokku_apps) + local APP="$2" INFO_FLAG="$3" + + if [[ -n "$APP" ]] && [[ "$APP" == --* ]]; then + INFO_FLAG="$APP" + APP="" + fi + + if [[ -z "$APP" ]] && [[ -z "$INFO_FLAG" ]]; then + INFO_FLAG="true" + fi + + if [[ -z "$APP" ]]; then + for app in $INSTALLED_APPS; do + cmd-scheduler-docker-local-report-single "$app" "$INFO_FLAG" | tee || true + done + else + cmd-scheduler-docker-local-report-single "$APP" "$INFO_FLAG" + fi +} + +cmd-scheduler-docker-local-report-single() { + declare APP="$1" INFO_FLAG="$2" + if [[ "$INFO_FLAG" == "true" ]]; then + INFO_FLAG="" + fi + verify_app_name "$APP" + local flag_map=( + "--scheduler-docker-local-disable-chown: $(fn-plugin-property-get "scheduler-docker-local" "$APP" "disable-chown" "")" + ) + + if [[ -z "$INFO_FLAG" ]]; then + dokku_log_info2_quiet "${APP} scheduler-docker-local information" + for flag in "${flag_map[@]}"; do + key="$(echo "${flag#--}" | cut -f1 -d' ' | tr - ' ')" + dokku_log_verbose "$(printf "%-30s %-25s" "${key^}" "${flag#*: }")" + done + else + local match=false; local value_exists=false + for flag in "${flag_map[@]}"; do + valid_flags="${valid_flags} $(echo "$flag" | cut -d':' -f1)" + if [[ "$flag" == "${INFO_FLAG}:"* ]]; then + value=${flag#*: } + size="${#value}" + if [[ "$size" -ne 0 ]]; then + echo "$value" && match=true && value_exists=true + else + match=true + fi + fi + done + [[ "$match" == "true" ]] || dokku_log_fail "Invalid flag passed, valid flags:${valid_flags}" + [[ "$value_exists" == "true" ]] || dokku_log_fail "not deployed" + fi +} + +scheduler_docker_local_help_content_func() { + declare desc="return scheduler-docker-local plugin help content" + cat<] [], Displays a scheduler-docker-local report for one or more apps + scheduler-docker-local:set (), Set or clear a scheduler-docker-local property for an app +help_content +} + +cmd-scheduler-docker-local-help() { + if [[ $1 = "scheduler-docker-local:help" ]] ; then + echo -e 'Usage: dokku scheduler-docker-local[:COMMAND]' + echo '' + echo 'Manages the scheduler-docker-local integration for an app.' + echo '' + echo 'Additional commands:' + scheduler_docker_local_help_content_func | sort | column -c2 -t -s, + echo '' + elif [[ $(ps -o command= $PPID) == *"--all"* ]]; then + scheduler_docker_local_help_content_func + else + cat<