fix: remove stale containers before compose recreate on deploy
Prevent docker name conflicts when a prior deploy fails mid-recreate.
This commit is contained in:
1 parent
d3c26a453e
commit
b02add914e
1 file changed
+10
@@ -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
|
||||
|
||||
Reference in new issue
Block a user