docker-image-arm64.yml 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. name: Publish Docker image (Multi Registries, native amd64+arm64)
  2. on:
  3. push:
  4. tags:
  5. - '*'
  6. workflow_dispatch:
  7. inputs:
  8. tag:
  9. description: 'Tag name to build (e.g., v0.10.8-alpha.3)'
  10. required: true
  11. type: string
  12. jobs:
  13. build_single_arch:
  14. name: Build & push (${{ matrix.arch }}) [native]
  15. strategy:
  16. fail-fast: false
  17. matrix:
  18. include:
  19. - arch: amd64
  20. platform: linux/amd64
  21. runner: ubuntu-latest
  22. - arch: arm64
  23. platform: linux/arm64
  24. runner: ubuntu-24.04-arm
  25. runs-on: ${{ matrix.runner }}
  26. permissions:
  27. packages: write
  28. contents: read
  29. steps:
  30. - name: Check out (shallow)
  31. uses: actions/checkout@v4
  32. with:
  33. fetch-depth: 1
  34. - name: Resolve tag & write VERSION
  35. run: |
  36. git fetch --tags --force --depth=1
  37. if [ -n "${{ github.event.inputs.tag }}" ]; then
  38. TAG="${{ github.event.inputs.tag }}"
  39. else
  40. TAG=${GITHUB_REF#refs/tags/}
  41. fi
  42. echo "TAG=$TAG" >> $GITHUB_ENV
  43. echo "$TAG" > VERSION
  44. echo "Building tag: $TAG for ${{ matrix.arch }}"
  45. # - name: Normalize GHCR repository
  46. # run: echo "GHCR_REPOSITORY=${GITHUB_REPOSITORY,,}" >> $GITHUB_ENV
  47. - name: Set up Docker Buildx
  48. uses: docker/setup-buildx-action@v3
  49. - name: Log in to Docker Hub
  50. uses: docker/login-action@v3
  51. with:
  52. username: ${{ secrets.DOCKERHUB_USERNAME }}
  53. password: ${{ secrets.DOCKERHUB_TOKEN }}
  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: Extract metadata (labels)
  61. id: meta
  62. uses: docker/metadata-action@v5
  63. with:
  64. images: |
  65. calciumion/new-api
  66. # ghcr.io/${{ env.GHCR_REPOSITORY }}
  67. - name: Build & push single-arch (to both registries)
  68. uses: docker/build-push-action@v6
  69. with:
  70. context: .
  71. platforms: ${{ matrix.platform }}
  72. push: true
  73. tags: |
  74. calciumion/new-api:${{ env.TAG }}-${{ matrix.arch }}
  75. calciumion/new-api:latest-${{ matrix.arch }}
  76. # ghcr.io/${{ env.GHCR_REPOSITORY }}:${{ env.TAG }}-${{ matrix.arch }}
  77. # ghcr.io/${{ env.GHCR_REPOSITORY }}:latest-${{ matrix.arch }}
  78. labels: ${{ steps.meta.outputs.labels }}
  79. cache-from: type=gha
  80. cache-to: type=gha,mode=max
  81. provenance: false
  82. sbom: false
  83. create_manifests:
  84. name: Create multi-arch manifests (Docker Hub)
  85. needs: [build_single_arch]
  86. runs-on: ubuntu-latest
  87. if: startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch'
  88. steps:
  89. - name: Extract tag
  90. run: |
  91. if [ -n "${{ github.event.inputs.tag }}" ]; then
  92. echo "TAG=${{ github.event.inputs.tag }}" >> $GITHUB_ENV
  93. else
  94. echo "TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
  95. fi
  96. #
  97. # - name: Normalize GHCR repository
  98. # run: echo "GHCR_REPOSITORY=${GITHUB_REPOSITORY,,}" >> $GITHUB_ENV
  99. - name: Log in to Docker Hub
  100. uses: docker/login-action@v3
  101. with:
  102. username: ${{ secrets.DOCKERHUB_USERNAME }}
  103. password: ${{ secrets.DOCKERHUB_TOKEN }}
  104. - name: Create & push manifest (Docker Hub - version)
  105. run: |
  106. docker buildx imagetools create \
  107. -t calciumion/new-api:${TAG} \
  108. calciumion/new-api:${TAG}-amd64 \
  109. calciumion/new-api:${TAG}-arm64
  110. - name: Create & push manifest (Docker Hub - latest)
  111. run: |
  112. docker buildx imagetools create \
  113. -t calciumion/new-api:latest \
  114. calciumion/new-api:latest-amd64 \
  115. calciumion/new-api:latest-arm64
  116. # ---- GHCR ----
  117. # - name: Log in to GHCR
  118. # uses: docker/login-action@v3
  119. # with:
  120. # registry: ghcr.io
  121. # username: ${{ github.actor }}
  122. # password: ${{ secrets.GITHUB_TOKEN }}
  123. # - name: Create & push manifest (GHCR - version)
  124. # run: |
  125. # docker buildx imagetools create \
  126. # -t ghcr.io/${GHCR_REPOSITORY}:${TAG} \
  127. # ghcr.io/${GHCR_REPOSITORY}:${TAG}-amd64 \
  128. # ghcr.io/${GHCR_REPOSITORY}:${TAG}-arm64
  129. #
  130. # - name: Create & push manifest (GHCR - latest)
  131. # run: |
  132. # docker buildx imagetools create \
  133. # -t ghcr.io/${GHCR_REPOSITORY}:latest \
  134. # ghcr.io/${GHCR_REPOSITORY}:latest-amd64 \
  135. # ghcr.io/${GHCR_REPOSITORY}:latest-arm64