docker-image-arm64.yml 4.9 KB

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