Fix container name conflicts in zero-downtime deployment
Some checks failed
CI/CD Pipeline (Zero Downtime) / production (push) Failing after 7m55s
CI/CD Pipeline (Simple) / production (push) Failing after 7m53s

- Use unique timestamp-based container names to avoid conflicts
- Clean up existing temporary containers before starting new ones
- Generate unique names like 'portfolio-app-temp-1234567890'
- Prevents 'container name already in use' errors
- Ensures reliable zero-downtime deployments
This commit is contained in:
2025-09-13 01:24:34 +02:00
parent 89e0f9f2f8
commit 20a6c416e3

View File

@@ -109,9 +109,18 @@ jobs:
if [ "$CURRENT_CONTAINER_RUNNING" = "true" ]; then if [ "$CURRENT_CONTAINER_RUNNING" = "true" ]; then
echo "🔄 Performing rolling update..." echo "🔄 Performing rolling update..."
# Start new container with temporary name (no port mapping needed for health check) # Generate unique container name
TIMESTAMP=$(date +%s)
TEMP_CONTAINER_NAME="portfolio-app-temp-$TIMESTAMP"
echo "🔧 Using temporary container name: $TEMP_CONTAINER_NAME"
# Clean up any existing temporary containers
echo "🧹 Cleaning up any existing temporary containers..."
docker rm -f portfolio-app-new portfolio-app-temp-* || true
# Start new container with unique temporary name (no port mapping needed for health check)
docker run -d \ docker run -d \
--name portfolio-app-new \ --name $TEMP_CONTAINER_NAME \
--restart unless-stopped \ --restart unless-stopped \
--network portfolio_net \ --network portfolio_net \
-e NODE_ENV=${{ vars.NODE_ENV }} \ -e NODE_ENV=${{ vars.NODE_ENV }} \
@@ -134,7 +143,7 @@ jobs:
# Health check new container using docker exec # Health check new container using docker exec
for i in {1..20}; do for i in {1..20}; do
if docker exec portfolio-app-new curl -f http://localhost:3000/api/health > /dev/null 2>&1; then if docker exec $TEMP_CONTAINER_NAME curl -f http://localhost:3000/api/health > /dev/null 2>&1; then
echo "✅ New container is healthy!" echo "✅ New container is healthy!"
break break
fi fi
@@ -150,7 +159,7 @@ jobs:
docker rm portfolio-app || true docker rm portfolio-app || true
# Rename new container # Rename new container
docker rename portfolio-app-new portfolio-app docker rename $TEMP_CONTAINER_NAME portfolio-app
# Update port mapping # Update port mapping
docker stop portfolio-app docker stop portfolio-app