From 2fc3a09b413bc47547ebbb74fc66c1f70455f012 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Mon, 5 Sep 2016 00:04:06 -0400 Subject: [PATCH] Move post-deploy trigger to core-post-deploy. Refs #2367 This avoids issues where community plugins may break core commands because of issues in the command output. --- docs/development/plugin-triggers.md | 22 ++++++++++++++++++- .../{post-deploy => core-post-deploy} | 4 ++-- plugins/20_events/core-post-deploy | 1 + plugins/common/functions | 1 + .../{post-deploy => core-post-deploy} | 6 ++--- .../{post-deploy => core-post-deploy} | 8 +++---- plugins/ps/{post-deploy => core-post-deploy} | 8 +++---- 7 files changed, 36 insertions(+), 14 deletions(-) rename plugins/00_dokku-standard/{post-deploy => core-post-deploy} (92%) create mode 120000 plugins/20_events/core-post-deploy rename plugins/named-containers/{post-deploy => core-post-deploy} (92%) rename plugins/nginx-vhosts/{post-deploy => core-post-deploy} (81%) rename plugins/ps/{post-deploy => core-post-deploy} (69%) diff --git a/docs/development/plugin-triggers.md b/docs/development/plugin-triggers.md index 7ca54dc06..5223ee2f1 100644 --- a/docs/development/plugin-triggers.md +++ b/docs/development/plugin-triggers.md @@ -134,6 +134,24 @@ help_content esac ``` +### `core-post-deploy` + +> To avoid issues with community plugins, this plugin trigger should be used *only* for core plugins. Please avoid using this trigger in your own plugins. + +- Description: Allows running of commands after an application's processes have been scaled up, but before old containers are torn down. Dokku core currently uses this to switch traffic on nginx. +- Invoked by: `dokku deploy` +- Arguments: `$APP $INTERNAL_PORT $INTERNAL_IP_ADDRESS $IMAGE_TAG` +- Example: + +```shell +#!/usr/bin/env bash +# Notify an external service that a successful deploy has occurred. + +set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x + +curl "http://httpstat.us/200" +``` + ### `dependencies` - Description: Used to install system-level dependencies. Invoked by `plugin:install-dependencies`. @@ -430,7 +448,9 @@ dokku postgres:destroy $APP ### `post-deploy` -- Description: Allows running of commands after an application's processes have been scaled up, but before old containers are torn down. Dokku core currently uses this to switch traffic on nginx. +> Please see [core-post-deploy](#core-post-deploy) if contributing a core plugin with the `post-deploy` hook. + +- Description: Allows running of commands after an application's processes have been scaled up, but before old containers are torn down. Dokku calls this _after_ `core-post-deploy`. - Invoked by: `dokku deploy` - Arguments: `$APP $INTERNAL_PORT $INTERNAL_IP_ADDRESS $IMAGE_TAG` - Example: diff --git a/plugins/00_dokku-standard/post-deploy b/plugins/00_dokku-standard/core-post-deploy similarity index 92% rename from plugins/00_dokku-standard/post-deploy rename to plugins/00_dokku-standard/core-post-deploy index 7c765c3b3..a020a1efe 100755 --- a/plugins/00_dokku-standard/post-deploy +++ b/plugins/00_dokku-standard/core-post-deploy @@ -5,7 +5,7 @@ source "$PLUGIN_CORE_AVAILABLE_PATH/00_dokku-standard/exec-app-json-scripts" exec_app_json_scripts() { declare desc="core app.json scripts execution" - local trigger="pre-deploy app_json_scripts" + local trigger="core-post-deploy app_json_scripts" local APP="$1"; local IMAGE_TAG="$4"; local PHASE_SCRIPT_KEY="postdeploy" dokku_log_info1 "Attempting to run scripts.dokku.$PHASE_SCRIPT_KEY from app.json (if defined)" @@ -14,7 +14,7 @@ exec_app_json_scripts() { cleanup_container_state() { declare desc="core post-deploy state cleanup" - local trigger="post-deploy cleanup_container_state" + local trigger="core-post-deploy cleanup_container_state" local APP="$1"; local PROCTYPES="$(egrep -v "^#" "$DOKKU_ROOT/$APP/DOKKU_SCALE" | awk -F '=' '{ print $1 }' | xargs)" local CONTAINER_FILES="$(find "$DOKKU_ROOT/$APP" -maxdepth 1 -name "CONTAINER.*" -printf "%f\n" 2>/dev/null | sort -t . -k 3 -n | xargs)" diff --git a/plugins/20_events/core-post-deploy b/plugins/20_events/core-post-deploy new file mode 120000 index 000000000..5178a749f --- /dev/null +++ b/plugins/20_events/core-post-deploy @@ -0,0 +1 @@ +hook \ No newline at end of file diff --git a/plugins/common/functions b/plugins/common/functions index 3e587d8ec..dc5c75b22 100755 --- a/plugins/common/functions +++ b/plugins/common/functions @@ -646,6 +646,7 @@ dokku_deploy_cmd() { done < "$DOKKU_SCALE_FILE" dokku_log_info1 "Running post-deploy" + plugn trigger core-post-deploy "$APP" "$port" "$ipaddr" "$IMAGE_TAG" plugn trigger post-deploy "$APP" "$port" "$ipaddr" "$IMAGE_TAG" # kill the old container diff --git a/plugins/named-containers/post-deploy b/plugins/named-containers/core-post-deploy similarity index 92% rename from plugins/named-containers/post-deploy rename to plugins/named-containers/core-post-deploy index 2489b71ce..2d84b28c3 100755 --- a/plugins/named-containers/post-deploy +++ b/plugins/named-containers/core-post-deploy @@ -2,9 +2,9 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" -named_containers_post_deploy() { +named_containers_core_post_deploy() { declare desc="names deployed app container is consistent manner" - local trigger="named_containers_post_deploy" + local trigger="named_containers_core_post_deploy" local APP="$1"; local APP_ROOT="$DOKKU_ROOT/$APP" local container @@ -38,4 +38,4 @@ named_containers_post_deploy() { shopt -u nullglob } -named_containers_post_deploy "$@" +named_containers_core_post_deploy "$@" diff --git a/plugins/nginx-vhosts/post-deploy b/plugins/nginx-vhosts/core-post-deploy similarity index 81% rename from plugins/nginx-vhosts/post-deploy rename to plugins/nginx-vhosts/core-post-deploy index f716b0715..7bb7db877 100755 --- a/plugins/nginx-vhosts/post-deploy +++ b/plugins/nginx-vhosts/core-post-deploy @@ -5,9 +5,9 @@ source "$PLUGIN_AVAILABLE_PATH/domains/functions" source "$PLUGIN_AVAILABLE_PATH/nginx-vhosts/functions" source "$PLUGIN_AVAILABLE_PATH/proxy/functions" -nginx_post_deploy() { - declare desc="nginx-vhosts post-deploy plugin trigger" - local trigger="nginx_post_deploy" +nginx_core_post_deploy() { + declare desc="nginx-vhosts core-post-deploy plugin trigger" + local trigger="nginx_core_post_deploy" local APP="$1" if [[ -f "$DOKKU_ROOT/$APP/IP.web.1" ]] && [[ -f "$DOKKU_ROOT/$APP/PORT.web.1" ]]; then if [[ "$(is_app_vhost_enabled "$APP")" == "false" ]]; then @@ -21,5 +21,5 @@ nginx_post_deploy() { } if [[ "$(get_app_proxy_type "$1")" == "nginx" ]]; then - nginx_post_deploy "$@" + nginx_core_post_deploy "$@" fi diff --git a/plugins/ps/post-deploy b/plugins/ps/core-post-deploy similarity index 69% rename from plugins/ps/post-deploy rename to plugins/ps/core-post-deploy index f66170f6f..1fc2e2b6b 100755 --- a/plugins/ps/post-deploy +++ b/plugins/ps/core-post-deploy @@ -4,13 +4,13 @@ source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_AVAILABLE_PATH/config/functions" source "$PLUGIN_AVAILABLE_PATH/ps/functions" -ps_post_deploy() { - declare desc="ps post-deploy plugin trigger" - local trigger="ps_post_deploy" +ps_core_post_deploy() { + declare desc="ps core-post-deploy plugin trigger" + local trigger="ps_core_post_deploy" local APP="$1" remove_procfile "$APP" config_set --no-restart "$APP" DOKKU_APP_RESTORE=1 } -ps_post_deploy "$@" +ps_core_post_deploy "$@"