deploy
Some checks failed
Build & Deploy KLZ Cables / deploy (push) Failing after 3m49s

This commit is contained in:
2026-01-25 12:20:31 +01:00
parent b3827b95c2
commit aac2cb2041

View File

@@ -92,11 +92,25 @@ jobs:
run: | run: |
echo "Starting deployment on server..." echo "Starting deployment on server..."
# Create deployment script on server # Create environment file for deployment
cat > /tmp/deploy.env << EOF
export REGISTRY_USER='${REGISTRY_USER}'
export REGISTRY_PASS='${REGISTRY_PASS}'
export NEXT_PUBLIC_UMAMI_WEBSITE_ID='${NEXT_PUBLIC_UMAMI_WEBSITE_ID}'
export NEXT_PUBLIC_UMAMI_SCRIPT_URL='${NEXT_PUBLIC_UMAMI_SCRIPT_URL}'
export SENTRY_DSN='${SENTRY_DSN}'
export REDIS_URL='${REDIS_URL}'
export REDIS_KEY_PREFIX='${REDIS_KEY_PREFIX}'
EOF
# Create deployment script
cat > /tmp/deploy.sh << 'DEPLOY_EOF' cat > /tmp/deploy.sh << 'DEPLOY_EOF'
#!/bin/bash #!/bin/bash
set -e set -e
# Load environment variables
source /tmp/deploy.env
echo '=== Starting deployment ===' echo '=== Starting deployment ==='
cd /home/deploy/sites/klz-cables.com cd /home/deploy/sites/klz-cables.com
@@ -110,13 +124,7 @@ jobs:
EOF EOF
echo '=== Logging into Docker registry ===' echo '=== Logging into Docker registry ==='
echo '${REGISTRY_PASS}' | docker login registry.infra.mintel.me -u '${REGISTRY_USER}' --password-stdin echo "${REGISTRY_PASS}" | docker login registry.infra.mintel.me -u "${REGISTRY_USER}" --password-stdin
if [ $? -eq 0 ]; then
echo '✓ Registry login successful'
else
echo '✗ Registry login failed'
exit 1
fi
echo '=== Checking if infra network exists ===' echo '=== Checking if infra network exists ==='
if ! docker network inspect infra >/dev/null 2>&1; then if ! docker network inspect infra >/dev/null 2>&1; then
@@ -127,34 +135,17 @@ jobs:
echo '=== Checking current containers ===' echo '=== Checking current containers ==='
docker compose ps docker compose ps
echo '=== Checking current image ==='
docker images registry.infra.mintel.me/mintel/klz-cables.com:latest
echo '=== Removing local image to force fresh pull ===' echo '=== Removing local image to force fresh pull ==='
docker rmi registry.infra.mintel.me/mintel/klz-cables.com:latest || true docker rmi registry.infra.mintel.me/mintel/klz-cables.com:latest || true
echo '=== Pulling latest image ===' echo '=== Pulling latest image ==='
docker compose pull docker compose pull
echo '✓ Image pull command completed'
echo '=== Verifying new image after pull ==='
docker images registry.infra.mintel.me/mintel/klz-cables.com:latest
echo '=== Checking if image was actually updated ==='
if docker inspect registry.infra.mintel.me/mintel/klz-cables.com:latest >/dev/null 2>&1; then
echo '✓ Image exists locally'
else
echo '✗ Image pull failed - image not found locally'
exit 1
fi
echo '=== Stopping all containers ===' echo '=== Stopping all containers ==='
docker compose down docker compose down
echo '✓ Containers stopped'
echo '=== Starting all containers ===' echo '=== Starting all containers ==='
docker compose up -d docker compose up -d
echo '✓ Containers started'
echo '=== Waiting for containers to be ready (30 seconds) ===' echo '=== Waiting for containers to be ready (30 seconds) ==='
sleep 30 sleep 30
@@ -162,12 +153,6 @@ jobs:
echo '=== Verifying deployment status ===' echo '=== Verifying deployment status ==='
docker compose ps docker compose ps
echo '=== Checking app container logs ==='
docker compose logs --tail=30 app
echo '=== Checking varnish container logs ==='
docker compose logs --tail=20 varnish
echo '=== Verifying application health ===' echo '=== Verifying application health ==='
# Wait a bit more for the app to be fully ready # Wait a bit more for the app to be fully ready
sleep 15 sleep 15
@@ -185,31 +170,40 @@ jobs:
echo '=== Deployment completed successfully ===' echo '=== Deployment completed successfully ==='
DEPLOY_EOF DEPLOY_EOF
# Make script executable and copy to server # Make script executable
chmod +x /tmp/deploy.sh chmod +x /tmp/deploy.sh
# Copy deployment script to server with keep-alive and timeout # SSH options for reliability
scp -i ~/.ssh/id_ed25519 -o StrictHostKeyChecking=no -o IPQoS=0x00 -o ServerAliveInterval=30 -o ServerAliveCountMax=3 -o ConnectTimeout=30 /tmp/deploy.sh deploy@alpha.mintel.me:/tmp/deploy.sh SSH_OPTS="-i ~/.ssh/id_ed25519 -o StrictHostKeyChecking=no -o ConnectTimeout=30 -o ServerAliveInterval=30 -o ServerAliveCountMax=3 -o BatchMode=yes"
# Copy files to server
scp $SSH_OPTS /tmp/deploy.sh /tmp/deploy.env deploy@alpha.mintel.me:/tmp/
# Execute deployment script on server with keep-alive and timeout # Execute deployment script on server with retry mechanism
# Retry up to 3 times if connection is lost MAX_RETRIES=3
for i in {1..3}; do RETRY_COUNT=0
echo "Attempt $i of 3..." SUCCESS=false
if ssh -i ~/.ssh/id_ed25519 -o StrictHostKeyChecking=no -o IPQoS=0x00 -o ServerAliveInterval=30 -o ServerAliveCountMax=3 -o ConnectTimeout=30 -o ServerAliveTimeout=300 deploy@alpha.mintel.me "
set -e while [ $RETRY_COUNT -lt $MAX_RETRIES ]; do
bash /tmp/deploy.sh RETRY_COUNT=$((RETRY_COUNT + 1))
"; then echo "Deployment attempt $RETRY_COUNT of $MAX_RETRIES..."
echo "✓ Deployment successful on attempt $i"
if ssh $SSH_OPTS deploy@alpha.mintel.me "bash /tmp/deploy.sh"; then
echo "✓ Deployment successful!"
SUCCESS=true
break break
else else
echo "✗ Deployment failed on attempt $i" echo "✗ Deployment attempt $RETRY_COUNT failed."
if [ $i -eq 3 ]; then if [ $RETRY_COUNT -lt $MAX_RETRIES ]; then
echo "All deployment attempts failed" echo "Retrying in 10 seconds..."
exit 1 sleep 10
fi fi
echo "Retrying in 10 seconds..."
sleep 10
fi fi
done done
if [ "$SUCCESS" = false ]; then
echo "All deployment attempts failed."
exit 1
fi
echo "Deployment completed" echo "Deployment completed"