WangDL 9e5fb7cb40
Some checks failed
Deploy API Server / build-and-deploy (push) Failing after 12s
fix: add backend health check + HTTPS nginx config with SSL support
2026-05-18 14:44:39 +08:00

60 lines
1.7 KiB
YAML

name: Deploy API Server
on:
push:
branches: [main]
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout latest code
run: |
if [ -d /tmp/api-server ]; then
cd /tmp/api-server && git pull
else
git clone http://localhost:3000/suche-Hermes/api-server.git /tmp/api-server
fi
- name: Build Docker image
run: cd /tmp/api-server && docker build -t zhixi-api:latest .
- name: Stop old container
run: docker stop zhixi-api 2>/dev/null || true
- name: Remove old container
run: docker rm zhixi-api 2>/dev/null || true
- name: Ensure infrastructure is ready
run: |
# Create network if missing
docker network inspect zhixi-net >/dev/null 2>&1 || docker network create zhixi-net
# Start MySQL + Redis via docker compose (try common locations)
for dir in /opt/zhixi /root/zhixi /tmp/api-server; do
if [ -f "$dir/docker-compose.yml" ]; then
cd "$dir" && docker compose up -d mysql redis 2>/dev/null || true
break
fi
done
sleep 3
- name: Start new container
run: |
ENV_FILE=""
if [ -f /etc/zhixi/.env.production ]; then
ENV_FILE="--env-file /etc/zhixi/.env.production"
fi
docker run -d \
--name zhixi-api \
--network zhixi-net \
--restart unless-stopped \
-p 3001:3000 \
$ENV_FILE \
zhixi-api:latest
- name: Health check
run: |
sleep 8
curl -f http://localhost:3001/health || (docker logs zhixi-api --tail 30 && exit 1)