Files
dokku/plugins/scheduler-docker-local/scheduler-stop
Jose Diaz-Gonzalez e53e8bb59f fix: register all containers for retirement on app stop
This ensures that unused docker images are _also_ removed. While this will mean a `ps:start` requires a rebuild in the case of a force-stop, it ensures we don't have unused images when destroying apps.
2021-10-09 18:46:48 -04:00

45 lines
1.5 KiB
Bash
Executable File

#!/usr/bin/env bash
set -eo pipefail
[[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
source "$PLUGIN_AVAILABLE_PATH/config/functions"
trigger-scheduler-docker-local-scheduler-stop() {
declare desc="scheduler-docker-local scheduler-stop plugin trigger"
declare trigger="scheduler-stop"
declare DOKKU_SCHEDULER="$1" APP="$2" REMOVE_CONTAINERS="$3"
if [[ "$DOKKU_SCHEDULER" != "docker-local" ]]; then
return
fi
local DOKKU_APP_RUNNING_CONTAINER_IDS=$(get_app_running_container_ids "$APP" 2>/dev/null)
local DOKKU_DOCKER_STOP_TIMEOUT="$(config_get "$APP" DOKKU_DOCKER_STOP_TIMEOUT || true)"
[[ -n "$DOKKU_DOCKER_STOP_TIMEOUT" ]] && DOCKER_STOP_TIME_ARG="--time=${DOKKU_DOCKER_STOP_TIMEOUT}"
if [[ -n "$DOKKU_APP_RUNNING_CONTAINER_IDS" ]]; then
# Disable the container restart policy
# shellcheck disable=SC2086
"$DOCKER_BIN" container update --restart=no $DOKKU_APP_RUNNING_CONTAINER_IDS &>/dev/null || true
# shellcheck disable=SC2086
"$DOCKER_BIN" container stop $DOCKER_STOP_TIME_ARG $DOKKU_APP_RUNNING_CONTAINER_IDS >/dev/null || true
fi
if [[ "$REMOVE_CONTAINERS" == "true" ]]; then
local DOKKU_APP_CIDS=$(get_app_container_ids "$APP")
if [[ -n "$DOKKU_APP_CIDS" ]]; then
for CID in $DOKKU_APP_CIDS; do
plugn trigger scheduler-register-retired "$APP" "$CID"
done
# shellcheck disable=SC2086
"$DOCKER_BIN" container rm --force $DOKKU_APP_CIDS >/dev/null 2>&1 || true
fi
fi
}
trigger-scheduler-docker-local-scheduler-stop "$@"