Files
mb-grid-solutions.com/.gitea/workflows/deploy.yml
Marc Mintel a3ae48b145
All checks were successful
Build & Deploy / deploy (push) Successful in 30s
deploy
2026-01-21 13:22:01 +01:00

139 lines
4.8 KiB
YAML

name: Build & Deploy
on:
push:
branches:
- main
jobs:
deploy:
runs-on: docker
steps:
# --- Checkout ---
- name: Checkout repo
uses: actions/checkout@v3
# --- Tools ---
- name: Install tools
run: |
apt-get update
apt-get install -y \
docker.io \
openssh-client \
rsync
# --- Docker registry login ---
- name: Login to registry
env:
REGISTRY_USER: ${{ secrets.REGISTRY_USER }}
REGISTRY_PASS: ${{ secrets.REGISTRY_PASS }}
run: |
echo "$REGISTRY_PASS" | docker login registry.infra.mintel.me \
-u "$REGISTRY_USER" \
--password-stdin
# --- Build image ---
- name: Build image
run: |
echo "Starting Docker build..."
docker build \
--pull \
-t registry.infra.mintel.me/mintel/mb-grid-solutions:latest .
echo "Docker build completed successfully"
echo "Built image:"
docker images registry.infra.mintel.me/mintel/mb-grid-solutions:latest --format "table {{.Repository}}:{{.Tag}}\t{{.ID}}\t{{.CreatedSince}}"
# --- Push image ---
- name: Push image
run: |
echo "Starting Docker push..."
docker push registry.infra.mintel.me/mintel/mb-grid-solutions:latest
echo "Docker push completed successfully"
# --- SSH setup ---
- name: Setup SSH
run: |
mkdir -p ~/.ssh
printf "%s\n" "${{ secrets.ALPHA_SSH_KEY }}" > ~/.ssh/id_ed25519
chmod 600 ~/.ssh/id_ed25519
ssh-keyscan -H alpha.mintel.me >> ~/.ssh/known_hosts
# --- Sync files ---
- name: Sync files to server
run: |
echo "Starting file sync to server..."
echo "Syncing docker-compose.yaml to alpha.mintel.me..."
tar czf - docker-compose.yaml | \
ssh -i ~/.ssh/id_ed25519 -o StrictHostKeyChecking=no -o IPQoS=0x00 deploy@alpha.mintel.me \
"mkdir -p /home/deploy/sites/mb-grid-solutions.com/ && tar xzf - -C /home/deploy/sites/mb-grid-solutions.com/ && echo 'Files synced successfully' && ls -la /home/deploy/sites/mb-grid-solutions.com/"
echo "File sync completed"
# --- Deploy ---
- name: Deploy on server
env:
REGISTRY_USER: ${{ secrets.REGISTRY_USER }}
REGISTRY_PASS: ${{ secrets.REGISTRY_PASS }}
run: |
echo "Starting deployment on server..."
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'
cd /home/deploy/sites/mb-grid-solutions.com || { echo 'Directory not found!'; exit 1; }
echo ''
echo '=== Current status before deploy ==='
docker compose ps -a || true
echo ''
echo '=== Current local image ==='
docker images registry.infra.mintel.me/mintel/mb-grid-solutions:latest --format 'table {{.Repository}}:{{.Tag}}\t{{.ID}}\t{{.CreatedSince}}' || echo 'No image found'
echo ''
echo '=== Pulling latest image (force) ==='
docker compose pull app || { echo 'Pull failed!'; exit 1; }
echo ''
echo '=== Stopping and removing old containers ==='
docker compose down app --remove-orphans || true
docker compose rm -f app || true
echo ''
echo '=== Starting services with force-recreate and no-build ==='
docker compose up -d --pull always --force-recreate --no-build --no-deps app
echo ''
echo '=== Waiting for containers to become healthy (max 30s) ==='
for i in {1..6}; do
echo \"Attempt \$i/6...\"
if docker compose ps --format '{{.Status}}' | grep -q 'healthy'; then
echo 'All containers healthy!'
break
fi
sleep 5
done
echo ''
echo '=== Final status ==='
docker compose ps -a
echo ''
echo '=== Image now in use ==='
docker compose ps --format '{{.Name}}\t{{.Image}}\t{{.Status}}'
echo ''
echo '=== Last 40 lines of logs ==='
docker compose logs --tail=40 app || true
echo ''
echo '=== Pruning dangling & old images (keep last 24h) ==='
docker image prune -f --filter 'until=24h' || true
echo ''
echo '=== Deployment completed ==='
"
echo "Deployment process finished"