docker-image-alpha.yml 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. steps:
  29. - name: Check out (shallow)
  30. uses: actions/checkout@v4
  31. with:
  32. fetch-depth: 1
  33. - name: Determine alpha version
  34. id: version
  35. run: |
  36. VERSION="alpha-$(date +'%Y%m%d')-$(git rev-parse --short HEAD)"
  37. echo "$VERSION" > VERSION
  38. echo "value=$VERSION" >> $GITHUB_OUTPUT
  39. echo "VERSION=$VERSION" >> $GITHUB_ENV
  40. echo "Publishing version: $VERSION for ${{ matrix.arch }}"
  41. - name: Normalize GHCR repository
  42. run: echo "GHCR_REPOSITORY=${GITHUB_REPOSITORY,,}" >> $GITHUB_ENV
  43. - name: Set up Docker Buildx
  44. uses: docker/setup-buildx-action@v3
  45. - name: Log in to Docker Hub
  46. uses: docker/login-action@v3
  47. with:
  48. username: ${{ secrets.DOCKERHUB_USERNAME }}
  49. password: ${{ secrets.DOCKERHUB_TOKEN }}
  50. - name: Log in to GHCR
  51. uses: docker/login-action@v3
  52. with:
  53. registry: ghcr.io
  54. username: ${{ github.actor }}
  55. password: ${{ secrets.GITHUB_TOKEN }}
  56. - name: Extract metadata (labels)
  57. id: meta
  58. uses: docker/metadata-action@v5
  59. with:
  60. images: |
  61. calciumion/new-api
  62. ghcr.io/${{ env.GHCR_REPOSITORY }}
  63. - name: Build & push single-arch (to both registries)
  64. uses: docker/build-push-action@v6
  65. with:
  66. context: .
  67. platforms: ${{ matrix.platform }}
  68. push: true
  69. tags: |
  70. calciumion/new-api:alpha-${{ matrix.arch }}
  71. calciumion/new-api:${{ steps.version.outputs.value }}-${{ matrix.arch }}
  72. ghcr.io/${{ env.GHCR_REPOSITORY }}:alpha-${{ matrix.arch }}
  73. ghcr.io/${{ env.GHCR_REPOSITORY }}:${{ steps.version.outputs.value }}-${{ matrix.arch }}
  74. labels: ${{ steps.meta.outputs.labels }}
  75. cache-from: type=gha
  76. cache-to: type=gha,mode=max
  77. provenance: false
  78. sbom: false
  79. create_manifests:
  80. name: Create multi-arch manifests (Docker Hub + GHCR)
  81. needs: [build_single_arch]
  82. runs-on: ubuntu-latest
  83. permissions:
  84. packages: write
  85. contents: read
  86. steps:
  87. - name: Check out (shallow)
  88. uses: actions/checkout@v4
  89. with:
  90. fetch-depth: 1
  91. - name: Normalize GHCR repository
  92. run: echo "GHCR_REPOSITORY=${GITHUB_REPOSITORY,,}" >> $GITHUB_ENV
  93. - name: Determine alpha version
  94. id: version
  95. run: |
  96. VERSION="alpha-$(date +'%Y%m%d')-$(git rev-parse --short HEAD)"
  97. echo "value=$VERSION" >> $GITHUB_OUTPUT
  98. echo "VERSION=$VERSION" >> $GITHUB_ENV
  99. - name: Log in to Docker Hub
  100. uses: docker/login-action@v3
  101. with:
  102. username: ${{ secrets.DOCKERHUB_USERNAME }}
  103. password: ${{ secrets.DOCKERHUB_TOKEN }}
  104. - name: Create & push manifest (Docker Hub - alpha)
  105. run: |
  106. docker buildx imagetools create \
  107. -t calciumion/new-api:alpha \
  108. calciumion/new-api:alpha-amd64 \
  109. calciumion/new-api:alpha-arm64
  110. - name: Create & push manifest (Docker Hub - versioned alpha)
  111. run: |
  112. docker buildx imagetools create \
  113. -t calciumion/new-api:${VERSION} \
  114. calciumion/new-api:${VERSION}-amd64 \
  115. calciumion/new-api:${VERSION}-arm64
  116. - name: Log in to GHCR
  117. uses: docker/login-action@v3
  118. with:
  119. registry: ghcr.io
  120. username: ${{ github.actor }}
  121. password: ${{ secrets.GITHUB_TOKEN }}
  122. - name: Create & push manifest (GHCR - alpha)
  123. run: |
  124. docker buildx imagetools create \
  125. -t ghcr.io/${GHCR_REPOSITORY}:alpha \
  126. ghcr.io/${GHCR_REPOSITORY}:alpha-amd64 \
  127. ghcr.io/${GHCR_REPOSITORY}:alpha-arm64
  128. - name: Create & push manifest (GHCR - versioned alpha)
  129. run: |
  130. docker buildx imagetools create \
  131. -t ghcr.io/${GHCR_REPOSITORY}:${VERSION} \
  132. ghcr.io/${GHCR_REPOSITORY}:${VERSION}-amd64 \
  133. ghcr.io/${GHCR_REPOSITORY}:${VERSION}-arm64