docker-image-alpha.yml 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. name: Publish Docker image (alpha)
  2. on:
  3. push:
  4. branches:
  5. - alpha
  6. workflow_dispatch:
  7. inputs:
  8. name:
  9. description: "reason"
  10. required: false
  11. jobs:
  12. build_single_arch:
  13. name: Build & push (${{ matrix.arch }}) [native]
  14. strategy:
  15. fail-fast: false
  16. matrix:
  17. include:
  18. - arch: amd64
  19. platform: linux/amd64
  20. runner: ubuntu-latest
  21. - arch: arm64
  22. platform: linux/arm64
  23. runner: ubuntu-24.04-arm
  24. runs-on: ${{ matrix.runner }}
  25. permissions:
  26. packages: write
  27. contents: read
  28. id-token: write
  29. steps:
  30. - name: Check out (shallow)
  31. uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
  32. with:
  33. fetch-depth: 1
  34. - name: Determine alpha version
  35. id: version
  36. run: |
  37. VERSION="alpha-$(date +'%Y%m%d')-$(git rev-parse --short HEAD)"
  38. echo "$VERSION" > VERSION
  39. echo "value=$VERSION" >> $GITHUB_OUTPUT
  40. echo "VERSION=$VERSION" >> $GITHUB_ENV
  41. echo "Publishing version: $VERSION for ${{ matrix.arch }}"
  42. - name: Normalize GHCR repository
  43. run: echo "GHCR_REPOSITORY=${GITHUB_REPOSITORY,,}" >> $GITHUB_ENV
  44. - name: Set up Docker Buildx
  45. uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3
  46. - name: Log in to Docker Hub
  47. uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3
  48. with:
  49. username: ${{ secrets.DOCKERHUB_USERNAME }}
  50. password: ${{ secrets.DOCKERHUB_TOKEN }}
  51. - name: Log in to GHCR
  52. uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3
  53. with:
  54. registry: ghcr.io
  55. username: ${{ github.actor }}
  56. password: ${{ secrets.GITHUB_TOKEN }}
  57. - name: Extract metadata (labels)
  58. id: meta
  59. uses: docker/metadata-action@c299e40c65443455700f0fdfc63efafe5b349051 # v5
  60. with:
  61. images: |
  62. calciumion/new-api
  63. ghcr.io/${{ env.GHCR_REPOSITORY }}
  64. - name: Build & push single-arch (to both registries)
  65. id: build
  66. uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6
  67. with:
  68. context: .
  69. platforms: ${{ matrix.platform }}
  70. push: true
  71. tags: |
  72. calciumion/new-api:alpha-${{ matrix.arch }}
  73. calciumion/new-api:${{ steps.version.outputs.value }}-${{ matrix.arch }}
  74. ghcr.io/${{ env.GHCR_REPOSITORY }}:alpha-${{ matrix.arch }}
  75. ghcr.io/${{ env.GHCR_REPOSITORY }}:${{ steps.version.outputs.value }}-${{ matrix.arch }}
  76. labels: ${{ steps.meta.outputs.labels }}
  77. cache-from: type=gha
  78. cache-to: type=gha,mode=max
  79. provenance: mode=max
  80. sbom: true
  81. - name: Install cosign
  82. uses: sigstore/cosign-installer@398d4b0eeef1380460a10c8013a76f728fb906ac # v3
  83. - name: Sign image with cosign
  84. run: |
  85. cosign sign --yes calciumion/new-api@${{ steps.build.outputs.digest }}
  86. cosign sign --yes ghcr.io/${{ env.GHCR_REPOSITORY }}@${{ steps.build.outputs.digest }}
  87. - name: Output digest
  88. run: |
  89. echo "### Docker Image Digest (${{ matrix.arch }})" >> $GITHUB_STEP_SUMMARY
  90. echo '```' >> $GITHUB_STEP_SUMMARY
  91. echo "calciumion/new-api:alpha-${{ matrix.arch }}" >> $GITHUB_STEP_SUMMARY
  92. echo "ghcr.io/${{ env.GHCR_REPOSITORY }}:alpha-${{ matrix.arch }}" >> $GITHUB_STEP_SUMMARY
  93. echo "${{ steps.build.outputs.digest }}" >> $GITHUB_STEP_SUMMARY
  94. echo '```' >> $GITHUB_STEP_SUMMARY
  95. create_manifests:
  96. name: Create multi-arch manifests (Docker Hub + GHCR)
  97. needs: [build_single_arch]
  98. runs-on: ubuntu-latest
  99. permissions:
  100. packages: write
  101. contents: read
  102. steps:
  103. - name: Check out (shallow)
  104. uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
  105. with:
  106. fetch-depth: 1
  107. - name: Normalize GHCR repository
  108. run: echo "GHCR_REPOSITORY=${GITHUB_REPOSITORY,,}" >> $GITHUB_ENV
  109. - name: Determine alpha version
  110. id: version
  111. run: |
  112. VERSION="alpha-$(date +'%Y%m%d')-$(git rev-parse --short HEAD)"
  113. echo "value=$VERSION" >> $GITHUB_OUTPUT
  114. echo "VERSION=$VERSION" >> $GITHUB_ENV
  115. - name: Log in to Docker Hub
  116. uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3
  117. with:
  118. username: ${{ secrets.DOCKERHUB_USERNAME }}
  119. password: ${{ secrets.DOCKERHUB_TOKEN }}
  120. - name: Create & push manifest (Docker Hub - alpha)
  121. run: |
  122. docker buildx imagetools create \
  123. -t calciumion/new-api:alpha \
  124. calciumion/new-api:alpha-amd64 \
  125. calciumion/new-api:alpha-arm64
  126. - name: Create & push manifest (Docker Hub - versioned alpha)
  127. run: |
  128. docker buildx imagetools create \
  129. -t calciumion/new-api:${VERSION} \
  130. calciumion/new-api:${VERSION}-amd64 \
  131. calciumion/new-api:${VERSION}-arm64
  132. - name: Log in to GHCR
  133. uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3
  134. with:
  135. registry: ghcr.io
  136. username: ${{ github.actor }}
  137. password: ${{ secrets.GITHUB_TOKEN }}
  138. - name: Create & push manifest (GHCR - alpha)
  139. run: |
  140. docker buildx imagetools create \
  141. -t ghcr.io/${GHCR_REPOSITORY}:alpha \
  142. ghcr.io/${GHCR_REPOSITORY}:alpha-amd64 \
  143. ghcr.io/${GHCR_REPOSITORY}:alpha-arm64
  144. - name: Create & push manifest (GHCR - versioned alpha)
  145. run: |
  146. docker buildx imagetools create \
  147. -t ghcr.io/${GHCR_REPOSITORY}:${VERSION} \
  148. ghcr.io/${GHCR_REPOSITORY}:${VERSION}-amd64 \
  149. ghcr.io/${GHCR_REPOSITORY}:${VERSION}-arm64
  150. - name: Output manifest digest
  151. run: |
  152. echo "### Multi-arch Manifest Digests" >> $GITHUB_STEP_SUMMARY
  153. echo '```' >> $GITHUB_STEP_SUMMARY
  154. docker buildx imagetools inspect calciumion/new-api:alpha >> $GITHUB_STEP_SUMMARY
  155. echo "---" >> $GITHUB_STEP_SUMMARY
  156. docker buildx imagetools inspect ghcr.io/${GHCR_REPOSITORY}:alpha >> $GITHUB_STEP_SUMMARY
  157. echo '```' >> $GITHUB_STEP_SUMMARY