diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml index cd79e3b..7329b11 100644 --- a/.gitea/workflows/deploy.yml +++ b/.gitea/workflows/deploy.yml @@ -55,7 +55,7 @@ jobs: - name: Setup SSH run: | mkdir -p ~/.ssh - printf "%s\n" "${{ secrets.ALPHA_SSH_KEY }}" > ~/.ssh/id_ed25519 + echo "${{ secrets.ALPHA_SSH_KEY }}" > ~/.ssh/id_ed25519 chmod 600 ~/.ssh/id_ed25519 ssh-keyscan -H alpha.mintel.me >> ~/.ssh/known_hosts @@ -77,57 +77,45 @@ jobs: 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 on server ===' - echo '$REGISTRY_PASS' | docker login registry.infra.mintel.me -u '$REGISTRY_USER' --password-stdin - echo 'Registry login successful' - + + echo '=== Starting deployment ===' cd /home/deploy/sites/mb-grid-solutions.com - - echo '' - echo '=== Checking current container status ===' - docker compose ps app || echo 'No running containers found' - - echo '' - echo '=== Checking current image ===' - docker images registry.infra.mintel.me/mintel/mb-grid-solutions:latest --format 'table {{.Repository}}:{{.Tag}}\t{{.ID}}\t{{.CreatedSince}}' || echo 'No local image found' - - echo '' + + 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 app - echo 'Image pull completed' - - echo '' - echo '=== Checking pulled image ===' - docker images registry.infra.mintel.me/mintel/mb-grid-solutions:latest --format 'table {{.Repository}}:{{.Tag}}\t{{.ID}}\t{{.CreatedSince}}' - - echo '' - echo '=== Force recreating and restarting app container ===' + echo '✓ Image pulled successfully' + + echo '=== Verifying new image ===' + docker images registry.infra.mintel.me/mintel/mb-grid-solutions:latest + + echo '=== Stopping and recreating containers ===' docker compose up -d --force-recreate app - - echo '' - echo '=== Waiting for container to be healthy (10 seconds) ===' - sleep 10 - - echo '' - echo '=== Checking container status after deployment ===' + echo '✓ Containers recreated' + + echo '=== Waiting for health check (15 seconds) ===' + sleep 15 + + echo '=== Verifying deployment ===' docker compose ps app - - echo '' - echo '=== Checking container logs (last 30 lines) ===' - docker compose logs --tail=30 app - - echo '' - echo '=== Pruning old images (keep last 24h) ===' + + echo '=== Checking container logs ===' + docker compose logs --tail=20 app + + echo '=== Cleaning up old images ===' docker image prune -f --filter 'until=24h' - - echo '' - echo '=== Final status check ===' - docker compose ps app - - echo '' + echo '=== Deployment completed successfully ===' " - echo "Deployment process finished" \ No newline at end of file + + echo "Deployment completed" \ No newline at end of file