docker.yml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. # This workflow uses actions that are not certified by GitHub.
  2. # They are provided by a third-party and are governed by
  3. # separate terms of service, privacy policy, and support
  4. # documentation.
  5. # GitHub recommends pinning actions to a commit SHA.
  6. # To get a newer version, you will need to update the SHA.
  7. # You can also reference a tag or branch, but the action may change without warning.
  8. name: Publish Docker image
  9. on:
  10. workflow_dispatch: # allows manual triggering
  11. schedule:
  12. # Rebuild daily rather than on every push because it is expensive
  13. - cron: '12 4 * * *'
  14. concurrency:
  15. group: ${{ github.workflow }}-${{ github.head_ref && github.ref || github.run_id }}
  16. cancel-in-progress: true
  17. # Fine-grant permission
  18. # https://docs.github.com/en/actions/security-for-github-actions/security-guides/automatic-token-authentication#modifying-the-permissions-for-the-github_token
  19. permissions:
  20. packages: write
  21. jobs:
  22. push_to_registry:
  23. name: Push Docker image to Docker Hub
  24. runs-on: ${{ matrix.config.runs_on }}
  25. env:
  26. COMMIT_SHA: ${{ github.sha }}
  27. strategy:
  28. fail-fast: false
  29. matrix:
  30. config:
  31. # Multi-stage build
  32. # Note: the arm64 images are failing, which prevents the amd64 images from being built
  33. # https://github.com/ggml-org/llama.cpp/issues/11888
  34. #- { tag: "cpu", dockerfile: ".devops/cpu.Dockerfile", platforms: "linux/amd64,linux/arm64", full: true, light: true, server: true, free_disk_space: false }
  35. - { tag: "cpu", dockerfile: ".devops/cpu.Dockerfile", platforms: "linux/amd64", full: true, light: true, server: true, free_disk_space: false, runs_on: "ubuntu-22.04" }
  36. - { tag: "cuda cuda12", dockerfile: ".devops/cuda.Dockerfile", platforms: "linux/amd64", full: true, light: true, server: true, free_disk_space: true, runs_on: "ubuntu-22.04", cuda_version: "12.4.0", ubuntu_version: "22.04" }
  37. - { tag: "cuda13", dockerfile: ".devops/cuda-new.Dockerfile", platforms: "linux/amd64", full: true, light: true, server: true, free_disk_space: true, runs_on: "ubuntu-22.04", cuda_version: "13.1.0", ubuntu_version: "24.04" }
  38. - { tag: "musa", dockerfile: ".devops/musa.Dockerfile", platforms: "linux/amd64", full: true, light: true, server: true, free_disk_space: true, runs_on: "ubuntu-22.04" }
  39. - { tag: "intel", dockerfile: ".devops/intel.Dockerfile", platforms: "linux/amd64", full: true, light: true, server: true, free_disk_space: true, runs_on: "ubuntu-22.04" }
  40. - { tag: "vulkan", dockerfile: ".devops/vulkan.Dockerfile", platforms: "linux/amd64", full: true, light: true, server: true, free_disk_space: false, runs_on: "ubuntu-22.04" }
  41. - { tag: "s390x", dockerfile: ".devops/s390x.Dockerfile", platforms: "linux/s390x", full: true, light: true, server: true, free_disk_space: false, runs_on: "ubuntu-22.04-s390x" }
  42. - { tag: "rocm", dockerfile: ".devops/rocm.Dockerfile", platforms: "linux/amd64", full: true, light: true, server: true, free_disk_space: true, runs_on: "ubuntu-22.04" }
  43. steps:
  44. - name: Check out the repo
  45. uses: actions/checkout@v6
  46. with:
  47. fetch-depth: 0 # preserve git history, so we can determine the build number
  48. - name: Set up QEMU
  49. if: ${{ matrix.config.tag != 's390x' }}
  50. uses: docker/setup-qemu-action@v3
  51. with:
  52. image: tonistiigi/binfmt:qemu-v7.0.0-28
  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. registry: ghcr.io
  59. username: ${{ github.repository_owner }}
  60. password: ${{ secrets.GITHUB_TOKEN }}
  61. - name: Determine source tag name
  62. id: srctag
  63. uses: ./.github/actions/get-tag-name
  64. env:
  65. BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
  66. - name: Determine image tag name
  67. id: tag
  68. shell: bash
  69. run: |
  70. REPO_OWNER="${GITHUB_REPOSITORY_OWNER@L}" # to lower case
  71. REPO_NAME="${{ github.event.repository.name }}"
  72. PREFIX="ghcr.io/${REPO_OWNER}/${REPO_NAME}:"
  73. # list all tags possible
  74. tags="${{ matrix.config.tag }}"
  75. for tag in $tags; do
  76. if [[ "$tag" == "cpu" ]]; then
  77. TYPE=""
  78. else
  79. TYPE="-$tag"
  80. fi
  81. CACHETAGS="${PREFIX}buildcache${TYPE}"
  82. FULLTAGS="${FULLTAGS:+$FULLTAGS,}${PREFIX}full${TYPE},${PREFIX}full${TYPE}-${{ steps.srctag.outputs.name }}"
  83. LIGHTTAGS="${LIGHTTAGS:+$LIGHTTAGS,}${PREFIX}light${TYPE},${PREFIX}light${TYPE}-${{ steps.srctag.outputs.name }}"
  84. SERVERTAGS="${SERVERTAGS:+$SERVERTAGS,}${PREFIX}server${TYPE},${PREFIX}server${TYPE}-${{ steps.srctag.outputs.name }}"
  85. done
  86. echo "cache_output_tags=$CACHETAGS" >> $GITHUB_OUTPUT
  87. echo "full_output_tags=$FULLTAGS" >> $GITHUB_OUTPUT
  88. echo "light_output_tags=$LIGHTTAGS" >> $GITHUB_OUTPUT
  89. echo "server_output_tags=$SERVERTAGS" >> $GITHUB_OUTPUT
  90. echo "cache_output_tags=$CACHETAGS" # print out for debugging
  91. echo "full_output_tags=$FULLTAGS" # print out for debugging
  92. echo "light_output_tags=$LIGHTTAGS" # print out for debugging
  93. echo "server_output_tags=$SERVERTAGS" # print out for debugging
  94. env:
  95. GITHUB_REPOSITORY_OWNER: '${{ github.repository_owner }}'
  96. - name: Free Disk Space (Ubuntu)
  97. if: ${{ matrix.config.free_disk_space == true }}
  98. uses: ggml-org/free-disk-space@v1.3.1
  99. with:
  100. # this might remove tools that are actually needed,
  101. # if set to "true" but frees about 6 GB
  102. tool-cache: false
  103. # all of these default to true, but feel free to set to
  104. # "false" if necessary for your workflow
  105. android: true
  106. dotnet: true
  107. haskell: true
  108. large-packages: true
  109. docker-images: true
  110. swap-storage: true
  111. - name: Build and push Full Docker image (tagged + versioned)
  112. if: ${{ (github.event_name == 'push' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') && matrix.config.full == true }}
  113. uses: docker/build-push-action@v6
  114. with:
  115. context: .
  116. push: true
  117. platforms: ${{ matrix.config.platforms }}
  118. # tag list is generated from step above
  119. tags: ${{ steps.tag.outputs.full_output_tags }}
  120. file: ${{ matrix.config.dockerfile }}
  121. target: full
  122. provenance: false
  123. build-args: |
  124. ${{ matrix.config.ubuntu_version && format('UBUNTU_VERSION={0}', matrix.config.ubuntu_version) || '' }}
  125. ${{ matrix.config.cuda_version && format('CUDA_VERSION={0}', matrix.config.cuda_version) || '' }}
  126. # using github experimental cache
  127. #cache-from: type=gha
  128. #cache-to: type=gha,mode=max
  129. # return to this if the experimental github cache is having issues
  130. #cache-to: type=local,dest=/tmp/.buildx-cache
  131. #cache-from: type=local,src=/tmp/.buildx-cache
  132. # using registry cache (no storage limit)
  133. cache-from: type=registry,ref=${{ steps.tag.outputs.cache_output_tags }}
  134. cache-to: type=registry,ref=${{ steps.tag.outputs.cache_output_tags }},mode=max
  135. - name: Build and push Light Docker image (tagged + versioned)
  136. if: ${{ (github.event_name == 'push' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') && matrix.config.light == true }}
  137. uses: docker/build-push-action@v6
  138. with:
  139. context: .
  140. push: true
  141. platforms: ${{ matrix.config.platforms }}
  142. # tag list is generated from step above
  143. tags: ${{ steps.tag.outputs.light_output_tags }}
  144. file: ${{ matrix.config.dockerfile }}
  145. target: light
  146. provenance: false
  147. build-args: |
  148. ${{ matrix.config.ubuntu_version && format('UBUNTU_VERSION={0}', matrix.config.ubuntu_version) || '' }}
  149. ${{ matrix.config.cuda_version && format('CUDA_VERSION={0}', matrix.config.cuda_version) || '' }}
  150. # using github experimental cache
  151. #cache-from: type=gha
  152. #cache-to: type=gha,mode=max
  153. # return to this if the experimental github cache is having issues
  154. #cache-to: type=local,dest=/tmp/.buildx-cache
  155. #cache-from: type=local,src=/tmp/.buildx-cache
  156. # using registry cache (no storage limit)
  157. cache-from: type=registry,ref=${{ steps.tag.outputs.cache_output_tags }}
  158. cache-to: type=registry,ref=${{ steps.tag.outputs.cache_output_tags }},mode=max
  159. - name: Build and push Server Docker image (tagged + versioned)
  160. if: ${{ (github.event_name == 'push' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') && matrix.config.server == true }}
  161. uses: docker/build-push-action@v6
  162. with:
  163. context: .
  164. push: true
  165. platforms: ${{ matrix.config.platforms }}
  166. # tag list is generated from step above
  167. tags: ${{ steps.tag.outputs.server_output_tags }}
  168. file: ${{ matrix.config.dockerfile }}
  169. target: server
  170. provenance: false
  171. build-args: |
  172. ${{ matrix.config.ubuntu_version && format('UBUNTU_VERSION={0}', matrix.config.ubuntu_version) || '' }}
  173. ${{ matrix.config.cuda_version && format('CUDA_VERSION={0}', matrix.config.cuda_version) || '' }}
  174. # using github experimental cache
  175. #cache-from: type=gha
  176. #cache-to: type=gha,mode=max
  177. # return to this if the experimental github cache is having issues
  178. #cache-to: type=local,dest=/tmp/.buildx-cache
  179. #cache-from: type=local,src=/tmp/.buildx-cache
  180. # using registry cache (no storage limit)
  181. cache-from: type=registry,ref=${{ steps.tag.outputs.cache_output_tags }}
  182. cache-to: type=registry,ref=${{ steps.tag.outputs.cache_output_tags }},mode=max
  183. create_tag:
  184. name: Create and push git tag
  185. runs-on: ubuntu-22.04
  186. permissions:
  187. contents: write
  188. steps:
  189. - name: Clone
  190. id: checkout
  191. uses: actions/checkout@v6
  192. with:
  193. fetch-depth: 0
  194. - name: Determine source tag name
  195. id: srctag
  196. uses: ./.github/actions/get-tag-name
  197. env:
  198. BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
  199. - name: Create and push git tag
  200. env:
  201. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  202. run: |
  203. git tag ${{ steps.srctag.outputs.name }} || exit 0
  204. git push origin ${{ steps.srctag.outputs.name }} || exit 0