64 lines
1.7 KiB
YAML
64 lines
1.7 KiB
YAML
name: Deploy
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
pull_request:
|
|
branches: [main]
|
|
|
|
jobs:
|
|
# ---- PR 时:验证 Docker 镜像可构建 ----
|
|
verify:
|
|
if: github.event_name == 'pull_request'
|
|
runs-on: aliyun
|
|
steps:
|
|
- name: Setup Node.js
|
|
run: |
|
|
sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
|
|
apk add --no-cache nodejs
|
|
|
|
- name: Checkout
|
|
uses: "http://8.161.227.145:3000/huanghaosheng/checkout@releases/v4"
|
|
|
|
- name: Verify Frontend Build
|
|
run: docker build -t camtalk-frontend-test ./frontend
|
|
|
|
- name: Verify Backend Build
|
|
run: docker build -t camtalk-backend-test ./backend
|
|
|
|
- name: Cleanup
|
|
run: |
|
|
docker rmi camtalk-frontend-test camtalk-backend-test || true
|
|
|
|
# ---- push main 时:构建并部署 ----
|
|
deploy:
|
|
if: github.event_name == 'push'
|
|
runs-on: aliyun
|
|
steps:
|
|
- name: Setup Node.js
|
|
run: |
|
|
sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
|
|
apk add --no-cache nodejs
|
|
|
|
- name: Checkout
|
|
uses: "http://8.161.227.145:3000/huanghaosheng/checkout@releases/v4"
|
|
|
|
- name: Build and Deploy
|
|
run: |
|
|
chmod +x deploy.sh
|
|
./deploy.sh build
|
|
./deploy.sh restart
|
|
|
|
- name: Health Check
|
|
run: |
|
|
for i in $(seq 1 10); do
|
|
if curl -sf http://localhost/api/health > /dev/null 2>&1; then
|
|
echo "服务启动成功"
|
|
exit 0
|
|
fi
|
|
echo "等待服务启动... ($i/10)"
|
|
sleep 3
|
|
done
|
|
echo "服务启动超时"
|
|
exit 1
|