better redeploy: reduced downtime

This commit is contained in:
Ludwig Lehnert
2026-03-17 10:08:26 +01:00
parent 6da6db6955
commit 972c1a649f

View File

@@ -10,20 +10,27 @@ if [[ ! -d .git ]]; then
exit 1
fi
log 'Stopping stack'
docker compose down
OLD_COMPOSE_FILE="$(mktemp)"
log 'Removing current local compose image(s)'
mapfile -t IMAGE_NAMES < <(docker compose config --images 2>/dev/null | sed '/^$/d' | sort -u)
if [[ "${#IMAGE_NAMES[@]}" -gt 0 ]]; then
docker image rm -f "${IMAGE_NAMES[@]}" || true
else
log 'No compose-managed local images found to remove.'
cleanup() {
if [[ -f "$OLD_COMPOSE_FILE" ]]; then
rm -f "$OLD_COMPOSE_FILE"
fi
}
trap cleanup EXIT
log 'Capturing current compose configuration'
docker compose config > "$OLD_COMPOSE_FILE"
log 'Pulling latest git changes'
git pull
log 'Building updated images while current stack is running'
docker compose build --no-cache
log 'Stopping previous stack using captured configuration'
docker compose --project-directory "$PWD" -f "$OLD_COMPOSE_FILE" down
log 'Starting stack'
docker compose up -d