docker-image-arm64.yml 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. name: Publish Docker image (Multi Registries, native amd64+arm64)
  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 }}) [native]
  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. permissions:
  28. packages: write
  29. contents: read
  30. id-token: write
  31. steps:
  32. - name: Check out
  33. uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
  34. with:
  35. fetch-depth: ${{ github.event_name == 'workflow_dispatch' && 0 || 1 }}
  36. ref: ${{ github.event.inputs.tag || github.ref }}
  37. - name: Resolve tag & write VERSION
  38. run: |
  39. if [ -n "${{ github.event.inputs.tag }}" ]; then
  40. TAG="${{ github.event.inputs.tag }}"
  41. # Verify tag exists
  42. if ! git rev-parse "refs/tags/$TAG" >/dev/null 2>&1; then
  43. echo "Error: Tag '$TAG' does not exist in the repository"
  44. exit 1
  45. fi
  46. else
  47. TAG=${GITHUB_REF#refs/tags/}
  48. fi
  49. echo "TAG=$TAG" >> $GITHUB_ENV
  50. echo "$TAG" > VERSION
  51. echo "Building tag: $TAG for ${{ matrix.arch }}"
  52. # - name: Normalize GHCR repository
  53. # run: echo "GHCR_REPOSITORY=${GITHUB_REPOSITORY,,}" >> $GITHUB_ENV
  54. - name: Set up Docker Buildx
  55. uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3
  56. - name: Log in to Docker Hub
  57. uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3
  58. with:
  59. username: ${{ secrets.DOCKERHUB_USERNAME }}
  60. password: ${{ secrets.DOCKERHUB_TOKEN }}
  61. # - name: Log in to GHCR
  62. # uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3
  63. # with:
  64. # registry: ghcr.io
  65. # username: ${{ github.actor }}
  66. # password: ${{ secrets.GITHUB_TOKEN }}
  67. - name: Extract metadata (labels)
  68. id: meta
  69. uses: docker/metadata-action@c299e40c65443455700f0fdfc63efafe5b349051 # v5
  70. with:
  71. images: |
  72. calciumion/new-api
  73. # ghcr.io/${{ env.GHCR_REPOSITORY }}
  74. - name: Build & push single-arch (to both registries)
  75. id: build
  76. uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6
  77. with:
  78. context: .
  79. platforms: ${{ matrix.platform }}
  80. push: true
  81. tags: |
  82. calciumion/new-api:${{ env.TAG }}-${{ matrix.arch }}
  83. calciumion/new-api:latest-${{ matrix.arch }}
  84. # ghcr.io/${{ env.GHCR_REPOSITORY }}:${{ env.TAG }}-${{ matrix.arch }}
  85. # ghcr.io/${{ env.GHCR_REPOSITORY }}:latest-${{ matrix.arch }}
  86. labels: ${{ steps.meta.outputs.labels }}
  87. cache-from: type=gha
  88. cache-to: type=gha,mode=max
  89. provenance: mode=max
  90. sbom: true
  91. - name: Install cosign
  92. uses: sigstore/cosign-installer@398d4b0eeef1380460a10c8013a76f728fb906ac # v3
  93. - name: Sign image with cosign
  94. run: cosign sign --yes calciumion/new-api@${{ steps.build.outputs.digest }}
  95. - name: Output digest
  96. run: |
  97. echo "### Docker Image Digest (${{ matrix.arch }})" >> $GITHUB_STEP_SUMMARY
  98. echo '```' >> $GITHUB_STEP_SUMMARY
  99. echo "calciumion/new-api:${{ env.TAG }}-${{ matrix.arch }}" >> $GITHUB_STEP_SUMMARY
  100. echo "${{ steps.build.outputs.digest }}" >> $GITHUB_STEP_SUMMARY
  101. echo '```' >> $GITHUB_STEP_SUMMARY
  102. create_manifests:
  103. name: Create multi-arch manifests (Docker Hub)
  104. needs: [build_single_arch]
  105. runs-on: ubuntu-latest
  106. if: startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch'
  107. steps:
  108. - name: Extract tag
  109. run: |
  110. if [ -n "${{ github.event.inputs.tag }}" ]; then
  111. echo "TAG=${{ github.event.inputs.tag }}" >> $GITHUB_ENV
  112. else
  113. echo "TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
  114. fi
  115. #
  116. # - name: Normalize GHCR repository
  117. # run: echo "GHCR_REPOSITORY=${GITHUB_REPOSITORY,,}" >> $GITHUB_ENV
  118. - name: Log in to Docker Hub
  119. uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3
  120. with:
  121. username: ${{ secrets.DOCKERHUB_USERNAME }}
  122. password: ${{ secrets.DOCKERHUB_TOKEN }}
  123. - name: Create & push manifest (Docker Hub - version)
  124. run: |
  125. docker buildx imagetools create \
  126. -t calciumion/new-api:${TAG} \
  127. calciumion/new-api:${TAG}-amd64 \
  128. calciumion/new-api:${TAG}-arm64
  129. - name: Create & push manifest (Docker Hub - latest)
  130. run: |
  131. docker buildx imagetools create \
  132. -t calciumion/new-api:latest \
  133. calciumion/new-api:latest-amd64 \
  134. calciumion/new-api:latest-arm64
  135. - name: Output manifest digest
  136. run: |
  137. echo "### Multi-arch Manifest" >> $GITHUB_STEP_SUMMARY
  138. echo '```' >> $GITHUB_STEP_SUMMARY
  139. docker buildx imagetools inspect calciumion/new-api:${TAG} >> $GITHUB_STEP_SUMMARY
  140. echo '```' >> $GITHUB_STEP_SUMMARY
  141. # ---- GHCR ----
  142. # - name: Log in to GHCR
  143. # uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3
  144. # with:
  145. # registry: ghcr.io
  146. # username: ${{ github.actor }}
  147. # password: ${{ secrets.GITHUB_TOKEN }}
  148. # - name: Create & push manifest (GHCR - version)
  149. # run: |
  150. # docker buildx imagetools create \
  151. # -t ghcr.io/${GHCR_REPOSITORY}:${TAG} \
  152. # ghcr.io/${GHCR_REPOSITORY}:${TAG}-amd64 \
  153. # ghcr.io/${GHCR_REPOSITORY}:${TAG}-arm64
  154. #
  155. # - name: Create & push manifest (GHCR - latest)
  156. # run: |
  157. # docker buildx imagetools create \
  158. # -t ghcr.io/${GHCR_REPOSITORY}:latest \
  159. # ghcr.io/${GHCR_REPOSITORY}:latest-amd64 \
  160. # ghcr.io/${GHCR_REPOSITORY}:latest-arm64