docker-image-arm64.yml 4.9 KB

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