Auto-deploys to 192.168.1.151 on push to production-deployment: - Builds backend and frontend Docker images - Starts all services with health checks - Optionally deploys monitoring stack - Cleans up old images Requires a self-hosted runner on the target server. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
105 lines
3.2 KiB
YAML
105 lines
3.2 KiB
YAML
name: Deploy to Homelab
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- production-deployment
|
|
|
|
jobs:
|
|
deploy:
|
|
name: Deploy Wordly to 192.168.1.151
|
|
runs-on: self-hosted
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
with:
|
|
ref: production-deployment
|
|
|
|
- name: Copy environment file
|
|
run: |
|
|
if [ ! -f .env ]; then
|
|
echo "WARNING: .env file not found. Creating from template."
|
|
echo "You must manually set secrets in .env on the server."
|
|
cp .env.production .env
|
|
fi
|
|
|
|
- name: Build and start services
|
|
run: |
|
|
docker compose build --no-cache backend frontend
|
|
docker compose up -d
|
|
|
|
- name: Wait for services to be healthy
|
|
run: |
|
|
echo "Waiting for services to start..."
|
|
sleep 15
|
|
|
|
# Check each service
|
|
SERVICES="wordly-postgres wordly-redis wordly-backend wordly-frontend"
|
|
FAILED=0
|
|
|
|
for svc in $SERVICES; do
|
|
STATUS=$(docker inspect --format='{{.State.Status}}' $svc 2>/dev/null || echo "not found")
|
|
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
|
|
sleep 20
|
|
|
|
# Final health check on backend
|
|
for i in $(seq 1 10); do
|
|
if curl -sf http://localhost:8000/health > /dev/null 2>&1; then
|
|
echo "Backend health check: OK"
|
|
break
|
|
fi
|
|
echo "Waiting for backend... attempt $i/10"
|
|
sleep 5
|
|
done
|
|
|
|
if ! curl -sf http://localhost:8000/health > /dev/null 2>&1; then
|
|
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
|
|
echo ""
|
|
echo "Health: $(curl -sf http://localhost:8000/health 2>/dev/null || echo 'FAILED')"
|
|
echo "========================================="
|
|
|
|
# Optional: deploy monitoring stack
|
|
deploy-monitoring:
|
|
name: Deploy Monitoring (if configured)
|
|
runs-on: self-hosted
|
|
needs: deploy
|
|
if: hashFiles('docker-compose.monitoring.yml') != ''
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
with:
|
|
ref: production-deployment
|
|
|
|
- name: Start monitoring services
|
|
run: |
|
|
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
|
|
continue-on-error: true
|