Skip to content

feat: automate CD via GitHub self-hosted runner on ECS - #3

Open
qiaolei1973 wants to merge 1 commit into
mainfrom
worktree-feat+auto-cd-self-hosted-runner
Open

feat: automate CD via GitHub self-hosted runner on ECS#3
qiaolei1973 wants to merge 1 commit into
mainfrom
worktree-feat+auto-cd-self-hosted-runner

Conversation

@qiaolei1973

@qiaolei1973 qiaolei1973 commented Jun 4, 2026

Copy link
Copy Markdown
Collaborator

变更说明

实现基于 GitHub Self-hosted Runner 的自动化 CD,push main 后无需任何手动 SSH 操作即可自动部署到 ECS k3s 集群。关联 #2

  • 新增 deploy job:依赖 build job 成功后运行,runs-on: [self-hosted, ecs],先从 GitHub Secrets 同步 UPSTREAM_API_KEY(若已配置),再调用 deploy-remote.sh 完成部署
  • 新增 scripts/setup-runner.sh:一次性初始化脚本,下载 Actions runner 二进制、注册到 GitHub、以 systemd 服务启动(Pull 模式,无需开放入站端口,天然兼容 NAT 环境)。通过 npm run ecs:runner 调用
  • 修复 deploy-remote.sh:将三处硬编码的 :latest 替换为 $IMAGE_TAG(默认 latest),使 workflow_dispatch 自定义 tag 能端到端生效
  • 更新 package.json:新增 ecs:runner(安装 runner)和 ecs:rollback(一键回滚)便捷脚本

ECS 一次性初始化

# 1. 在 GitHub 获取注册 token:
#    Repo → Settings → Actions → Runners → New self-hosted runner → 复制 token

# 2. SSH 到 ECS,执行:
RUNNER_TOKEN=<token> \
RUNNER_REPO=https://github.com/ob-labs/talos-deploy \
npm run ecs:runner

# 3. 验证 runner 状态为 Idle:
#    GitHub → Settings → Actions → Runners

测试计划

  • 在 ECS 安装并注册 runner,GitHub 显示 Idle
  • push 一个无关紧要的改动到 main,观察 Actions 中 builddeploy job 均成功
  • k3s kubectl get pods -n system 确认 Pod 正常运行且镜像为最新
  • 通过 workflow_dispatch 指定 image_tag=v1.0.0,确认 Pod 使用对应 tag
  • 配置 UPSTREAM_API_KEY GitHub Secret 后重新部署,确认 k8s Secret 同步更新
  • 执行 npm run ecs:rollback,确认 Pod 回滚到上一个 revision

🤖 Generated with Claude Code

Adds a self-hosted runner-based deploy job so that pushing to main
triggers build + automated deployment to the ECS k3s cluster without
any manual SSH steps.

- .github/workflows/deploy.yml: add `deploy` job (runs-on: self-hosted,
  ecs) that checks out the repo, optionally syncs UPSTREAM_API_KEY from
  GitHub Secrets, and runs deploy-remote.sh; gated by `environment:
  production`
- scripts/setup-runner.sh: one-shot script to download, register, and
  install the GitHub Actions runner as a systemd service (NAT-friendly
  pull model, `npm run ecs:runner`)
- scripts/deploy-remote.sh: replace hardcoded `latest` image tag with
  IMAGE_TAG env var (default: latest) so workflow_dispatch with a custom
  tag works end-to-end
- package.json: add `ecs:runner` and `ecs:rollback` convenience scripts

Closes #2

Co-Authored-By: Claude Sonnet 4 <noreply@anthropic.com>
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.

1 participant