docker-build.yml 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. # 自动构建并推送 GHCR:push master 或手动/workflow_dispatch 触发
  2. # 镜像 tag:latest + 日期时间 - 提交哈希(如 20260815T0054-a1b2c3d)
  3. # workflow_dispatch 提供两种钩入方式:
  4. # - 手动:Actions 页面点「Run workflow」或 gh workflow run docker-build.yml
  5. # - 被钩:upstream-check 自动升级推送后显式触发——bot 用 GITHUB_TOKEN 推送的提交不会触发
  6. # push 事件(GitHub 递归保护),而 workflow_dispatch 是 GITHUB_TOKEN 的例外,总是创建 run
  7. #
  8. # Auto-build and push to GHCR: triggered on push to master or manual/API dispatch
  9. # Image tags: latest + datetime-commit-hash (e.g. 20260815T0054-a1b2c3d)
  10. # workflow_dispatch offers two hook-in paths:
  11. # - Manual: click "Run workflow" in the Actions tab or gh workflow run docker-build.yml
  12. # - Hooked: upstream-check dispatches explicitly after an auto-upgrade push—commits pushed by
  13. # the bot's GITHUB_TOKEN do not fire the push event (GitHub recursion protection),
  14. # while workflow_dispatch is the GITHUB_TOKEN exception and always creates a run
  15. name: build-push-ghcr
  16. on:
  17. push:
  18. branches: [master]
  19. workflow_dispatch:
  20. env:
  21. IMAGE: ghcr.io/xidong-ai/deepseek-harness-web-docker
  22. jobs:
  23. # 推送前冒烟:构建镜像并跑端到端检查(basic auth / 特权 API fence / 双进程 / trustedHosts 注入),失败则不推送
  24. # 手动 push 的代码不再未经验证直接发布
  25. #
  26. # Pre-push smoke test: build the image and run end-to-end checks (basic auth / privileged-API fence /
  27. # both processes / trustedHosts injection); a failure blocks the push, so manually pushed code
  28. # is no longer published unverified
  29. verify:
  30. runs-on: ubuntu-latest
  31. permissions:
  32. contents: read
  33. steps:
  34. - uses: actions/checkout@v4
  35. - name: 提取 DSH_VERSION
  36. id: version
  37. run: |
  38. echo "version=$(grep -E '^ARG DSH_VERSION=' Dockerfile | head -n1 | cut -d= -f2)" >> "$GITHUB_OUTPUT"
  39. - name: 构建并冒烟测试
  40. run: |
  41. scripts/smoke-test.sh "${{ steps.version.outputs.version }}"
  42. build:
  43. needs: verify
  44. runs-on: ubuntu-latest
  45. permissions:
  46. contents: read
  47. packages: write
  48. steps:
  49. - uses: actions/checkout@v4
  50. - name: Set up QEMU
  51. uses: docker/setup-qemu-action@v3
  52. - name: Set up Docker Buildx
  53. uses: docker/setup-buildx-action@v3
  54. - name: Log in to GHCR
  55. uses: docker/login-action@v3
  56. with:
  57. registry: ghcr.io
  58. username: ${{ github.actor }}
  59. password: ${{ secrets.GITHUB_TOKEN }}
  60. - name: 生成日期时间 - 哈希 tag
  61. id: meta
  62. run: |
  63. echo "tag=$(date +%Y%m%dT%H%M)-${GITHUB_SHA::7}" >> "$GITHUB_OUTPUT"
  64. - name: Build and push
  65. uses: docker/build-push-action@v6
  66. with:
  67. context: .
  68. push: true
  69. platforms: linux/amd64,linux/arm64
  70. # gha 缓存:跨 run 复用构建层(mode=max 保留 apt/corepack 等中间层,
  71. # DSH_VERSION 变化时未变层仍命中);cache scope 为当前分支
  72. #
  73. # gha cache: reuse build layers across runs (mode=max keeps intermediate
  74. # layers such as apt/corepack, so unchanged layers still hit when DSH_VERSION changes);
  75. # cache scope is the current branch
  76. cache-from: type=gha
  77. cache-to: type=gha,mode=max
  78. tags: |
  79. ${{ env.IMAGE }}:latest
  80. ${{ env.IMAGE }}:${{ steps.meta.outputs.tag }}