docker-image-arm64.yml 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. TAG=${GITHUB_REF#refs/tags/}
  32. echo "TAG=$TAG" >> $GITHUB_ENV
  33. echo "$TAG" > VERSION
  34. echo "Building tag: $TAG for ${{ matrix.arch }}"
  35. # - name: Normalize GHCR repository
  36. # run: echo "GHCR_REPOSITORY=${GITHUB_REPOSITORY,,}" >> $GITHUB_ENV
  37. - name: Set up Docker Buildx
  38. uses: docker/setup-buildx-action@v3
  39. - name: Log in to Docker Hub
  40. uses: docker/login-action@v3
  41. with:
  42. username: ${{ secrets.DOCKERHUB_USERNAME }}
  43. password: ${{ secrets.DOCKERHUB_TOKEN }}
  44. # - name: Log in to GHCR
  45. # uses: docker/login-action@v3
  46. # with:
  47. # registry: ghcr.io
  48. # username: ${{ github.actor }}
  49. # password: ${{ secrets.GITHUB_TOKEN }}
  50. - name: Extract metadata (labels)
  51. id: meta
  52. uses: docker/metadata-action@v5
  53. with:
  54. images: |
  55. calciumion/new-api
  56. # ghcr.io/${{ env.GHCR_REPOSITORY }}
  57. - name: Build & push single-arch (to both registries)
  58. uses: docker/build-push-action@v6
  59. with:
  60. context: .
  61. platforms: ${{ matrix.platform }}
  62. push: true
  63. tags: |
  64. calciumion/new-api:${{ env.TAG }}-${{ matrix.arch }}
  65. calciumion/new-api:latest-${{ matrix.arch }}
  66. # ghcr.io/${{ env.GHCR_REPOSITORY }}:${{ env.TAG }}-${{ matrix.arch }}
  67. # ghcr.io/${{ env.GHCR_REPOSITORY }}:latest-${{ matrix.arch }}
  68. labels: ${{ steps.meta.outputs.labels }}
  69. cache-from: type=gha
  70. cache-to: type=gha,mode=max
  71. provenance: false
  72. sbom: false
  73. create_manifests:
  74. name: Create multi-arch manifests (Docker Hub)
  75. needs: [build_single_arch]
  76. runs-on: ubuntu-latest
  77. if: startsWith(github.ref, 'refs/tags/')
  78. steps:
  79. - name: Extract tag
  80. run: echo "TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
  81. #
  82. # - name: Normalize GHCR repository
  83. # run: echo "GHCR_REPOSITORY=${GITHUB_REPOSITORY,,}" >> $GITHUB_ENV
  84. - name: Log in to Docker Hub
  85. uses: docker/login-action@v3
  86. with:
  87. username: ${{ secrets.DOCKERHUB_USERNAME }}
  88. password: ${{ secrets.DOCKERHUB_TOKEN }}
  89. - name: Create & push manifest (Docker Hub - version)
  90. run: |
  91. docker buildx imagetools create \
  92. -t calciumion/new-api:${TAG} \
  93. calciumion/new-api:${TAG}-amd64 \
  94. calciumion/new-api:${TAG}-arm64
  95. - name: Create & push manifest (Docker Hub - latest)
  96. run: |
  97. docker buildx imagetools create \
  98. -t calciumion/new-api:latest \
  99. calciumion/new-api:latest-amd64 \
  100. calciumion/new-api:latest-arm64
  101. # ---- GHCR ----
  102. # - name: Log in to GHCR
  103. # uses: docker/login-action@v3
  104. # with:
  105. # registry: ghcr.io
  106. # username: ${{ github.actor }}
  107. # password: ${{ secrets.GITHUB_TOKEN }}
  108. # - name: Create & push manifest (GHCR - version)
  109. # run: |
  110. # docker buildx imagetools create \
  111. # -t ghcr.io/${GHCR_REPOSITORY}:${TAG} \
  112. # ghcr.io/${GHCR_REPOSITORY}:${TAG}-amd64 \
  113. # ghcr.io/${GHCR_REPOSITORY}:${TAG}-arm64
  114. #
  115. # - name: Create & push manifest (GHCR - latest)
  116. # run: |
  117. # docker buildx imagetools create \
  118. # -t ghcr.io/${GHCR_REPOSITORY}:latest \
  119. # ghcr.io/${GHCR_REPOSITORY}:latest-amd64 \
  120. # ghcr.io/${GHCR_REPOSITORY}:latest-arm64