This commit is contained in:
@@ -16,7 +16,10 @@ jobs:
|
||||
- name: Install tools
|
||||
run: |
|
||||
apt-get update
|
||||
apt-get install -y docker.io openssh-client
|
||||
apt-get install -y \
|
||||
docker.io \
|
||||
openssh-client \
|
||||
rsync
|
||||
|
||||
- name: Login to registry
|
||||
env:
|
||||
@@ -60,51 +63,61 @@ jobs:
|
||||
|
||||
echo "Found and syncing: $COMPOSE_FILE"
|
||||
|
||||
ssh -i ~/.ssh/id_ed25519 -o StrictHostKeyChecking=no deploy@alpha.mintel.me \
|
||||
"mkdir -p /home/deploy/sites/klz-cables.com && chmod 775 /home/deploy/sites/klz-cables.com"
|
||||
|
||||
scp -i ~/.ssh/id_ed25519 -o StrictHostKeyChecking=no \
|
||||
"$COMPOSE_FILE" \
|
||||
deploy@alpha.mintel.me:/home/deploy/sites/klz-cables.com/"$COMPOSE_FILE"
|
||||
|
||||
if [ -d "./varnish" ]; then
|
||||
scp -r -i ~/.ssh/id_ed25519 -o StrictHostKeyChecking=no \
|
||||
varnish/ deploy@alpha.mintel.me:/home/deploy/sites/klz-cables.com/
|
||||
echo "varnish synced"
|
||||
fi
|
||||
|
||||
ssh -i ~/.ssh/id_ed25519 -o StrictHostKeyChecking=no deploy@alpha.mintel.me \
|
||||
"chmod 664 /home/deploy/sites/klz-cables.com/$COMPOSE_FILE && \
|
||||
ls -la /home/deploy/sites/klz-cables.com/ && \
|
||||
stat /home/deploy/sites/klz-cables.com/$COMPOSE_FILE && \
|
||||
echo 'Sync completed - using: $COMPOSE_FILE'"
|
||||
# Use tar to bundle files and send them via SSH in a single connection
|
||||
tar czf - "$COMPOSE_FILE" varnish 2>/dev/null || tar czf - "$COMPOSE_FILE" | \
|
||||
ssh -i ~/.ssh/id_ed25519 -o StrictHostKeyChecking=no -o IPQoS=0x00 deploy@alpha.mintel.me \
|
||||
"mkdir -p /home/deploy/sites/klz-cables.com/ && tar xzf - -C /home/deploy/sites/klz-cables.com/ && echo 'Files synced successfully' && ls -la /home/deploy/sites/klz-cables.com/"
|
||||
|
||||
echo "File sync completed"
|
||||
|
||||
- name: Deploy on server
|
||||
env:
|
||||
REGISTRY_USER: ${{ secrets.REGISTRY_USER }}
|
||||
REGISTRY_PASS: ${{ secrets.REGISTRY_PASS }}
|
||||
run: |
|
||||
echo "Starting deployment on server..."
|
||||
|
||||
# Execute deployment commands directly with proper error handling
|
||||
ssh -i ~/.ssh/id_ed25519 -o StrictHostKeyChecking=no -o IPQoS=0x00 deploy@alpha.mintel.me "
|
||||
set -e
|
||||
|
||||
echo 'Logging in to registry...'
|
||||
echo \"\$REGISTRY_PASS\" | docker login registry.infra.mintel.me -u \"\$REGISTRY_USER\" --password-stdin
|
||||
|
||||
cd /home/deploy/sites/klz-cables.com || { echo 'Directory not found!'; exit 1; }
|
||||
|
||||
echo 'Creating .env...'
|
||||
|
||||
echo '=== Starting deployment ==='
|
||||
cd /home/deploy/sites/klz-cables.com
|
||||
|
||||
echo '=== Creating .env ==='
|
||||
echo 'SENTRY_DSN=${{ secrets.SENTRY_DSN }}' > .env
|
||||
|
||||
echo 'Pulling latest image...'
|
||||
|
||||
echo '=== Logging into Docker registry ==='
|
||||
echo '${{ secrets.REGISTRY_PASS }}' | docker login registry.infra.mintel.me -u '${{ secrets.REGISTRY_USER }}' --password-stdin
|
||||
echo '✓ Registry login successful'
|
||||
|
||||
echo '=== Checking current containers ==='
|
||||
docker compose ps
|
||||
|
||||
echo '=== Pulling latest image ==='
|
||||
docker compose pull
|
||||
|
||||
echo 'Force recreating app...'
|
||||
echo '✓ Image pulled successfully'
|
||||
|
||||
echo '=== Verifying new image ==='
|
||||
docker images registry.infra.mintel.me/mintel/klz-cables.com:latest
|
||||
|
||||
echo '=== Stopping and recreating containers ==='
|
||||
docker compose up -d
|
||||
|
||||
echo 'Pruning old images...'
|
||||
docker image prune -f --filter 'until=24h'
|
||||
|
||||
echo 'Deployment finished. Status:'
|
||||
echo '✓ Containers recreated'
|
||||
|
||||
echo '=== Waiting for health check (15 seconds) ==='
|
||||
sleep 15
|
||||
|
||||
echo '=== Verifying deployment ==='
|
||||
docker compose ps app
|
||||
|
||||
echo '=== Checking container logs ==='
|
||||
docker compose logs --tail=20 app
|
||||
"
|
||||
|
||||
echo '=== Cleaning up old images ==='
|
||||
docker image prune -f --filter 'until=24h'
|
||||
|
||||
echo '=== Deployment completed successfully ==='
|
||||
"
|
||||
|
||||
echo "Deployment completed"
|
||||
Reference in New Issue
Block a user