ci: 测试环境补齐自带 PG + DATABASE_URL/JWT_SECRET 注入,后端健康检查加重试

This commit is contained in:
Sisyphus committed 2026-08-24 22:53:46 +08:00
1 parent 8388598bd7
commit 387be2c92e
1 file changed
+33 -3
+33 -3
View File
@@ -53,15 +53,36 @@ jobs:
HOST="${{ secrets.PERLER_DEPLOY_HOST }}" HOST="${{ secrets.PERLER_DEPLOY_HOST }}"
SSH_CMD="ssh -i $HOME/.ssh/id_ed25519_deploy root@$HOST" SSH_CMD="ssh -i $HOME/.ssh/id_ed25519_deploy root@$HOST"
# 生成测试环境专用 compose(镜像来自 registry,数据卷持久化 SQLite) # 生成测试环境专用 compose(自带 PG,镜像来自 registry,数据卷持久化)
cat > /tmp/docker-compose.test.yml <<'COMPOSE_EOF' cat > /tmp/docker-compose.test.yml <<'COMPOSE_EOF'
services: services:
postgres:
image: postgres:17-alpine
container_name: perler-lab-pg
restart: unless-stopped
environment:
POSTGRES_USER: perler
POSTGRES_PASSWORD: "7c5608fe52a5223a6c6107b6"
POSTGRES_DB: perler_lab
volumes:
- pg-data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U perler -d perler_lab"]
interval: 5s
timeout: 3s
retries: 12
networks: [perler-net]
server: server:
image: 156.233.226.46:5000/perler-lab-server:test image: 156.233.226.46:5000/perler-lab-server:test
container_name: perler-lab-server container_name: perler-lab-server
restart: unless-stopped restart: unless-stopped
depends_on:
postgres:
condition: service_healthy
environment: environment:
PORT: "8788" PORT: "8788"
DATABASE_URL: postgres://perler:7c5608fe52a5223a6c6107b6@postgres:5432/perler_lab
JWT_SECRET: "4c695e86451281112d20aae50f1fbde5a30d10f77ce4f750c1873b2d25549c81"
volumes: volumes:
- db-data:/app/data - db-data:/app/data
networks: [perler-net] networks: [perler-net]
@@ -78,6 +99,7 @@ jobs:
perler-net: {} perler-net: {}
volumes: volumes:
db-data: {} db-data: {}
pg-data: {}
COMPOSE_EOF COMPOSE_EOF
$SSH_CMD 'mkdir -p /opt/perler-lab' $SSH_CMD 'mkdir -p /opt/perler-lab'
@@ -102,8 +124,16 @@ jobs:
fi fi
echo "前端 OK" echo "前端 OK"
echo "===== 后端健康 (/health 经容器内自检) =====" echo "===== 后端健康 (/health 容器内自检,带重试) ====="
docker exec perler-lab-server node -e "fetch(\"http://localhost:8788/health\").then(r=>{console.log(\"server /health ->\",r.status);process.exit(r.ok?0:1)}).catch(()=>process.exit(1))" BOK=0
for i in $(seq 1 24); do
if docker exec perler-lab-server node -e "fetch('http://localhost:8788/health').then(r=>process.exit(r.ok?0:1)).catch(()=>process.exit(1))" 2>/dev/null; then BOK=1; break; fi
sleep 5
done
if [ "$BOK" != "1" ]; then
echo "后端健康检查失败"; docker logs perler-lab-server --tail 20; exit 1
fi
echo "后端 OK"
curl -s -o /dev/null -w "首页 HTTP %{http_code}\n" http://127.0.0.1:8080/ curl -s -o /dev/null -w "首页 HTTP %{http_code}\n" http://127.0.0.1:8080/
echo "===== 测试环境部署完成 =====" echo "===== 测试环境部署完成 ====="