docker.yml 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. name: Publish Docker Image
  2. on:
  3. push:
  4. branches: [ master ]
  5. tags:
  6. - '**'
  7. concurrency:
  8. group: ${{ github.ref }}-${{ github.workflow }}
  9. cancel-in-progress: true
  10. env:
  11. REGISTRY_IMAGE: metacubex/subconverter
  12. GHCR_IMAGE: ghcr.io/metacubex/subconverter
  13. jobs:
  14. build-dockerhub:
  15. strategy:
  16. matrix:
  17. include:
  18. - platform: linux/amd64
  19. os: ubuntu-latest
  20. - platform: linux/386
  21. os: ubuntu-latest
  22. - platform: linux/arm/v7
  23. os: ubuntu-24.04-arm
  24. - platform: linux/arm64
  25. os: ubuntu-24.04-arm
  26. runs-on: ${{ matrix.os }}
  27. name: Build ${{ matrix.platform }} for Docker Hub
  28. steps:
  29. - name: Prepare
  30. run: |
  31. platform=${{ matrix.platform }}
  32. echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
  33. - name: Checkout base
  34. uses: actions/checkout@v4
  35. with:
  36. fetch-depth: 0
  37. - name: Set up Docker Buildx
  38. uses: docker/setup-buildx-action@v3
  39. - name: Docker meta
  40. id: meta
  41. uses: docker/metadata-action@v5
  42. with:
  43. images: ${{ env.REGISTRY_IMAGE }}
  44. tags: |
  45. type=semver,pattern={{version}}
  46. type=raw,value=latest,enable={{is_default_branch}}
  47. - name: Docker login
  48. uses: docker/login-action@v3
  49. with:
  50. username: ${{ secrets.DOCKER_USERNAME }}
  51. password: ${{ secrets.DOCKER_PASSWORD }}
  52. - name: Get commit SHA
  53. if: github.ref == 'refs/heads/master'
  54. id: vars
  55. run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
  56. - name: Build and export
  57. id: build
  58. uses: docker/build-push-action@v5
  59. with:
  60. platforms: ${{ matrix.platform }}
  61. context: scripts/
  62. labels: ${{ steps.meta.outputs.labels }}
  63. build-args: |
  64. SHA=${{ steps.vars.outputs.sha_short }}
  65. outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true
  66. - name: Export digest
  67. run: |
  68. rm -rf /tmp/digests-dockerhub
  69. mkdir -p /tmp/digests-dockerhub
  70. digest="${{ steps.build.outputs.digest }}"
  71. touch "/tmp/digests-dockerhub/${digest#sha256:}"
  72. - name: Upload artifact
  73. uses: actions/upload-artifact@v4
  74. with:
  75. name: digest-dockerhub-${{ env.PLATFORM_PAIR }}
  76. path: /tmp/digests-dockerhub/*
  77. if-no-files-found: error
  78. retention-days: 1
  79. build-ghcr:
  80. strategy:
  81. matrix:
  82. include:
  83. - platform: linux/amd64
  84. os: ubuntu-latest
  85. - platform: linux/386
  86. os: ubuntu-latest
  87. - platform: linux/arm/v7
  88. os: ubuntu-24.04-arm
  89. - platform: linux/arm64
  90. os: ubuntu-24.04-arm
  91. runs-on: ${{ matrix.os }}
  92. name: Build ${{ matrix.platform }} for GHCR
  93. steps:
  94. - name: Prepare
  95. run: |
  96. platform=${{ matrix.platform }}
  97. echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
  98. - name: Checkout base
  99. uses: actions/checkout@v4
  100. with:
  101. fetch-depth: 0
  102. - name: Set up Docker Buildx
  103. uses: docker/setup-buildx-action@v3
  104. - name: Docker meta
  105. id: meta
  106. uses: docker/metadata-action@v5
  107. with:
  108. images: ${{ env.GHCR_IMAGE }}
  109. tags: |
  110. type=semver,pattern={{version}}
  111. type=raw,value=latest,enable={{is_default_branch}}
  112. - name: Login to GitHub Container Registry
  113. uses: docker/login-action@v3
  114. with:
  115. registry: ghcr.io
  116. username: ${{ github.actor }}
  117. password: ${{ secrets.GITHUB_TOKEN }}
  118. - name: Get commit SHA
  119. if: github.ref == 'refs/heads/master'
  120. id: vars
  121. run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
  122. - name: Build and export
  123. id: build
  124. uses: docker/build-push-action@v5
  125. with:
  126. platforms: ${{ matrix.platform }}
  127. context: scripts/
  128. labels: ${{ steps.meta.outputs.labels }}
  129. build-args: |
  130. SHA=${{ steps.vars.outputs.sha_short }}
  131. outputs: type=image,name=${{ env.GHCR_IMAGE }},push-by-digest=true,name-canonical=true,push=true
  132. - name: Export digest
  133. run: |
  134. rm -rf /tmp/digests-ghcr
  135. mkdir -p /tmp/digests-ghcr
  136. digest="${{ steps.build.outputs.digest }}"
  137. touch "/tmp/digests-ghcr/${digest#sha256:}"
  138. - name: Upload artifact
  139. uses: actions/upload-artifact@v4
  140. with:
  141. name: digest-ghcr-${{ env.PLATFORM_PAIR }}
  142. path: /tmp/digests-ghcr/*
  143. if-no-files-found: error
  144. retention-days: 1
  145. merge-dockerhub:
  146. name: Merge Docker Hub
  147. needs: build-dockerhub
  148. runs-on: ubuntu-latest
  149. steps:
  150. - name: Download digests
  151. uses: actions/download-artifact@v4
  152. with:
  153. path: /tmp/digests-dockerhub
  154. pattern: digest-dockerhub-*
  155. merge-multiple: true
  156. - name: Set up Docker Buildx
  157. uses: docker/setup-buildx-action@v3
  158. - name: Docker meta
  159. id: meta
  160. uses: docker/metadata-action@v5
  161. with:
  162. images: ${{ env.REGISTRY_IMAGE }}
  163. tags: |
  164. type=semver,pattern={{version}}
  165. type=raw,value=latest,enable={{is_default_branch}}
  166. - name: Docker login
  167. uses: docker/login-action@v3
  168. with:
  169. username: ${{ secrets.DOCKER_USERNAME }}
  170. password: ${{ secrets.DOCKER_PASSWORD }}
  171. - name: Create manifest list and push
  172. working-directory: /tmp/digests-dockerhub
  173. run: |
  174. docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
  175. $(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)
  176. - name: Inspect image
  177. run: |
  178. docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}
  179. merge-ghcr:
  180. name: Merge GHCR
  181. needs: build-ghcr
  182. runs-on: ubuntu-latest
  183. steps:
  184. - name: Download digests
  185. uses: actions/download-artifact@v4
  186. with:
  187. path: /tmp/digests-ghcr
  188. pattern: digest-ghcr-*
  189. merge-multiple: true
  190. - name: Set up Docker Buildx
  191. uses: docker/setup-buildx-action@v3
  192. - name: Docker meta
  193. id: meta
  194. uses: docker/metadata-action@v5
  195. with:
  196. images: ${{ env.GHCR_IMAGE }}
  197. tags: |
  198. type=semver,pattern={{version}}
  199. type=raw,value=latest,enable={{is_default_branch}}
  200. - name: Login to GitHub Container Registry
  201. uses: docker/login-action@v3
  202. with:
  203. registry: ghcr.io
  204. username: ${{ github.actor }}
  205. password: ${{ secrets.GITHUB_TOKEN }}
  206. - name: Create manifest list and push
  207. working-directory: /tmp/digests-ghcr
  208. run: |
  209. docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
  210. $(printf '${{ env.GHCR_IMAGE }}@sha256:%s ' *)
  211. - name: Inspect image
  212. run: |
  213. docker buildx imagetools inspect ${{ env.GHCR_IMAGE }}:${{ steps.meta.outputs.version }}