fix: rewrite deploy workflow to use SSH-based deployment
Use ubuntu-24.04 runner with SSH to 192.168.1.151 (same pattern as memento project). Self-hosted runner is not needed on the server. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -1,104 +1,109 @@
|
|||||||
name: Deploy to Homelab
|
name: Deploy to Production
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- production-deployment
|
- production-deployment
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
deploy:
|
deploy:
|
||||||
name: Deploy Wordly to 192.168.1.151
|
name: Build and Deploy
|
||||||
runs-on: self-hosted
|
runs-on: ubuntu-24.04
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Setup SSH
|
||||||
uses: actions/checkout@v4
|
|
||||||
with:
|
|
||||||
ref: production-deployment
|
|
||||||
|
|
||||||
- name: Copy environment file
|
|
||||||
run: |
|
run: |
|
||||||
if [ ! -f .env ]; then
|
mkdir -p ~/.ssh
|
||||||
echo "WARNING: .env file not found. Creating from template."
|
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
|
||||||
echo "You must manually set secrets in .env on the server."
|
chmod 600 ~/.ssh/id_rsa
|
||||||
cp .env.production .env
|
ssh-keyscan -H 192.168.1.151 >> ~/.ssh/known_hosts
|
||||||
fi
|
|
||||||
|
|
||||||
- name: Build and start services
|
- name: Deploy via SSH
|
||||||
run: |
|
run: |
|
||||||
docker compose build --no-cache backend frontend
|
ssh root@192.168.1.151 << 'ENDSSH'
|
||||||
docker compose up -d
|
set -e
|
||||||
|
cd /opt/wordly
|
||||||
|
|
||||||
- name: Wait for services to be healthy
|
echo "=== Git pull ==="
|
||||||
run: |
|
git config --global --add safe.directory /opt/wordly
|
||||||
echo "Waiting for services to start..."
|
git fetch origin production-deployment
|
||||||
sleep 15
|
git reset --hard origin/production-deployment
|
||||||
|
|
||||||
# Check each service
|
echo "=== Building images ==="
|
||||||
SERVICES="wordly-postgres wordly-redis wordly-backend wordly-frontend"
|
docker compose build backend frontend
|
||||||
FAILED=0
|
|
||||||
|
|
||||||
for svc in $SERVICES; do
|
echo "=== Starting services ==="
|
||||||
STATUS=$(docker inspect --format='{{.State.Status}}' $svc 2>/dev/null || echo "not found")
|
docker compose up -d --remove-orphans
|
||||||
if [ "$STATUS" = "running" ]; then
|
|
||||||
echo " $svc: RUNNING"
|
|
||||||
else
|
|
||||||
echo " $svc: $STATUS (may still be starting)"
|
|
||||||
FAILED=$((FAILED + 1))
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
# Wait more for slow services
|
echo "=== Waiting for postgres ==="
|
||||||
sleep 20
|
for i in $(seq 1 30); do
|
||||||
|
if docker compose exec -T postgres pg_isready -U translate >/dev/null 2>&1; then
|
||||||
# Final health check on backend
|
echo "Postgres ready after $((i * 2))s"
|
||||||
for i in $(seq 1 10); do
|
|
||||||
if curl -sf http://localhost:8001/health > /dev/null 2>&1; then
|
|
||||||
echo "Backend health check: OK"
|
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
echo "Waiting for backend... attempt $i/10"
|
if [ "$i" -eq 30 ]; then
|
||||||
|
echo "ERROR: Postgres not ready after 60s"
|
||||||
|
docker compose logs postgres --tail=30
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
sleep 2
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "=== Waiting for backend healthy ==="
|
||||||
|
for i in $(seq 1 20); do
|
||||||
|
if curl -sf http://localhost:8001/health >/dev/null 2>&1; then
|
||||||
|
echo "Backend healthy after $((i * 5))s"
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
if [ "$i" -eq 20 ]; then
|
||||||
|
echo "ERROR: Backend not healthy after 100s"
|
||||||
|
docker compose logs backend --tail=50
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
sleep 5
|
sleep 5
|
||||||
done
|
done
|
||||||
|
|
||||||
if ! curl -sf http://localhost:8000/health > /dev/null 2>&1; then
|
echo "=== Deploy summary ==="
|
||||||
echo "ERROR: Backend health check failed after 50 seconds"
|
|
||||||
docker compose logs --tail=30 backend
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
- name: Cleanup old images
|
|
||||||
run: |
|
|
||||||
docker image prune -f --filter "until=48h" 2>/dev/null || true
|
|
||||||
|
|
||||||
- name: Deploy summary
|
|
||||||
run: |
|
|
||||||
echo "========================================="
|
|
||||||
echo " Wordly Deployment Complete"
|
|
||||||
echo "========================================="
|
|
||||||
docker compose ps
|
docker compose ps
|
||||||
echo ""
|
|
||||||
echo "Health: $(curl -sf http://localhost:8001/health 2>/dev/null || echo 'FAILED')"
|
echo "Health: $(curl -sf http://localhost:8001/health 2>/dev/null || echo 'FAILED')"
|
||||||
echo "========================================="
|
ENDSSH
|
||||||
|
|
||||||
|
- name: Wait for frontend
|
||||||
|
run: |
|
||||||
|
echo "Waiting for frontend..."
|
||||||
|
for i in $(seq 1 20); do
|
||||||
|
CODE=$(curl -s -o /dev/null -w "%{http_code}" --max-time 5 http://192.168.1.151:3000/ || echo "000")
|
||||||
|
if [ "$CODE" != "000" ] && [ "$CODE" -lt 500 ]; then
|
||||||
|
echo "Frontend OK (HTTP $CODE) after $((i * 5))s"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
echo " [$((i * 5))s] HTTP $CODE"
|
||||||
|
sleep 5
|
||||||
|
done
|
||||||
|
echo "Timeout!"
|
||||||
|
exit 1
|
||||||
|
|
||||||
|
- name: Cleanup
|
||||||
|
if: always()
|
||||||
|
run: ssh root@192.168.1.151 "docker image prune -f" || true
|
||||||
|
|
||||||
# Optional: deploy monitoring stack
|
|
||||||
deploy-monitoring:
|
deploy-monitoring:
|
||||||
name: Deploy Monitoring (if configured)
|
name: Deploy Monitoring
|
||||||
runs-on: self-hosted
|
runs-on: ubuntu-24.04
|
||||||
needs: deploy
|
needs: deploy
|
||||||
if: hashFiles('docker-compose.monitoring.yml') != ''
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Setup SSH
|
||||||
uses: actions/checkout@v4
|
|
||||||
with:
|
|
||||||
ref: production-deployment
|
|
||||||
|
|
||||||
- name: Start monitoring services
|
|
||||||
run: |
|
run: |
|
||||||
|
mkdir -p ~/.ssh
|
||||||
|
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
|
||||||
|
chmod 600 ~/.ssh/id_rsa
|
||||||
|
ssh-keyscan -H 192.168.1.151 >> ~/.ssh/known_hosts
|
||||||
|
|
||||||
|
- name: Start monitoring
|
||||||
|
run: |
|
||||||
|
ssh root@192.168.1.151 << 'ENDSSH'
|
||||||
|
cd /opt/wordly
|
||||||
docker compose -f docker-compose.yml -f docker-compose.monitoring.yml up -d prometheus grafana node-exporter cadvisor
|
docker compose -f docker-compose.yml -f docker-compose.monitoring.yml up -d prometheus grafana node-exporter cadvisor
|
||||||
continue-on-error: true
|
|
||||||
|
|
||||||
- name: Monitoring status
|
|
||||||
run: |
|
|
||||||
echo "Monitoring services:"
|
|
||||||
docker compose -f docker-compose.yml -f docker-compose.monitoring.yml ps
|
docker compose -f docker-compose.yml -f docker-compose.monitoring.yml ps
|
||||||
|
ENDSSH
|
||||||
continue-on-error: true
|
continue-on-error: true
|
||||||
|
|||||||
Reference in New Issue
Block a user