docker-build.yaml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. name: Create and publish Docker images with specific build args
  2. on:
  3. workflow_dispatch:
  4. push:
  5. branches:
  6. - main
  7. - dev
  8. tags:
  9. - v*
  10. env:
  11. REGISTRY: ghcr.io
  12. IMAGE_NAME: ${{ github.repository }}
  13. FULL_IMAGE_NAME: ghcr.io/${{ github.repository }}
  14. jobs:
  15. build-main-image:
  16. runs-on: ubuntu-latest
  17. permissions:
  18. contents: read
  19. packages: write
  20. strategy:
  21. fail-fast: false
  22. matrix:
  23. platform:
  24. - linux/amd64
  25. - linux/arm64
  26. steps:
  27. - name: Prepare
  28. run: |
  29. platform=${{ matrix.platform }}
  30. echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
  31. - name: Checkout repository
  32. uses: actions/checkout@v4
  33. - name: Set up QEMU
  34. uses: docker/setup-qemu-action@v3
  35. - name: Set up Docker Buildx
  36. uses: docker/setup-buildx-action@v3
  37. - name: Log in to the Container registry
  38. uses: docker/login-action@v3
  39. with:
  40. registry: ${{ env.REGISTRY }}
  41. username: ${{ github.actor }}
  42. password: ${{ secrets.GITHUB_TOKEN }}
  43. - name: Extract metadata for Docker images (default latest tag)
  44. id: meta
  45. uses: docker/metadata-action@v5
  46. with:
  47. images: ${{ env.FULL_IMAGE_NAME }}
  48. tags: |
  49. type=ref,event=branch
  50. type=ref,event=tag
  51. type=sha,prefix=git-
  52. type=semver,pattern={{version}}
  53. type=semver,pattern={{major}}.{{minor}}
  54. flavor: |
  55. latest=${{ github.ref == 'refs/heads/main' }}
  56. - name: Build Docker image (latest)
  57. uses: docker/build-push-action@v5
  58. id: build
  59. with:
  60. context: .
  61. push: true
  62. platforms: ${{ matrix.platform }}
  63. labels: ${{ steps.meta.outputs.labels }}
  64. outputs: type=image,name=${{ env.FULL_IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true
  65. cache-from: type=gha
  66. cache-to: type=gha,mode=max
  67. - name: Export digest
  68. run: |
  69. mkdir -p /tmp/digests
  70. digest="${{ steps.build.outputs.digest }}"
  71. touch "/tmp/digests/${digest#sha256:}"
  72. - name: Upload digest
  73. uses: actions/upload-artifact@v4
  74. with:
  75. name: digests-main-${{ env.PLATFORM_PAIR }}
  76. path: /tmp/digests/*
  77. if-no-files-found: error
  78. retention-days: 1
  79. build-cuda-image:
  80. runs-on: ubuntu-latest
  81. permissions:
  82. contents: read
  83. packages: write
  84. strategy:
  85. fail-fast: false
  86. matrix:
  87. platform:
  88. - linux/amd64
  89. - linux/arm64
  90. steps:
  91. - name: Prepare
  92. run: |
  93. platform=${{ matrix.platform }}
  94. echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
  95. - name: Checkout repository
  96. uses: actions/checkout@v4
  97. - name: Set up QEMU
  98. uses: docker/setup-qemu-action@v3
  99. - name: Set up Docker Buildx
  100. uses: docker/setup-buildx-action@v3
  101. - name: Log in to the Container registry
  102. uses: docker/login-action@v3
  103. with:
  104. registry: ${{ env.REGISTRY }}
  105. username: ${{ github.actor }}
  106. password: ${{ secrets.GITHUB_TOKEN }}
  107. - name: Extract metadata for Docker images (default latest tag)
  108. id: meta
  109. uses: docker/metadata-action@v5
  110. with:
  111. images: ${{ env.FULL_IMAGE_NAME }}
  112. tags: |
  113. type=ref,event=branch
  114. type=ref,event=tag
  115. type=sha,prefix=git-
  116. type=semver,pattern={{version}}
  117. type=semver,pattern={{major}}.{{minor}}
  118. type=raw,enable=${{ github.ref == 'refs/heads/main' }},prefix=,suffix=,value=cuda
  119. flavor: |
  120. latest=${{ github.ref == 'refs/heads/main' }}
  121. suffix=-cuda,onlatest=true
  122. - name: Build Docker image (cuda)
  123. uses: docker/build-push-action@v5
  124. id: build
  125. with:
  126. context: .
  127. push: true
  128. platforms: ${{ matrix.platform }}
  129. labels: ${{ steps.meta.outputs.labels }}
  130. outputs: type=image,name=${{ env.FULL_IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true
  131. cache-from: type=gha
  132. cache-to: type=gha,mode=max
  133. build-args: USE_CUDA=true
  134. - name: Export digest
  135. run: |
  136. mkdir -p /tmp/digests
  137. digest="${{ steps.build.outputs.digest }}"
  138. touch "/tmp/digests/${digest#sha256:}"
  139. - name: Upload digest
  140. uses: actions/upload-artifact@v4
  141. with:
  142. name: digests-cuda-${{ env.PLATFORM_PAIR }}
  143. path: /tmp/digests/*
  144. if-no-files-found: error
  145. retention-days: 1
  146. build-ollama-image:
  147. runs-on: ubuntu-latest
  148. permissions:
  149. contents: read
  150. packages: write
  151. strategy:
  152. fail-fast: false
  153. matrix:
  154. platform:
  155. - linux/amd64
  156. - linux/arm64
  157. steps:
  158. - name: Prepare
  159. run: |
  160. platform=${{ matrix.platform }}
  161. echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
  162. - name: Checkout repository
  163. uses: actions/checkout@v4
  164. - name: Set up QEMU
  165. uses: docker/setup-qemu-action@v3
  166. - name: Set up Docker Buildx
  167. uses: docker/setup-buildx-action@v3
  168. - name: Log in to the Container registry
  169. uses: docker/login-action@v3
  170. with:
  171. registry: ${{ env.REGISTRY }}
  172. username: ${{ github.actor }}
  173. password: ${{ secrets.GITHUB_TOKEN }}
  174. - name: Extract metadata for Docker images (ollama tag)
  175. id: meta
  176. uses: docker/metadata-action@v5
  177. with:
  178. images: ${{ env.FULL_IMAGE_NAME }}
  179. tags: |
  180. type=ref,event=branch
  181. type=ref,event=tag
  182. type=sha,prefix=git-
  183. type=semver,pattern={{version}}
  184. type=semver,pattern={{major}}.{{minor}}
  185. type=raw,enable=${{ github.ref == 'refs/heads/main' }},prefix=,suffix=,value=ollama
  186. flavor: |
  187. latest=${{ github.ref == 'refs/heads/main' }}
  188. suffix=-ollama,onlatest=true
  189. - name: Build Docker image (ollama)
  190. uses: docker/build-push-action@v5
  191. id: build
  192. with:
  193. context: .
  194. push: true
  195. platforms: ${{ matrix.platform }}
  196. labels: ${{ steps.meta.outputs.labels }}
  197. outputs: type=image,name=${{ env.FULL_IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true
  198. cache-from: type=gha
  199. cache-to: type=gha,mode=max
  200. build-args: USE_OLLAMA=true
  201. - name: Export digest
  202. run: |
  203. mkdir -p /tmp/digests
  204. digest="${{ steps.build.outputs.digest }}"
  205. touch "/tmp/digests/${digest#sha256:}"
  206. - name: Upload digest
  207. uses: actions/upload-artifact@v4
  208. with:
  209. name: digests-ollama-${{ env.PLATFORM_PAIR }}
  210. path: /tmp/digests/*
  211. if-no-files-found: error
  212. retention-days: 1
  213. merge-main-images:
  214. runs-on: ubuntu-latest
  215. needs: [ build-main-image ]
  216. steps:
  217. - name: Download digests
  218. uses: actions/download-artifact@v4
  219. with:
  220. pattern: digests-main-*
  221. path: /tmp/digests
  222. merge-multiple: true
  223. - name: Set up Docker Buildx
  224. uses: docker/setup-buildx-action@v3
  225. - name: Log in to the Container registry
  226. uses: docker/login-action@v3
  227. with:
  228. registry: ${{ env.REGISTRY }}
  229. username: ${{ github.actor }}
  230. password: ${{ secrets.GITHUB_TOKEN }}
  231. - name: Extract metadata for Docker images (default latest tag)
  232. id: meta
  233. uses: docker/metadata-action@v5
  234. with:
  235. images: ${{ env.FULL_IMAGE_NAME }}
  236. tags: |
  237. type=ref,event=branch
  238. type=ref,event=tag
  239. type=sha,prefix=git-
  240. type=semver,pattern={{version}}
  241. type=semver,pattern={{major}}.{{minor}}
  242. flavor: |
  243. latest=${{ github.ref == 'refs/heads/main' }}
  244. - name: Create manifest list and push
  245. working-directory: /tmp/digests
  246. run: |
  247. docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
  248. $(printf '${{ env.FULL_IMAGE_NAME }}@sha256:%s ' *)
  249. - name: Inspect image
  250. run: |
  251. docker buildx imagetools inspect ${{ env.FULL_IMAGE_NAME }}:${{ steps.meta.outputs.version }}
  252. merge-cuda-images:
  253. runs-on: ubuntu-latest
  254. needs: [ build-cuda-image ]
  255. steps:
  256. - name: Download digests
  257. uses: actions/download-artifact@v4
  258. with:
  259. pattern: digests-cuda-*
  260. path: /tmp/digests
  261. merge-multiple: true
  262. - name: Set up Docker Buildx
  263. uses: docker/setup-buildx-action@v3
  264. - name: Log in to the Container registry
  265. uses: docker/login-action@v3
  266. with:
  267. registry: ${{ env.REGISTRY }}
  268. username: ${{ github.actor }}
  269. password: ${{ secrets.GITHUB_TOKEN }}
  270. - name: Extract metadata for Docker images (default latest tag)
  271. id: meta
  272. uses: docker/metadata-action@v5
  273. with:
  274. images: ${{ env.FULL_IMAGE_NAME }}
  275. tags: |
  276. type=ref,event=branch
  277. type=ref,event=tag
  278. type=sha,prefix=git-
  279. type=semver,pattern={{version}}
  280. type=semver,pattern={{major}}.{{minor}}
  281. type=raw,enable=${{ github.ref == 'refs/heads/main' }},prefix=,suffix=,value=cuda
  282. flavor: |
  283. latest=${{ github.ref == 'refs/heads/main' }}
  284. suffix=-cuda,onlatest=true
  285. - name: Create manifest list and push
  286. working-directory: /tmp/digests
  287. run: |
  288. docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
  289. $(printf '${{ env.FULL_IMAGE_NAME }}@sha256:%s ' *)
  290. - name: Inspect image
  291. run: |
  292. docker buildx imagetools inspect ${{ env.FULL_IMAGE_NAME }}:${{ steps.meta.outputs.version }}
  293. merge-ollama-images:
  294. runs-on: ubuntu-latest
  295. needs: [ build-ollama-image ]
  296. steps:
  297. - name: Download digests
  298. uses: actions/download-artifact@v4
  299. with:
  300. pattern: digests-ollama-*
  301. path: /tmp/digests
  302. merge-multiple: true
  303. - name: Set up Docker Buildx
  304. uses: docker/setup-buildx-action@v3
  305. - name: Log in to the Container registry
  306. uses: docker/login-action@v3
  307. with:
  308. registry: ${{ env.REGISTRY }}
  309. username: ${{ github.actor }}
  310. password: ${{ secrets.GITHUB_TOKEN }}
  311. - name: Extract metadata for Docker images (default ollama tag)
  312. id: meta
  313. uses: docker/metadata-action@v5
  314. with:
  315. images: ${{ env.FULL_IMAGE_NAME }}
  316. tags: |
  317. type=ref,event=branch
  318. type=ref,event=tag
  319. type=sha,prefix=git-
  320. type=semver,pattern={{version}}
  321. type=semver,pattern={{major}}.{{minor}}
  322. type=raw,enable=${{ github.ref == 'refs/heads/main' }},prefix=,suffix=,value=ollama
  323. flavor: |
  324. latest=${{ github.ref == 'refs/heads/main' }}
  325. suffix=-ollama,onlatest=true
  326. - name: Create manifest list and push
  327. working-directory: /tmp/digests
  328. run: |
  329. docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
  330. $(printf '${{ env.FULL_IMAGE_NAME }}@sha256:%s ' *)
  331. - name: Inspect image
  332. run: |
  333. docker buildx imagetools inspect ${{ env.FULL_IMAGE_NAME }}:${{ steps.meta.outputs.version }}