Files
perler-lab/.github/workflows/deploy.yml
T
Workflow config file is invalid. Please check your config file: job deploy: Unrecognized named-value: 'secrets'
Sisyphus (主代理) 02762400fb chore: 项目基线提交 - 拼豆图纸生成器 V1.0 核心代码
- 前端: React+Vite 首页/AI专区, 算法库(MARD色板/量化/背景去除), API对接
- 后端: Express+SQLite, 兑换码/订单/支付/chibi生成, 风控+云端同步
- CI/CD: GitHub Actions + Docker + nginx 配置
- 文档: PRD/DESIGN/LAUNCH/ROADMAP/E2E/竞品对照等 15 份
- 工程: 任务看板(taskboard) + 健康巡检(agent-health) + Git流程(gitflow)
2026-08-13 21:40:27 +08:00

113 lines
3.8 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# =============================================================================
# PERLER LAB — GitHub Actions CI/CD 流水线
# 触发条件:推送到 main 分支 或 手动触发
# 流程:
# 1. test — 安装依赖 + 运行测试(前后端并行)
# 2. build — 构建 Docker 镜像(验证 Dockerfile 正确)
# 3. deploy — SSH 到生产服务器,git pull + docker compose up -d
# =============================================================================
name: Deploy
on:
push:
branches: [main]
workflow_dispatch:
env:
# 镜像标签——使用 commit SHA 保证唯一性,部署时通过 docker compose up -d --build 重建
# 若需推送镜像到 registry,在此取消注释并配置后续步骤
# REGISTRY: ghcr.io
# IMAGE_TAG: ${{ github.sha }}
jobs:
# ── 测试 ──
test:
runs-on: ubuntu-latest
strategy:
matrix:
project:
- name: perler-lab
# perler-lab 无 package-lock.json,使用 npm install
install-cmd: npm install
- name: perler-lab-server
# perler-lab-server 有 package-lock.json,使用 npm ci 保证可复现
install-cmd: npm ci
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
cache-dependency-path: ${{ matrix.project.name }}/package-lock.json
- name: Install & Test (${{ matrix.project.name }})
working-directory: ${{ matrix.project.name }}
run: |
${{ matrix.project.install-cmd }} --no-audit --no-fund
npm test
# 额外:前端执行类型检查
- name: Typecheck (${{ matrix.project.name }})
if: matrix.project.name == 'perler-lab'
working-directory: ${{ matrix.project.name }}
run: npm run typecheck
# ── 构建 Docker 镜像(验证 Dockerfile 正确性) ──
build:
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build frontend image
run: docker build -t perler-lab-frontend:ci perler-lab
- name: Build backend image
run: docker build -t perler-lab-server:ci perler-lab-server
# ── 部署到生产服务器 ──
deploy:
needs: build
runs-on: ubuntu-latest
# 需要 GitHub Secrets 配置以下密钥,否则跳过(上一步 build 仍可通过)
if: ${{ secrets.DEPLOY_HOST != '' }}
steps:
- name: Deploy via SSH
uses: appleboy/ssh-action@v1.1.0
with:
host: ${{ secrets.DEPLOY_HOST }}
username: ${{ secrets.DEPLOY_USER }}
key: ${{ secrets.DEPLOY_SSH_KEY }}
# 可选:用端口转发跳过跳板机
# port: ${{ secrets.DEPLOY_PORT || '22' }}
script_stop: true
script: |
set -e
echo "===== 进入部署目录 ====="
cd ${{ secrets.DEPLOY_PATH || '/opt/perler-lab' }}
echo "===== 拉取最新代码 ====="
git pull origin main
echo "===== 构建并启动服务 ====="
docker compose -f perler-lab-server/docker-compose.yml up -d --build
echo "===== 健康检查:等待后端就绪 ====="
for i in $(seq 1 12); do
if curl -sf http://localhost:8080/healthz > /dev/null 2>&1; then
echo "✅ 前端健康检查通过"
break
fi
if curl -sf http://localhost:8788/health > /dev/null 2>&1; then
echo "✅ 后端健康检查通过"
break
fi
echo "等待服务就绪($i/12)..."
sleep 5
done
echo "===== 清理旧镜像 ====="
docker image prune -f
echo "===== 部署完成 ====="