All checks were successful
Deploy API Server / build-and-deploy (push) Successful in 3m21s
- test/worker-integration.worker-int-spec.ts (was m-ai-01-09.worker-int-spec) - test/api-e2e.worker-int-spec.ts (was m-ai-01-09-api-e2e.worker-int-spec) - test/run-integration-tests.sh (was run-integration-ci.sh) - CI step: "Worker 集成测试 (BullMQ/MySQL/Redis 真实验证)" - npm script: test:integration Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
136 lines
5.2 KiB
YAML
136 lines
5.2 KiB
YAML
name: Deploy API Server
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
|
|
env:
|
|
DATABASE_URL: mysql://zhixi_user:hKHQ+N0wBjJAiLukFu5OMEI8@127.0.0.1:3306/zhixi_prod
|
|
|
|
jobs:
|
|
build-and-deploy:
|
|
runs-on: prod
|
|
steps:
|
|
- name: Checkout latest code
|
|
run: |
|
|
if [ -d /tmp/api-server ]; then
|
|
cd /tmp/api-server && git fetch origin && git reset --hard origin/main
|
|
else
|
|
git clone http://10.2.0.7:3000/wangdl/api-server.git /tmp/api-server
|
|
fi
|
|
|
|
- name: Install dependencies
|
|
run: |
|
|
cd /tmp/api-server
|
|
npm ci
|
|
|
|
- name: Build
|
|
run: |
|
|
cd /tmp/api-server
|
|
npx prisma generate
|
|
npm run build
|
|
|
|
- name: Ensure infrastructure is ready
|
|
run: |
|
|
docker start mysql redis qdrant 2>/dev/null || true
|
|
sleep 2
|
|
|
|
- name: Resolve failed migrations
|
|
run: |
|
|
MYSQL_CMD="docker exec mysql mysql -u zhixi_user -phKHQ+N0wBjJAiLukFu5OMEI8 zhixi_prod"
|
|
FAILED=$($MYSQL_CMD -N -e \
|
|
"SELECT migration_name FROM _prisma_migrations WHERE logs LIKE '%failed%' LIMIT 1;" 2>/dev/null || true)
|
|
if [ -n "$FAILED" ]; then
|
|
echo "[deploy] Found failed migration: $FAILED, cleaning up..."
|
|
$MYSQL_CMD -e "DROP TABLE IF EXISTS AiUsageLog;" 2>/dev/null || true
|
|
$MYSQL_CMD -e "DROP TABLE IF EXISTS WaitlistEntry;" 2>/dev/null || true
|
|
$MYSQL_CMD -e "DROP TABLE IF EXISTS ModelRoute;" 2>/dev/null || true
|
|
$MYSQL_CMD -e "DROP TABLE IF EXISTS ProviderConfig;" 2>/dev/null || true
|
|
$MYSQL_CMD -e "DROP TABLE IF EXISTS FallbackEvent;" 2>/dev/null || true
|
|
$MYSQL_CMD -e "DROP TABLE IF EXISTS ViolationRecord;" 2>/dev/null || true
|
|
$MYSQL_CMD -e "DROP TABLE IF EXISTS UserDevice;" 2>/dev/null || true
|
|
$MYSQL_CMD -e "DROP TABLE IF EXISTS AccountDeletionRequest;" 2>/dev/null || true
|
|
$MYSQL_CMD -e "ALTER TABLE UploadedFile DROP COLUMN objectKey;" 2>/dev/null || true
|
|
$MYSQL_CMD -e "ALTER TABLE UploadedFile DROP COLUMN bucket;" 2>/dev/null || true
|
|
$MYSQL_CMD -e "DROP INDEX UploadedFile_objectKey_idx ON UploadedFile;" 2>/dev/null || true
|
|
$MYSQL_CMD -e "DELETE FROM _prisma_migrations WHERE migration_name = '$FAILED';"
|
|
echo "[deploy] Cleaned up failed migration $FAILED"
|
|
else
|
|
echo "[deploy] No failed migrations found"
|
|
fi
|
|
|
|
- name: Sync database schema
|
|
run: |
|
|
cd /tmp/api-server
|
|
npx prisma db push --skip-generate
|
|
|
|
- name: Deploy NestJS API
|
|
run: |
|
|
sudo rsync -av --delete \
|
|
/tmp/api-server/dist/ /opt/zhixi/backend/dist/
|
|
sudo rsync -av --delete \
|
|
/tmp/api-server/node_modules/ /opt/zhixi/backend/node_modules/
|
|
sudo rsync -av \
|
|
/tmp/api-server/prisma/ /opt/zhixi/backend/prisma/
|
|
sudo rsync -av \
|
|
/tmp/api-server/package.json /opt/zhixi/backend/package.json
|
|
|
|
- name: Generate Prisma client
|
|
run: |
|
|
cd /opt/zhixi/backend && npx prisma generate
|
|
|
|
- name: Restart API service
|
|
run: |
|
|
sudo systemctl reset-failed zhixi-api 2>/dev/null || true
|
|
sudo systemctl restart zhixi-api
|
|
sleep 3
|
|
if curl -sf http://localhost:3000/api > /dev/null 2>&1; then
|
|
echo "[deploy] API health OK"
|
|
else
|
|
echo "[deploy] Health check failed — checking logs:"
|
|
sudo journalctl -u zhixi-api --no-pager -n 20
|
|
exit 1
|
|
fi
|
|
|
|
- name: Deploy NestJS Worker
|
|
run: |
|
|
cd /opt/zhixi/backend
|
|
sudo cp deploy/zhixi-nest-worker.service /etc/systemd/system/
|
|
sudo systemctl daemon-reload
|
|
sudo systemctl reset-failed zhixi-nest-worker 2>/dev/null || true
|
|
sudo systemctl restart zhixi-nest-worker
|
|
sleep 5
|
|
echo "[deploy] Worker status: $(sudo systemctl is-active zhixi-nest-worker)"
|
|
echo "[deploy] Worker startup log:"
|
|
sudo journalctl -u zhixi-nest-worker --no-pager -n 10
|
|
|
|
- name: Worker 集成测试 (BullMQ/MySQL/Redis 真实验证)
|
|
run: |
|
|
cd /tmp/api-server
|
|
bash test/run-integration-tests.sh
|
|
env:
|
|
DATABASE_URL: mysql://zhixi_user:hKHQ+N0wBjJAiLukFu5OMEI8@127.0.0.1:3306/zhixi_prod
|
|
REDIS_HOST: 127.0.0.1
|
|
REDIS_PORT: '6379'
|
|
REDIS_PASSWORD: THTC2B5wXvhlMw/ZB6TYwB6MI9r1tO0F
|
|
JWT_SECRET: test-integration-secret
|
|
INTERNAL_API_KEY: test-key
|
|
CREDENTIAL_ENCRYPTION_KEY: '0123456789abcdef0123456789abcdef'
|
|
STORAGE_DRIVER: local
|
|
MYSQL_ROOT_PASSWORD: Zhixi@2026!Root_8C
|
|
timeout-minutes: 10
|
|
|
|
- name: Deploy RAG Worker
|
|
run: |
|
|
set -e
|
|
WORKER_DIR="/opt/zhixi/backend/rag-worker"
|
|
mkdir -p "$WORKER_DIR"
|
|
rsync -av --delete --exclude='.env' --exclude='__pycache__' \
|
|
/tmp/api-server/rag-worker/ "$WORKER_DIR/"
|
|
sudo cp "$WORKER_DIR/zhixi-worker.service" /etc/systemd/system/
|
|
sudo systemctl daemon-reload
|
|
sudo systemctl restart zhixi-worker
|
|
sleep 5
|
|
sudo systemctl is-active zhixi-worker
|
|
echo "[deploy] zhixi-worker active OK"
|