docker-image-arm64.yml 4.0 KB

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