docker-build.yml 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. # 自动构建并推送 GHCR:push master 触发
  2. # 镜像 tag:latest + 日期时间 - 提交哈希(如 20260815T0054-a1b2c3d)
  3. #
  4. # Auto-build and push to GHCR: triggered on push to master
  5. # Image tags: latest + datetime-commit-hash (e.g. 20260815T0054-a1b2c3d)
  6. name: build-push-ghcr
  7. on:
  8. push:
  9. branches: [master]
  10. env:
  11. IMAGE: ghcr.io/xidong-ai/deepseek-harness-web-docker
  12. jobs:
  13. # 推送前冒烟:构建镜像并跑端到端检查(basic auth / 特权 API fence / 双进程 / trustedHosts 注入),失败则不推送
  14. # 手动 push 的代码不再未经验证直接发布
  15. #
  16. # Pre-push smoke test: build the image and run end-to-end checks (basic auth / privileged-API fence /
  17. # both processes / trustedHosts injection); a failure blocks the push, so manually pushed code
  18. # is no longer published unverified
  19. verify:
  20. runs-on: ubuntu-latest
  21. permissions:
  22. contents: read
  23. steps:
  24. - uses: actions/checkout@v4
  25. - name: 提取 DSH_VERSION
  26. id: version
  27. run: |
  28. echo "version=$(grep -E '^ARG DSH_VERSION=' Dockerfile | head -n1 | cut -d= -f2)" >> "$GITHUB_OUTPUT"
  29. - name: 构建并冒烟测试
  30. run: |
  31. scripts/smoke-test.sh "${{ steps.version.outputs.version }}"
  32. build:
  33. needs: verify
  34. runs-on: ubuntu-latest
  35. permissions:
  36. contents: read
  37. packages: write
  38. steps:
  39. - uses: actions/checkout@v4
  40. - name: Set up QEMU
  41. uses: docker/setup-qemu-action@v3
  42. - name: Set up Docker Buildx
  43. uses: docker/setup-buildx-action@v3
  44. - name: Log in to GHCR
  45. uses: docker/login-action@v3
  46. with:
  47. registry: ghcr.io
  48. username: ${{ github.actor }}
  49. password: ${{ secrets.GITHUB_TOKEN }}
  50. - name: 生成日期时间 - 哈希 tag
  51. id: meta
  52. run: |
  53. echo "tag=$(date +%Y%m%dT%H%M)-${GITHUB_SHA::7}" >> "$GITHUB_OUTPUT"
  54. - name: Build and push
  55. uses: docker/build-push-action@v6
  56. with:
  57. context: .
  58. push: true
  59. platforms: linux/amd64,linux/arm64
  60. # gha 缓存:跨 run 复用构建层(mode=max 保留 apt/corepack 等中间层,
  61. # DSH_VERSION 变化时未变层仍命中);cache scope 为当前分支
  62. #
  63. # gha cache: reuse build layers across runs (mode=max keeps intermediate
  64. # layers such as apt/corepack, so unchanged layers still hit when DSH_VERSION changes);
  65. # cache scope is the current branch
  66. cache-from: type=gha
  67. cache-to: type=gha,mode=max
  68. tags: |
  69. ${{ env.IMAGE }}:latest
  70. ${{ env.IMAGE }}:${{ steps.meta.outputs.tag }}