fix: robust backend startup — clone api-server repo, build image, full infrastructure
All checks were successful
Deploy Website / build-and-deploy (push) Successful in 14s
All checks were successful
Deploy Website / build-and-deploy (push) Successful in 14s
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
parent
87e904b97e
commit
07feed61b8
@ -38,22 +38,51 @@ jobs:
|
||||
|
||||
- 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
|
||||
set -x
|
||||
|
||||
# Clone or pull api-server repo for docker-compose.yml
|
||||
if [ -d /tmp/api-server ]; then
|
||||
cd /tmp/api-server && git pull 2>/dev/null || true
|
||||
else
|
||||
git clone http://localhost:3000/suche-Hermes/api-server.git /tmp/api-server 2>/dev/null || true
|
||||
fi
|
||||
|
||||
# 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
|
||||
# Start MySQL + Redis via docker compose
|
||||
if [ -f /tmp/api-server/docker-compose.yml ]; then
|
||||
cd /tmp/api-server && docker compose up -d mysql redis 2>&1 || true
|
||||
fi
|
||||
|
||||
# Wait for MySQL to be ready
|
||||
sleep 5
|
||||
|
||||
# Check current state
|
||||
echo "=== Container status ==="
|
||||
docker ps -a --format 'table {{.Names}}\t{{.Status}}' 2>/dev/null | grep -iE 'zhixi|mysql|redis' || true
|
||||
|
||||
# If API container exists but stopped, start it
|
||||
if docker ps -a --format '{{.Names}}' | grep -q '^zhixi-api$'; then
|
||||
if ! docker ps --format '{{.Names}}' | grep -q '^zhixi-api$'; then
|
||||
echo "[deploy] zhixi-api exists but stopped, starting..."
|
||||
docker start zhixi-api 2>&1 || true
|
||||
sleep 8
|
||||
fi
|
||||
else
|
||||
# No container — create one
|
||||
echo "[deploy] zhixi-api not found, building and creating..."
|
||||
cd /tmp/api-server && docker build -t zhixi-api:latest . 2>&1 || true
|
||||
ENV_FILE=""
|
||||
[ -f /etc/zhixi/.env.production ] && ENV_FILE="--env-file /etc/zhixi/.env.production"
|
||||
docker run -d \
|
||||
--name zhixi-api \
|
||||
--network zhixi-net \
|
||||
--restart unless-stopped \
|
||||
-p 3001:3000 \
|
||||
$ENV_FILE \
|
||||
zhixi-api:latest 2>&1 || true
|
||||
sleep 8
|
||||
fi
|
||||
|
||||
# Health check
|
||||
@ -61,9 +90,12 @@ jobs:
|
||||
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
|
||||
echo "=== API container logs (tail 40) ==="
|
||||
docker logs zhixi-api --tail 40 2>&1 || true
|
||||
fi
|
||||
|
||||
set +x
|
||||
|
||||
- name: Install Nginx config (HTTPS)
|
||||
run: |
|
||||
if [ -f /etc/letsencrypt/live/longde.cloud/fullchain.pem ]; then
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user