docker-build.yml 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. name: Publish Docker image (Multi-arch)
  2. on:
  3. push:
  4. tags:
  5. - '*'
  6. - '!nightly*'
  7. workflow_dispatch:
  8. inputs:
  9. tag:
  10. description: 'Tag name to build (e.g., v0.10.8-alpha.3)'
  11. required: true
  12. type: string
  13. jobs:
  14. build_single_arch:
  15. name: Build & push (${{ matrix.arch }})
  16. strategy:
  17. fail-fast: false
  18. matrix:
  19. include:
  20. - arch: amd64
  21. platform: linux/amd64
  22. runner: ubuntu-latest
  23. - arch: arm64
  24. platform: linux/arm64
  25. runner: ubuntu-24.04-arm
  26. runs-on: ${{ matrix.runner }}
  27. outputs:
  28. tag: ${{ steps.version.outputs.tag }}
  29. permissions:
  30. packages: write
  31. contents: read
  32. id-token: write
  33. steps:
  34. - name: Check out
  35. uses: actions/checkout@v4
  36. with:
  37. fetch-depth: ${{ github.event_name == 'workflow_dispatch' && 0 || 1 }}
  38. ref: ${{ github.event.inputs.tag || github.ref }}
  39. - name: Resolve tag & write VERSION
  40. id: version
  41. run: |
  42. if [ -n "${{ github.event.inputs.tag }}" ]; then
  43. TAG="${{ github.event.inputs.tag }}"
  44. if ! git rev-parse "refs/tags/$TAG" >/dev/null 2>&1; then
  45. echo "::error::Tag '$TAG' does not exist"
  46. exit 1
  47. fi
  48. else
  49. TAG=${GITHUB_REF#refs/tags/}
  50. fi
  51. echo "TAG=${TAG}" >> $GITHUB_ENV
  52. echo "tag=${TAG}" >> $GITHUB_OUTPUT
  53. echo "${TAG}" > VERSION
  54. echo "Building tag: ${TAG} for ${{ matrix.arch }}"
  55. - name: Set up Docker Buildx
  56. uses: docker/setup-buildx-action@v3
  57. - name: Log in to Docker Hub
  58. uses: docker/login-action@v3
  59. with:
  60. username: ${{ secrets.DOCKERHUB_USERNAME }}
  61. password: ${{ secrets.DOCKERHUB_TOKEN }}
  62. - name: Extract metadata (labels)
  63. id: meta
  64. uses: docker/metadata-action@v5
  65. with:
  66. images: calciumion/new-api
  67. - name: Build & push
  68. id: build
  69. uses: docker/build-push-action@v6
  70. with:
  71. context: .
  72. platforms: ${{ matrix.platform }}
  73. push: true
  74. tags: |
  75. calciumion/new-api:${{ env.TAG }}-${{ matrix.arch }}
  76. calciumion/new-api:latest-${{ matrix.arch }}
  77. labels: ${{ steps.meta.outputs.labels }}
  78. cache-from: type=gha
  79. cache-to: type=gha,mode=max
  80. provenance: mode=max
  81. sbom: true
  82. - name: Install cosign
  83. uses: sigstore/cosign-installer@v3
  84. - name: Sign image with cosign
  85. run: cosign sign --yes calciumion/new-api@${{ steps.build.outputs.digest }}
  86. - name: Image summary
  87. run: |
  88. echo "### Docker Image Digest (${{ matrix.arch }})" >> $GITHUB_STEP_SUMMARY
  89. echo '```' >> $GITHUB_STEP_SUMMARY
  90. echo "calciumion/new-api:${TAG}-${{ matrix.arch }}" >> $GITHUB_STEP_SUMMARY
  91. echo "${{ steps.build.outputs.digest }}" >> $GITHUB_STEP_SUMMARY
  92. echo '```' >> $GITHUB_STEP_SUMMARY
  93. create_manifests:
  94. name: Create multi-arch manifests
  95. needs: [build_single_arch]
  96. runs-on: ubuntu-latest
  97. if: startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch'
  98. steps:
  99. - name: Set version
  100. run: echo "TAG=${{ needs.build_single_arch.outputs.tag }}" >> $GITHUB_ENV
  101. - name: Log in to Docker Hub
  102. uses: docker/login-action@v3
  103. with:
  104. username: ${{ secrets.DOCKERHUB_USERNAME }}
  105. password: ${{ secrets.DOCKERHUB_TOKEN }}
  106. - name: Create & push manifest (version)
  107. run: |
  108. docker buildx imagetools create \
  109. -t calciumion/new-api:${TAG} \
  110. calciumion/new-api:${TAG}-amd64 \
  111. calciumion/new-api:${TAG}-arm64
  112. - name: Create & push manifest (latest)
  113. run: |
  114. docker buildx imagetools create \
  115. -t calciumion/new-api:latest \
  116. calciumion/new-api:latest-amd64 \
  117. calciumion/new-api:latest-arm64
  118. - name: Manifest summary
  119. run: |
  120. echo "### Multi-arch Manifest" >> $GITHUB_STEP_SUMMARY
  121. echo '```' >> $GITHUB_STEP_SUMMARY
  122. docker buildx imagetools inspect calciumion/new-api:${TAG} >> $GITHUB_STEP_SUMMARY
  123. echo '```' >> $GITHUB_STEP_SUMMARY