From fabb18c55c4d54d870406513d1a20c3c4f9220ec Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sun, 30 Sep 2018 15:33:42 -0400 Subject: [PATCH 1/2] feat: allow disabling the nginx-vhosts plugin by default This allows us to force another plugin as the default vhost implementation, or disable it altogether in favor of some higher-level proxy implementation, such as one that integrates with service discovery. --- bootstrap.sh | 1 + contrib/dokku-installer.py | 1 + debian/config | 1 + debian/postinst | 6 +++++- debian/postrm | 5 ++++- debian/templates | 5 +++++ docs/getting-started/install/debian.md | 1 + 7 files changed, 18 insertions(+), 2 deletions(-) diff --git a/bootstrap.sh b/bootstrap.sh index 0da17ab04..622928a55 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -173,6 +173,7 @@ install-dokku-from-deb-package() { [[ -n $DOKKU_HOSTNAME ]] && echo "dokku dokku/hostname string $DOKKU_HOSTNAME" | sudo debconf-set-selections [[ -n $DOKKU_SKIP_KEY_FILE ]] && echo "dokku dokku/skip_key_file boolean $DOKKU_SKIP_KEY_FILE" | sudo debconf-set-selections [[ -n $DOKKU_KEY_FILE ]] && echo "dokku dokku/key_file string $DOKKU_KEY_FILE" | sudo debconf-set-selections + [[ -n $DOKKU_NGINX_ENABLE ]] && echo "dokku dokku/nginx_enable string $DOKKU_NGINX_ENABLE" | sudo debconf-set-selections if [[ -n $DOKKU_CHECKOUT ]]; then # shellcheck disable=SC2086 diff --git a/contrib/dokku-installer.py b/contrib/dokku-installer.py index 240900cb6..9fb73bf4b 100755 --- a/contrib/dokku-installer.py +++ b/contrib/dokku-installer.py @@ -120,6 +120,7 @@ class GetHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): proc.stdin.close() proc.wait() + set_debconf_selection('boolean', 'nginx_enable', 'true') set_debconf_selection('boolean', 'skip_key_file', 'true') set_debconf_selection('boolean', 'vhost_enable', vhost_enable) set_debconf_selection('boolean', 'web_config', 'false') diff --git a/debian/config b/debian/config index d988e0516..eab3ea415 100755 --- a/debian/config +++ b/debian/config @@ -17,6 +17,7 @@ if [ $RET = "true" ]; then exit 0 fi +db_input "high" "dokku/nginx_enable" || true db_input "high" "dokku/hostname" || true db_input "high" "dokku/vhost_enable" || true if [ "$ACTION" != "reconfigure" ]; then diff --git a/debian/postinst b/debian/postinst index ac40b8e72..78aa58a91 100755 --- a/debian/postinst +++ b/debian/postinst @@ -59,9 +59,13 @@ case "$1" in fi done + db_get "dokku/nginx_enable" echo "Enabling all core plugins" find ${DOKKU_LIB_ROOT}/core-plugins/available -mindepth 1 -maxdepth 1 -type d -printf '%f\n' | while read -r plugin; do - if [ ! -d ${DOKKU_LIB_ROOT}/plugins/available/$plugin ]; then + if [ "$plugin" = "nginx-vhosts" ] && [ "$RET" = "false" ]; then + echo "Skipping enable of nginx-vhosts plugin" + continue + elif [ ! -d ${DOKKU_LIB_ROOT}/plugins/available/$plugin ]; then ln -s ${DOKKU_LIB_ROOT}/core-plugins/available/$plugin ${DOKKU_LIB_ROOT}/plugins/available/$plugin; PLUGIN_PATH=${DOKKU_LIB_ROOT}/core-plugins plugn enable $plugin PLUGIN_PATH=${DOKKU_LIB_ROOT}/plugins plugn enable $plugin diff --git a/debian/postrm b/debian/postrm index ba0916cb3..f939ee55a 100755 --- a/debian/postrm +++ b/debian/postrm @@ -21,7 +21,10 @@ main() { rm -f /etc/systemd/system/dokku-redeploy.service rm -f /etc/update-motd.d/99-dokku - (nginx -t && service nginx reload) || true + db_get "dokku/nginx_enable" + if [ "$RET" = "true" ]; then + (nginx -t && service nginx reload) || true + fi if [[ "$1" == "purge" ]]; then rm -f /etc/nginx/conf.d/dokku.conf diff --git a/debian/templates b/debian/templates index f3334d60e..e5f314de4 100644 --- a/debian/templates +++ b/debian/templates @@ -22,3 +22,8 @@ Template: dokku/key_file Description: Keyfile for initial user: Type: string Default: /root/.ssh/id_rsa.pub + +Template: dokku/nginx_enable +Description: Enable nginx-vhosts plugin? +Type: boolean +Default: true diff --git a/docs/getting-started/install/debian.md b/docs/getting-started/install/debian.md index 4282d12c3..d902180ce 100644 --- a/docs/getting-started/install/debian.md +++ b/docs/getting-started/install/debian.md @@ -41,3 +41,4 @@ After setting the desired options, proceed with the installation as described ab | dokku/hostname | string | dokku.me | Hostname, used as vhost domain and for showing app URL after deploy | | dokku/skip_key_file| boolean | false | Don't check for the existence of the dokku/key_file. Warning: Setting this to true, will require you to manually add an SSH key later on. | | dokku/key_file | string | /root/.ssh/id_rsa.pub | Path on disk to an SSH key to add to the Dokku user (Will be ignored on `dpkg-reconfigure`) | +| dokku/nginx_enable | boolean | true | Enable nginx-vhosts plugin | From ed190527cea74418f267340714e37930639304a3 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sun, 30 Sep 2018 21:36:53 -0400 Subject: [PATCH 2/2] feat: allow overriding the scheduler globally Being able to override globally is useful for cases where a user will _always_ want their applications to be globally distributed --- plugins/00_dokku-standard/subcommands/run | 2 +- plugins/apps/functions | 4 ++-- plugins/common/functions | 21 ++++++++++++++++--- plugins/logs/subcommands/failed | 2 +- plugins/ps/functions | 4 ++-- plugins/ps/subcommands/restore | 6 +----- plugins/scheduler-docker-local/check-deploy | 2 +- .../scheduler-docker-local/core-post-deploy | 2 +- plugins/scheduler-docker-local/post-delete | 2 +- plugins/scheduler-docker-local/pre-deploy | 2 +- plugins/tags/subcommands/create | 2 +- plugins/tags/subcommands/destroy | 2 +- 12 files changed, 31 insertions(+), 20 deletions(-) diff --git a/plugins/00_dokku-standard/subcommands/run b/plugins/00_dokku-standard/subcommands/run index 8041be46c..b5a4ec6cb 100755 --- a/plugins/00_dokku-standard/subcommands/run +++ b/plugins/00_dokku-standard/subcommands/run @@ -9,7 +9,7 @@ dokku_run_cmd() { verify_app_name "$APP" shift 2 - local DOKKU_SCHEDULER=$(config_get "$APP" DOKKU_SCHEDULER || echo "docker-local") + local DOKKU_SCHEDULER=$(get_app_scheduler "$APP") plugn trigger scheduler-run "$DOKKU_SCHEDULER" "$APP" "$@" } diff --git a/plugins/apps/functions b/plugins/apps/functions index 24d8d7ee4..598dd87f2 100755 --- a/plugins/apps/functions +++ b/plugins/apps/functions @@ -36,7 +36,7 @@ apps_destroy() { echo "Destroying $APP (including all add-ons)" plugn trigger pre-delete "$APP" "$IMAGE_TAG" - local DOKKU_SCHEDULER=$(config_get "$APP" DOKKU_SCHEDULER || echo "docker-local") + local DOKKU_SCHEDULER=$(get_app_scheduler "$APP") local REMOVE_CONTAINERS="true" plugn trigger scheduler-stop "$DOKKU_SCHEDULER" "$APP" "$REMOVE_CONTAINERS" plugn trigger post-delete "$APP" "$IMAGE_TAG" @@ -63,4 +63,4 @@ apps_maybe_create() { suppress_output apps_create "$APP" fi fi -} \ No newline at end of file +} diff --git a/plugins/common/functions b/plugins/common/functions index 926d7a7af..562ee1310 100755 --- a/plugins/common/functions +++ b/plugins/common/functions @@ -221,6 +221,22 @@ get_app_image_name() { echo "$IMAGE" } +get_app_scheduler() { + declare desc="fetch the scheduler for a given application" + declare APP="$1" + local DOKKU_SCHEDULER + + DOKKU_APP_SCHEDULER="$(config_get "$APP" DOKKU_SCHEDULER || true)" + DOKKU_GLOBAL_SCHEDULER="$(config_get --global DOKKU_SCHEDULER || true)" + + DOKKU_SCHEDULER=${DOKKU_APP_SCHEDULER:="$DOKKU_GLOBAL_SCHEDULER"} + if [[ -z "$DOKKU_SCHEDULER" ]]; then + DOKKU_SCHEDULER="docker-local" + fi + + echo "$DOKKU_SCHEDULER" +} + get_running_image_tag() { declare desc="retrieve current image tag for a given app. returns empty string if no deployed containers are found" local APP="$1" @@ -559,7 +575,7 @@ dokku_deploy_cmd() { declare APP="$1" IMAGE_TAG="$2" source "$PLUGIN_AVAILABLE_PATH/config/functions" - local DOKKU_SCHEDULER=$(config_get "$APP" DOKKU_SCHEDULER || echo "docker-local") + local DOKKU_SCHEDULER=$(get_app_scheduler "$APP") plugn trigger scheduler-deploy "$DOKKU_SCHEDULER" "$APP" "$IMAGE_TAG" } @@ -633,8 +649,7 @@ docker_cleanup() { fi dokku_log_info1 "Cleaning up..." - local DOKKU_SCHEDULER="docker-local" - [[ -n "$APP" ]] && DOKKU_SCHEDULER=$(config_get "$APP" DOKKU_SCHEDULER || echo "docker-local") + local DOKKU_SCHEDULER=$(get_app_scheduler "$APP") plugn trigger scheduler-docker-cleanup "$DOKKU_SCHEDULER" "$APP" "$FORCE_CLEANUP" # delete all non-running containers diff --git a/plugins/logs/subcommands/failed b/plugins/logs/subcommands/failed index a064ea6b7..3c9efdecc 100755 --- a/plugins/logs/subcommands/failed +++ b/plugins/logs/subcommands/failed @@ -26,7 +26,7 @@ fn-logs-failed-single() { local DOKKU_SCHEDULER dokku_log_info2_quiet "${APP} failed deploy logs" - DOKKU_SCHEDULER=$(config_get "$APP" DOKKU_SCHEDULER || echo "docker-local") + DOKKU_SCHEDULER=$(get_app_scheduler "$APP") plugn trigger scheduler-logs-failed "$DOKKU_SCHEDULER" "$APP" } diff --git a/plugins/ps/functions b/plugins/ps/functions index 60604924f..cbb1793c6 100755 --- a/plugins/ps/functions +++ b/plugins/ps/functions @@ -119,7 +119,7 @@ ps_stop() { ! (is_deployed "$APP") && dokku_log_warn "App $APP has not been deployed" && exit 0 dokku_log_quiet "Stopping $APP ..." - local DOKKU_SCHEDULER=$(config_get "$APP" DOKKU_SCHEDULER || echo "docker-local") + local DOKKU_SCHEDULER=$(get_app_scheduler "$APP") plugn trigger scheduler-stop "$DOKKU_SCHEDULER" "$APP" plugn trigger post-stop "$APP" } @@ -208,4 +208,4 @@ fn-ps-is-app-running() { declare APP="$1" APP_STATUS=$(fn-ps-app-status "$APP") echo "$APP_STATUS" | cut -d ' ' -f 2 -} \ No newline at end of file +} diff --git a/plugins/ps/subcommands/restore b/plugins/ps/subcommands/restore index 7103f59d8..bbfa86f82 100755 --- a/plugins/ps/subcommands/restore +++ b/plugins/ps/subcommands/restore @@ -10,11 +10,7 @@ ps_restore_cmd() { local APP="$2" local DOKKU_SCHEDULER - DOKKU_SCHEDULER=$(config_get --global DOKKU_SCHEDULER || echo "docker-local") - if [[ -n "$APP" ]]; then - DOKKU_SCHEDULER=$(config_get "$APP" DOKKU_SCHEDULER || echo "docker-local") - fi - + DOKKU_SCHEDULER=$(get_app_scheduler "$APP") plugn trigger pre-restore "$DOKKU_SCHEDULER" if [[ -n "$APP" ]]; then diff --git a/plugins/scheduler-docker-local/check-deploy b/plugins/scheduler-docker-local/check-deploy index cae18ef5a..bbced03f6 100755 --- a/plugins/scheduler-docker-local/check-deploy +++ b/plugins/scheduler-docker-local/check-deploy @@ -43,7 +43,7 @@ scheduler-docker-local-check-deploy() { local trigger="scheduler-docker-local-check-deploy" local APP="$1"; local DOKKU_APP_CONTAINER_ID="$2"; local DOKKU_APP_CONTAINER_TYPE="$3"; local DOKKU_APP_LISTEN_PORT="$4"; local DOKKU_APP_LISTEN_IP="$5" - local DOKKU_SCHEDULER=$(config_get "$APP" DOKKU_SCHEDULER || echo "docker-local") + local DOKKU_SCHEDULER=$(get_app_scheduler "$APP") if [[ "$DOKKU_SCHEDULER" != "docker-local" ]]; then return fi diff --git a/plugins/scheduler-docker-local/core-post-deploy b/plugins/scheduler-docker-local/core-post-deploy index 793c65dfa..f052097fe 100755 --- a/plugins/scheduler-docker-local/core-post-deploy +++ b/plugins/scheduler-docker-local/core-post-deploy @@ -9,7 +9,7 @@ scheduler-docker-local-core-post-deploy() { declare APP="$1"; local APP_ROOT="$DOKKU_ROOT/$APP" - local DOKKU_SCHEDULER=$(config_get "$APP" DOKKU_SCHEDULER || echo "docker-local") + local DOKKU_SCHEDULER=$(get_app_scheduler "$APP") if [[ "$DOKKU_SCHEDULER" != "docker-local" ]]; then return fi diff --git a/plugins/scheduler-docker-local/post-delete b/plugins/scheduler-docker-local/post-delete index fe180e91a..39f753f93 100755 --- a/plugins/scheduler-docker-local/post-delete +++ b/plugins/scheduler-docker-local/post-delete @@ -8,7 +8,7 @@ scheduler-docker-local-post-delete() { declare trigger="scheduler-docker-local post-delete" declare APP="$1" - local DOKKU_SCHEDULER=$(config_get "$APP" DOKKU_SCHEDULER || echo "docker-local") + local DOKKU_SCHEDULER=$(get_app_scheduler "$APP") if [[ "$DOKKU_SCHEDULER" != "docker-local" ]]; then return fi diff --git a/plugins/scheduler-docker-local/pre-deploy b/plugins/scheduler-docker-local/pre-deploy index 68473c25a..cb0f6f378 100755 --- a/plugins/scheduler-docker-local/pre-deploy +++ b/plugins/scheduler-docker-local/pre-deploy @@ -11,7 +11,7 @@ scheduler-docker-local-pre-deploy() { local IMAGE DISABLE_CHOWN DOCKER_ARGS DOKKU_APP_TYPE DOKKU_APP_USER APP_PATHS CONTAINER_PATHS declare -a ARG_ARRAY - local DOKKU_SCHEDULER=$(config_get "$APP" DOKKU_SCHEDULER || echo "docker-local") + local DOKKU_SCHEDULER=$(get_app_scheduler "$APP") if [[ "$DOKKU_SCHEDULER" != "docker-local" ]]; then return fi diff --git a/plugins/tags/subcommands/create b/plugins/tags/subcommands/create index 2a90f8c8c..6c0286d15 100755 --- a/plugins/tags/subcommands/create +++ b/plugins/tags/subcommands/create @@ -10,7 +10,7 @@ tags_create_cmd() { local APP="$2"; local IMAGE_TAG="$3"; local IMAGE_REPO=$(get_app_image_repo "$APP") verify_app_name "$APP" - local DOKKU_SCHEDULER=$(config_get "$APP" DOKKU_SCHEDULER || echo "docker-local") + local DOKKU_SCHEDULER=$(get_app_scheduler "$APP") plugn trigger scheduler-tags-create "$DOKKU_SCHEDULER" "$APP" "$IMAGE_REPO:latest" "$IMAGE_REPO:$IMAGE_TAG" dokku_log_info2_quiet "Added $IMAGE_TAG tag to $IMAGE_REPO" diff --git a/plugins/tags/subcommands/destroy b/plugins/tags/subcommands/destroy index 5a8293c4a..1b285641f 100755 --- a/plugins/tags/subcommands/destroy +++ b/plugins/tags/subcommands/destroy @@ -16,7 +16,7 @@ tags_destroy_cmd() { ;; *) - local DOKKU_SCHEDULER=$(config_get "$APP" DOKKU_SCHEDULER || echo "docker-local") + local DOKKU_SCHEDULER=$(get_app_scheduler "$APP") plugn trigger scheduler-tags-destroy "$DOKKU_SCHEDULER" "$APP" "$IMAGE_REPO" "$IMAGE_TAG" ;; esac