WangDL 87e904b97e
All checks were successful
Deploy Website / build-and-deploy (push) Successful in 8s
fix: add backend health check + HTTPS nginx config with SSL support
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-18 14:46:16 +08:00

78 lines
2.8 KiB
YAML

name: Deploy Website
on:
push:
branches: [main]
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout latest code
run: |
if [ -d /tmp/web-projects ]; then
cd /tmp/web-projects && git pull
else
git clone http://localhost:3000/suche-Hermes/web-projects.git /tmp/web-projects
fi
- name: Build Astro site
run: |
docker run --rm \
-v /tmp/web-projects:/app \
-w /app \
node:22-alpine sh -c "npm install && npm run build"
- name: Install Nginx config (HTTP)
run: |
mkdir -p /etc/nginx/conf.d 2>/dev/null
cp /tmp/web-projects/nginx/longde.cloud.conf /etc/nginx/conf.d/longde.cloud.conf
mkdir -p /etc/nginx/sites-available /etc/nginx/sites-enabled 2>/dev/null
cp /tmp/web-projects/nginx/longde.cloud.conf /etc/nginx/sites-available/longde.cloud.conf 2>/dev/null
ln -sf /etc/nginx/sites-available/longde.cloud.conf /etc/nginx/sites-enabled/longde.cloud.conf 2>/dev/null
- name: Deploy to web root
run: |
rm -rf /var/www/longde.cloud/*
cp -r /tmp/web-projects/dist/* /var/www/longde.cloud/
- name: Ensure API backend is running
run: |
# Start MySQL + Redis via docker compose (try common locations)
for dir in /opt/zhixi /root/zhixi /home/*/zhixi; do
if [ -f "$dir/docker-compose.yml" ]; then
cd "$dir" && docker compose up -d mysql redis 2>/dev/null || true
break
fi
done
# Create shared network if missing
docker network inspect zhixi-net >/dev/null 2>&1 || docker network create zhixi-net
# Restart API container if not running
if ! docker ps --format '{{.Names}}' | grep -q '^zhixi-api$'; then
echo "[deploy] zhixi-api is down, attempting restart..."
docker start zhixi-api 2>/dev/null || true
sleep 5
fi
# Health check
if curl -sf http://localhost:3001/health; then
echo "[deploy] Backend health OK"
else
echo "[deploy] WARNING: Backend health check failed"
docker ps --format 'table {{.Names}}\t{{.Status}}' 2>/dev/null | grep -i zhixi || true
fi
- name: Install Nginx config (HTTPS)
run: |
if [ -f /etc/letsencrypt/live/longde.cloud/fullchain.pem ]; then
cp /tmp/web-projects/nginx/longde.cloud-ssl.conf /etc/nginx/conf.d/longde.cloud-ssl.conf
else
echo "[deploy] No SSL cert found, skipping HTTPS config"
rm -f /etc/nginx/conf.d/longde.cloud-ssl.conf
fi
- name: Reload Nginx
run: nginx -s reload || nginx -t 2>&1