Skip to content

ci(image): build images on an in-cluster BuildKit in the staging cluster - #237

Merged
shark0F0497 merged 8 commits into
main-v2from
ci/github-hosted-runners
Nov 18, 2026
Merged

shark0F0497 merged 8 commits into
main-v2from
ci/github-hosted-runners

Conversation

@shark0F0497

Copy link
Copy Markdown
Collaborator

背景

GitHub 托管 runner 直推火山 CR 实测 19 KB/s(2 MiB 分片上传 110s):
冷构建 push 耗时 2h30m、增量构建 25.5 分钟,每次 main-v2 合并都会跑一次,不可用。

仓库里现成可用的凭据里,只有 staging 集群 kubeconfig(STAGING_KUBECONFIG_B64,staging environment,无审批)能在
GitHub runner 上访问,且集群与 CR 同区域。因此把镜像构建/推送搬到集群内,不新增任何运维配置。

改动

keystone-image.yml:

  • job 声明 environment: staging,用已有的 STAGING_KUBECONFIG_B64 配置 kubeconfig;
  • 在集群内 keystone-image-build namespace 里创建:
    • cr-pull imagePullSecret(用现有 CR 账号密码);
    • 持久化 PVC buildkit-cache(ebs-ssd,40Gi),作为 BuildKit 构建缓存;
    • 单次运行的 privileged BuildKit Pod(镜像来自 CR 的 upstream/buildkit:buildx-stable-1);
  • GitHub runner 用 kubectl port-forward 连到该 BuildKit(--driver remote),构建上下文(约 5-9MB)经 port-forward 上传;
  • 构建产物由集群内 BuildKit 直接 push 到 CR(同区域,快);
  • 清理:优雅关闭并删除 Pod(保留 PVC 缓存),if: always();
  • 加 concurrency: keystone-image 串行化(PVC 是 RWO);
  • 新增 allowNonMainV2Branch workflow_dispatch 开关,便于从开发分支手动验证。

实测(本分支 dispatch 两次,都成功)

阶段 冷构建 次构建(部分缓存)
总时长 18m41s 12m46s
上下文上传 ~7m ~7m
构建 ~8m ~4.5m
push 到 CR 6.9s 6.8s

对比改造前:push 2h30m(冷)/ 25.5 分钟(增量)。

注意

  • 构建期间会临时占用 staging 集群资源(1 个 privileged Pod,requests 2C/4Gi);
  • keystone-image-build namespace 与 40Gi PVC 会保留下来做缓存;
  • job 依赖 staging environment secret,若以后给 staging 环境加审批规则,镜像构建会被卡住;
  • 剩余瓶颈是 ~7 分钟的跨境内核上下文上传;后续可考虑改用 BuildKit git context(让集群自己从 GitHub 克隆)或 GHCR 中转来进一步缩短。

@shark0F0497
shark0F0497 merged commit 822657b into main-v2 Nov 18, 2026
4 checks passed
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