docker-image-arm64.yml 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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)
  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. #
  81. # - name: Normalize GHCR repository
  82. # run: echo "GHCR_REPOSITORY=${GITHUB_REPOSITORY,,}" >> $GITHUB_ENV
  83. - name: Log in to Docker Hub
  84. uses: docker/login-action@v3
  85. with:
  86. username: ${{ secrets.DOCKERHUB_USERNAME }}
  87. password: ${{ secrets.DOCKERHUB_TOKEN }}
  88. - name: Create & push manifest (Docker Hub - version)
  89. run: |
  90. docker buildx imagetools create \
  91. -t calciumion/new-api:${TAG} \
  92. calciumion/new-api:${TAG}-amd64 \
  93. calciumion/new-api:${TAG}-arm64
  94. - name: Create & push manifest (Docker Hub - latest)
  95. run: |
  96. docker buildx imagetools create \
  97. -t calciumion/new-api:latest \
  98. calciumion/new-api:latest-amd64 \
  99. calciumion/new-api:latest-arm64
  100. # ---- GHCR ----
  101. # - name: Log in to GHCR
  102. # uses: docker/login-action@v3
  103. # with:
  104. # registry: ghcr.io
  105. # username: ${{ github.actor }}
  106. # password: ${{ secrets.GITHUB_TOKEN }}
  107. # - name: Create & push manifest (GHCR - version)
  108. # run: |
  109. # docker buildx imagetools create \
  110. # -t ghcr.io/${GHCR_REPOSITORY}:${TAG} \
  111. # ghcr.io/${GHCR_REPOSITORY}:${TAG}-amd64 \
  112. # ghcr.io/${GHCR_REPOSITORY}:${TAG}-arm64
  113. #
  114. # - name: Create & push manifest (GHCR - latest)
  115. # run: |
  116. # docker buildx imagetools create \
  117. # -t ghcr.io/${GHCR_REPOSITORY}:latest \
  118. # ghcr.io/${GHCR_REPOSITORY}:latest-amd64 \
  119. # ghcr.io/${GHCR_REPOSITORY}:latest-arm64