Files
sundynix-agentix/.gitea/workflows/deploy.yml
T
Blizzard 2599936777 ci(gitea): push-to-main 自动部署到 132 + 防 GitHub CI 在 Gitea 误跑
- .gitea/workflows/deploy.yml:runner(128) 检出 → rsync 仓库到 132 → 在 132 本地
  docker compose up -d --build → 循环 curl :3000/healthz。在 132 构建、132 运行(不拿
  4 个大镜像去 128 构建);rsync 排除 .env/node_modules,不覆盖 132 上的密钥。
  Gitea secrets:DEPLOY_HOST/DEPLOY_USER/DEPLOY_PASSWORD。
- .github/workflows/ci.yml:6 个 job 加 if !contains(github.server_url,'sundynix.cn'),
  Gitea 上只跑 deploy、不误跑 GitHub CI(此前为此把 Gitea 工作流整个关了)。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-18 14:45:24 +08:00

71 lines
2.6 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.
name: deploy-132
# 只认 main(含 PR 合并入 main)。runner 在 128,应用部署到 132
# runner 检出 → rsync 仓库到 132 → 在 132 本地 docker compose up -d --build → 健康检查。
# 在 132 构建、132 运行:不把 4 个大镜像塞去 128 构建(128 是基础设施机)。
on:
push:
branches: [main]
workflow_dispatch:
env:
REMOTE_DIR: /opt/sundynix-agentix
jobs:
deploy:
runs-on: ubuntu-latest # 须匹配 128 上已注册 runner 的标签;不符请改成你的标签
steps:
- name: 检出代码
uses: actions/checkout@v4
- name: 安装 ssh / rsync 工具
run: |
if command -v apt-get >/dev/null; then
apt-get update && apt-get install -y sshpass openssh-client rsync
elif command -v apk >/dev/null; then
apk add --no-cache sshpass openssh-client rsync
fi
- name: rsync 仓库到 132
env:
SSHPASS: ${{ secrets.DEPLOY_PASSWORD }}
run: |
H="${{ secrets.DEPLOY_HOST }}"
U="${{ secrets.DEPLOY_USER }}"
sshpass -e ssh -o StrictHostKeyChecking=no "$U@$H" "mkdir -p $REMOTE_DIR"
# 同步源码;排除本地产物与密钥(132 上的 .env 由你手工放置,绝不被覆盖/删除)。
sshpass -e rsync -az --delete \
--exclude '.git' \
--exclude 'node_modules' \
--exclude '**/node_modules' \
--exclude '**/dist' \
--exclude '.env' \
--exclude '**/.env' \
-e "ssh -o StrictHostKeyChecking=no" \
./ "$U@$H:$REMOTE_DIR/"
- name: 132 本地构建并起服务
env:
SSHPASS: ${{ secrets.DEPLOY_PASSWORD }}
run: |
H="${{ secrets.DEPLOY_HOST }}"
U="${{ secrets.DEPLOY_USER }}"
sshpass -e ssh -o StrictHostKeyChecking=no "$U@$H" "\
cd $REMOTE_DIR/deploy/132-app && \
docker compose up -d --build && \
docker image prune -f"
- name: 健康检查(gateway :3000/healthz
env:
SSHPASS: ${{ secrets.DEPLOY_PASSWORD }}
run: |
H="${{ secrets.DEPLOY_HOST }}"
U="${{ secrets.DEPLOY_USER }}"
sshpass -e ssh -o StrictHostKeyChecking=no "$U@$H" "\
for i in \$(seq 1 20); do \
curl -sf http://127.0.0.1:3000/healthz && echo ' ✅ 健康' && exit 0; \
sleep 3; \
done; \
echo '❌ 健康检查失败'; \
cd $REMOTE_DIR/deploy/132-app && docker compose logs --tail 50 gateway; exit 1"