From b02add914e0dad25f3eeacd8d3b769e325491ec5 Mon Sep 17 00:00:00 2001 From: 1sonhador <1sonhador@gmail.com> Date: Thu, 2 Jul 2026 23:02:43 +0100 Subject: [PATCH] fix: remove stale containers before compose recreate on deploy Prevent docker name conflicts when a prior deploy fails mid-recreate. --- deploy/deploy-pull.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/deploy/deploy-pull.sh b/deploy/deploy-pull.sh index 612db33..c214493 100644 --- a/deploy/deploy-pull.sh +++ b/deploy/deploy-pull.sh @@ -9,6 +9,13 @@ STATUS_FILE="$REPO_DIR/storage/deploy-logs/last-deploy.status" log() { echo "[$(date '+%Y-%m-%d %H:%M:%S')] [forwarder-deploy] $*"; } +remove_stale_service_containers() { + local service="$1" + local container="forwarder-${service}-1" + docker rm -f "$container" 2>/dev/null || true + docker ps -a --format '{{.Names}}' | grep "_${container}$" | xargs -r docker rm -f || true +} + write_status() { mkdir -p "$(dirname "$STATUS_FILE")" echo "$1" > "$STATUS_FILE" @@ -52,9 +59,12 @@ log "Building API + worker ($GIT_SHA)" $COMPOSE build --build-arg FORWARDER_GIT_SHA="$GIT_SHA" api worker migrate log "Running migrations" $COMPOSE run --rm migrate + remove_stale_service_containers api + remove_stale_service_containers worker $COMPOSE up -d --force-recreate api worker log "Building admin UI ($GIT_SHA)" $COMPOSE build --build-arg GIT_SHA="$GIT_SHA" web + remove_stale_service_containers web $COMPOSE up -d --force-recreate web for i in 1 2 3 4 5; do curl -sf --max-time 8 http://127.0.0.1:8000/api/health >/dev/null && break