Skip to content

ci: 接入 GitHub Actions(CI + 自动部署) - #1

Merged
webxiongda merged 2 commits into
mainfrom
cicd-setup
Oct 3, 2026
Merged

webxiongda merged 2 commits into
mainfrom
cicd-setup

Conversation

@webxiongda

Copy link
Copy Markdown
Owner

内容

  • .github/workflows/ci.yml:CI(前端构建 + 后端测试/产物校验)
  • .github/workflows/deploy.yml:push main 后自动部署到 ECS
  • deploy/deploy-*.sh:幂等部署脚本,含前置校验、备份回滚点、部署后契约验证
  • deploy/ca_result.py:解析 Cloud Assistant 返回(避免内联多行 Python 顶断 YAML 缩进)

部署通道

不走 SSH,走阿里云 Cloud Assistant(aliyun ecs RunCommand)。

原因:GitHub Actions runner 与开发机同属境外出口,直连 47.93.15.207:22 会被阿里云上游静默丢包(已实测 nc 超时),安全组规则在该层之下,加了也不生效。Cloud Assistant 走 HTTPS API,已用最小权限 RAM 子账号实测可正常下发执行。

凭据

  • RAM 子账号 ecs-deploy-ci + 自定义策略 ecs-deploy-minimal,仅授予 ecs:RunCommand / ecs:DescribeInvocationResults / ecs:DescribeInstances
  • 已实测越权:子账号无法修改安全组规则
  • 密钥存于仓库 Secrets(ALIYUN_AK / ALIYUN_SK),明文不入库

合并后行为

deploy workflow 监听 main,合并即自动部署:java(systemd)、python(PM2)、node(静态 + nginx)。每次约 30 秒重启,脚本幂等且带备份回滚点。

本 PR 合并前不会触碰线上。

- ci.yml:前端 tsc/vite 构建 + 后端 mvn test(测试用 H2,无需 MySQL)+ 打包校验
- deploy.yml:push main 自动部署到 ECS,走阿里云 Cloud Assistant 而非 SSH
  (Actions runner 属境外出口,直连 22 端口会被上游丢包,Cloud Assistant 走 HTTPS API)
- deploy/deploy-java.sh:幂等部署脚本,含前置校验、备份回滚点、
  AutoLoginService 打包校验(缺类则不重启服务)、免登录契约验证

部署后自动外网复验首页与免登录接口,结果写入 job summary。
workflow 里内联的多行 python3 -c 必须顶格写,会顶断 run: | 块标量的缩进,
导致 GitHub 无法解析 YAML。改为把解析逻辑抽到 deploy/ca_result.py。

已用真实 RunCommand 返回验证 status / output 两种模式均正确。
@webxiongda
webxiongda merged commit 4fa8ad6 into main Oct 3, 2026
1 check passed
@webxiongda
webxiongda deleted the cicd-setup branch October 3, 2026 14:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants