diff --git a/docs/advanced-usage/deployment-tasks.md b/docs/advanced-usage/deployment-tasks.md index 0a42f4edf..64ee09625 100644 --- a/docs/advanced-usage/deployment-tasks.md +++ b/docs/advanced-usage/deployment-tasks.md @@ -15,7 +15,8 @@ Dokku accomplishes this by using an `app.json` file. The format in use is simila However, Dokku currently only supports the nodes `scripts.dokku.predeploy` and `scripts.dokku.postdeploy`. For buildpack apps, simply place an `app.json` file in the root of your repository. For dockerfile apps, place `app.json` in the configured `WORKDIR` directory; otherwise Dokku defaults to the buildpack app behavior of looking in `/app`. ->NOTE: postdeploy changes are *NOT* committed to the app image. + +> NOTE: postdeploy changes are *NOT* committed to the app image. ### Example app.json diff --git a/docs/development/plugin-triggers.md b/docs/development/plugin-triggers.md index 7ca54dc06..846c6fecd 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`. Deployment Tasks are also invoked by this plugin trigger. - Invoked by: `dokku deploy` - Arguments: `$APP $INTERNAL_PORT $INTERNAL_IP_ADDRESS $IMAGE_TAG` - Example: diff --git a/plugins/00_dokku-standard/core-post-deploy b/plugins/00_dokku-standard/core-post-deploy new file mode 100755 index 000000000..7b21978cb --- /dev/null +++ b/plugins/00_dokku-standard/core-post-deploy @@ -0,0 +1,23 @@ +#!/usr/bin/env bash +set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" + +cleanup_container_state() { + declare desc="core post-deploy state cleanup" + 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)" + + local CONTAINER_FILE + for CONTAINER_FILE in $CONTAINER_FILES; do + local CONTAINER_TYPE="$(awk -F '.' '{ print $2 }' <<< "$CONTAINER_FILE")" + if [[ "$(is_val_in_list "$CONTAINER_TYPE" "$PROCTYPES" " ")" == "false" ]]; then + dokku_log_info1 "Container type ($CONTAINER_TYPE) is no longer defined. Removing state" + local IP_FILE="${CONTAINER_FILE//CONTAINER/IP}" + local PORT_FILE="${CONTAINER_FILE//CONTAINER/PORT}" + rm -f "$DOKKU_ROOT/$APP/$CONTAINER_FILE" "$DOKKU_ROOT/$APP/$IP_FILE" "$DOKKU_ROOT/$APP/$PORT_FILE" + fi + done +} + +cleanup_container_state "$@" diff --git a/plugins/00_dokku-standard/post-deploy b/plugins/00_dokku-standard/post-deploy index 7c765c3b3..50603555e 100755 --- a/plugins/00_dokku-standard/post-deploy +++ b/plugins/00_dokku-standard/post-deploy @@ -5,30 +5,11 @@ 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="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)" execute_script "$APP" "$IMAGE_TAG" "$PHASE_SCRIPT_KEY" } -cleanup_container_state() { - declare desc="core post-deploy state cleanup" - local trigger="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)" - - local CONTAINER_FILE - for CONTAINER_FILE in $CONTAINER_FILES; do - local CONTAINER_TYPE="$(awk -F '.' '{ print $2 }' <<< "$CONTAINER_FILE")" - if [[ "$(is_val_in_list "$CONTAINER_TYPE" "$PROCTYPES" " ")" == "false" ]]; then - dokku_log_info1 "Container type ($CONTAINER_TYPE) is no longer defined. Removing state" - local IP_FILE="${CONTAINER_FILE//CONTAINER/IP}" - local PORT_FILE="${CONTAINER_FILE//CONTAINER/PORT}" - rm -f "$DOKKU_ROOT/$APP/$CONTAINER_FILE" "$DOKKU_ROOT/$APP/$IP_FILE" "$DOKKU_ROOT/$APP/$PORT_FILE" - fi - done -} - exec_app_json_scripts "$@" -cleanup_container_state "$@" 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 facc6bc17..68200ab79 100755 --- a/plugins/common/functions +++ b/plugins/common/functions @@ -651,6 +651,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 "$@"