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 exit 1
fi fi
log 'Stopping stack' OLD_COMPOSE_FILE="$(mktemp)"
docker compose down
log 'Removing current local compose image(s)' cleanup() {
mapfile -t IMAGE_NAMES < <(docker compose config --images 2>/dev/null | sed '/^$/d' | sort -u) if [[ -f "$OLD_COMPOSE_FILE" ]]; then
if [[ "${#IMAGE_NAMES[@]}" -gt 0 ]]; then rm -f "$OLD_COMPOSE_FILE"
docker image rm -f "${IMAGE_NAMES[@]}" || true fi
else }
log 'No compose-managed local images found to remove.' trap cleanup EXIT
fi
log 'Capturing current compose configuration'
docker compose config > "$OLD_COMPOSE_FILE"
log 'Pulling latest git changes' log 'Pulling latest git changes'
git pull 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' log 'Starting stack'
docker compose up -d docker compose up -d