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
|
- name: Ensure API backend is running
|
||||||
run: |
|
run: |
|
||||||
# Start MySQL + Redis via docker compose (try common locations)
|
set -x
|
||||||
for dir in /opt/zhixi /root/zhixi /home/*/zhixi; do
|
|
||||||
if [ -f "$dir/docker-compose.yml" ]; then
|
# Clone or pull api-server repo for docker-compose.yml
|
||||||
cd "$dir" && docker compose up -d mysql redis 2>/dev/null || true
|
if [ -d /tmp/api-server ]; then
|
||||||
break
|
cd /tmp/api-server && git pull 2>/dev/null || true
|
||||||
fi
|
else
|
||||||
done
|
git clone http://localhost:3000/suche-Hermes/api-server.git /tmp/api-server 2>/dev/null || true
|
||||||
|
fi
|
||||||
|
|
||||||
# Create shared network if missing
|
# Create shared network if missing
|
||||||
docker network inspect zhixi-net >/dev/null 2>&1 || docker network create zhixi-net
|
docker network inspect zhixi-net >/dev/null 2>&1 || docker network create zhixi-net
|
||||||
|
|
||||||
# Restart API container if not running
|
# Start MySQL + Redis via docker compose
|
||||||
if ! docker ps --format '{{.Names}}' | grep -q '^zhixi-api$'; then
|
if [ -f /tmp/api-server/docker-compose.yml ]; then
|
||||||
echo "[deploy] zhixi-api is down, attempting restart..."
|
cd /tmp/api-server && docker compose up -d mysql redis 2>&1 || true
|
||||||
docker start zhixi-api 2>/dev/null || true
|
fi
|
||||||
sleep 5
|
|
||||||
|
# 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
|
fi
|
||||||
|
|
||||||
# Health check
|
# Health check
|
||||||
@ -61,9 +90,12 @@ jobs:
|
|||||||
echo "[deploy] Backend health OK"
|
echo "[deploy] Backend health OK"
|
||||||
else
|
else
|
||||||
echo "[deploy] WARNING: Backend health check failed"
|
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
|
fi
|
||||||
|
|
||||||
|
set +x
|
||||||
|
|
||||||
- name: Install Nginx config (HTTPS)
|
- name: Install Nginx config (HTTPS)
|
||||||
run: |
|
run: |
|
||||||
if [ -f /etc/letsencrypt/live/longde.cloud/fullchain.pem ]; then
|
if [ -f /etc/letsencrypt/live/longde.cloud/fullchain.pem ]; then
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user