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.
This commit is contained in:
41
plugins/named-containers/core-post-deploy
Executable file
41
plugins/named-containers/core-post-deploy
Executable file
@@ -0,0 +1,41 @@
|
||||
#!/usr/bin/env bash
|
||||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||
|
||||
named_containers_core_post_deploy() {
|
||||
declare desc="names deployed app container is consistent manner"
|
||||
local trigger="named_containers_core_post_deploy"
|
||||
local APP="$1"; local APP_ROOT="$DOKKU_ROOT/$APP"
|
||||
local container
|
||||
|
||||
shopt -s nullglob
|
||||
for container in $APP_ROOT/CONTAINER.*; do
|
||||
local DYNO=$(echo "$container" | sed -r 's/.*CONTAINER\.(.*)/\1/') || true
|
||||
local NAME="$APP.$DYNO"
|
||||
local CURRENT_CONTAINER_ID="$(< "$container")"
|
||||
local PREVIOUS_CIDS=$(docker ps -a -q -f name="^.?$NAME\$" | xargs) || true
|
||||
if [[ -n $PREVIOUS_CIDS ]]; then
|
||||
dokku_log_info1_quiet "Found previous container(s) ($PREVIOUS_CIDS) named $NAME"
|
||||
# in case $PREVIOUS_CIDS has more than one entry
|
||||
local cid
|
||||
for cid in $PREVIOUS_CIDS; do
|
||||
local PREVIOUS_CONTAINER_STATUS=$(docker inspect -f '{{.State.Status}}' "$cid" || echo "dead")
|
||||
# dead containers cannot be renamed
|
||||
if [[ "$PREVIOUS_CONTAINER_STATUS" != "dead" ]]; then
|
||||
local CONTAINER_DATE_NAME="$NAME.$(date +%s)"
|
||||
dokku_log_info2_quiet "renaming container ($cid) ${NAME} to $CONTAINER_DATE_NAME"
|
||||
docker rename "$NAME" "$CONTAINER_DATE_NAME" > /dev/null
|
||||
fi
|
||||
done
|
||||
fi
|
||||
local ID=$(cat "$container")
|
||||
local CURRENT_NAME=$(docker inspect -f '{{.Name}}' "$ID" | tr -d /)
|
||||
if [[ -n "$CURRENT_NAME" ]]; then
|
||||
dokku_log_info2_quiet "renaming container (${ID:0:12}) $CURRENT_NAME to $NAME"
|
||||
docker rename "$CURRENT_NAME" "$NAME" > /dev/null
|
||||
fi
|
||||
done
|
||||
shopt -u nullglob
|
||||
}
|
||||
|
||||
named_containers_core_post_deploy "$@"
|
||||
Reference in New Issue
Block a user