docker.yml 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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", dockerfile: ".devops/cuda.Dockerfile", platforms: "linux/amd64", full: true, light: true, server: true, free_disk_space: true, runs_on: "ubuntu-22.04" }
  37. - { tag: "musa", dockerfile: ".devops/musa.Dockerfile", platforms: "linux/amd64", full: true, light: true, server: true, free_disk_space: true, runs_on: "ubuntu-22.04" }
  38. - { tag: "intel", dockerfile: ".devops/intel.Dockerfile", platforms: "linux/amd64", full: true, light: true, server: true, free_disk_space: true, runs_on: "ubuntu-22.04" }
  39. - { tag: "vulkan", dockerfile: ".devops/vulkan.Dockerfile", platforms: "linux/amd64", full: true, light: true, server: true, free_disk_space: false, runs_on: "ubuntu-22.04" }
  40. - { 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" }
  41. - { tag: "rocm", dockerfile: ".devops/rocm.Dockerfile", platforms: "linux/amd64", full: true, light: true, server: true, free_disk_space: true, runs_on: "ubuntu-22.04" }
  42. steps:
  43. - name: Check out the repo
  44. uses: actions/checkout@v4
  45. with:
  46. fetch-depth: 0 # preserve git history, so we can determine the build number
  47. - name: Set up QEMU
  48. if: ${{ matrix.config.tag != 's390x' }}
  49. uses: docker/setup-qemu-action@v3
  50. with:
  51. image: tonistiigi/binfmt:qemu-v7.0.0-28
  52. - name: Set up Docker Buildx
  53. uses: docker/setup-buildx-action@v3
  54. - name: Log in to Docker Hub
  55. uses: docker/login-action@v2
  56. with:
  57. registry: ghcr.io
  58. username: ${{ github.repository_owner }}
  59. password: ${{ secrets.GITHUB_TOKEN }}
  60. - name: Determine source tag name
  61. id: srctag
  62. uses: ./.github/actions/get-tag-name
  63. env:
  64. BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
  65. - name: Determine image tag name
  66. id: tag
  67. shell: bash
  68. run: |
  69. REPO_OWNER="${GITHUB_REPOSITORY_OWNER@L}" # to lower case
  70. REPO_NAME="${{ github.event.repository.name }}"
  71. # list all tags possible
  72. if [[ "${{ matrix.config.tag }}" == "cpu" ]]; then
  73. TYPE=""
  74. else
  75. TYPE="-${{ matrix.config.tag }}"
  76. fi
  77. PREFIX="ghcr.io/${REPO_OWNER}/${REPO_NAME}:"
  78. CACHETAGS="${PREFIX}buildcache${TYPE}"
  79. FULLTAGS="${PREFIX}full${TYPE},${PREFIX}full${TYPE}-${{ steps.srctag.outputs.name }}"
  80. LIGHTTAGS="${PREFIX}light${TYPE},${PREFIX}light${TYPE}-${{ steps.srctag.outputs.name }}"
  81. SERVERTAGS="${PREFIX}server${TYPE},${PREFIX}server${TYPE}-${{ steps.srctag.outputs.name }}"
  82. echo "cache_output_tags=$CACHETAGS" >> $GITHUB_OUTPUT
  83. echo "full_output_tags=$FULLTAGS" >> $GITHUB_OUTPUT
  84. echo "light_output_tags=$LIGHTTAGS" >> $GITHUB_OUTPUT
  85. echo "server_output_tags=$SERVERTAGS" >> $GITHUB_OUTPUT
  86. echo "cache_output_tags=$CACHETAGS" # print out for debugging
  87. echo "full_output_tags=$FULLTAGS" # print out for debugging
  88. echo "light_output_tags=$LIGHTTAGS" # print out for debugging
  89. echo "server_output_tags=$SERVERTAGS" # print out for debugging
  90. env:
  91. GITHUB_REPOSITORY_OWNER: '${{ github.repository_owner }}'
  92. - name: Free Disk Space (Ubuntu)
  93. if: ${{ matrix.config.free_disk_space == true }}
  94. uses: ggml-org/free-disk-space@v1.3.1
  95. with:
  96. # this might remove tools that are actually needed,
  97. # if set to "true" but frees about 6 GB
  98. tool-cache: false
  99. # all of these default to true, but feel free to set to
  100. # "false" if necessary for your workflow
  101. android: true
  102. dotnet: true
  103. haskell: true
  104. large-packages: true
  105. docker-images: true
  106. swap-storage: true
  107. - name: Build and push Full Docker image (tagged + versioned)
  108. if: ${{ (github.event_name == 'push' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') && matrix.config.full == true }}
  109. uses: docker/build-push-action@v6
  110. with:
  111. context: .
  112. push: true
  113. platforms: ${{ matrix.config.platforms }}
  114. # tag list is generated from step above
  115. tags: ${{ steps.tag.outputs.full_output_tags }}
  116. file: ${{ matrix.config.dockerfile }}
  117. target: full
  118. provenance: false
  119. # using github experimental cache
  120. #cache-from: type=gha
  121. #cache-to: type=gha,mode=max
  122. # return to this if the experimental github cache is having issues
  123. #cache-to: type=local,dest=/tmp/.buildx-cache
  124. #cache-from: type=local,src=/tmp/.buildx-cache
  125. # using registry cache (no storage limit)
  126. cache-from: type=registry,ref=${{ steps.tag.outputs.cache_output_tags }}
  127. cache-to: type=registry,ref=${{ steps.tag.outputs.cache_output_tags }},mode=max
  128. - name: Build and push Light Docker image (tagged + versioned)
  129. if: ${{ (github.event_name == 'push' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') && matrix.config.light == true }}
  130. uses: docker/build-push-action@v6
  131. with:
  132. context: .
  133. push: true
  134. platforms: ${{ matrix.config.platforms }}
  135. # tag list is generated from step above
  136. tags: ${{ steps.tag.outputs.light_output_tags }}
  137. file: ${{ matrix.config.dockerfile }}
  138. target: light
  139. provenance: false
  140. # using github experimental cache
  141. #cache-from: type=gha
  142. #cache-to: type=gha,mode=max
  143. # return to this if the experimental github cache is having issues
  144. #cache-to: type=local,dest=/tmp/.buildx-cache
  145. #cache-from: type=local,src=/tmp/.buildx-cache
  146. # using registry cache (no storage limit)
  147. cache-from: type=registry,ref=${{ steps.tag.outputs.cache_output_tags }}
  148. cache-to: type=registry,ref=${{ steps.tag.outputs.cache_output_tags }},mode=max
  149. - name: Build and push Server Docker image (tagged + versioned)
  150. if: ${{ (github.event_name == 'push' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') && matrix.config.server == true }}
  151. uses: docker/build-push-action@v6
  152. with:
  153. context: .
  154. push: true
  155. platforms: ${{ matrix.config.platforms }}
  156. # tag list is generated from step above
  157. tags: ${{ steps.tag.outputs.server_output_tags }}
  158. file: ${{ matrix.config.dockerfile }}
  159. target: server
  160. provenance: false
  161. # using github experimental cache
  162. #cache-from: type=gha
  163. #cache-to: type=gha,mode=max
  164. # return to this if the experimental github cache is having issues
  165. #cache-to: type=local,dest=/tmp/.buildx-cache
  166. #cache-from: type=local,src=/tmp/.buildx-cache
  167. # using registry cache (no storage limit)
  168. cache-from: type=registry,ref=${{ steps.tag.outputs.cache_output_tags }}
  169. cache-to: type=registry,ref=${{ steps.tag.outputs.cache_output_tags }},mode=max
  170. create_tag:
  171. name: Create and push git tag
  172. runs-on: ubuntu-22.04
  173. permissions:
  174. contents: write
  175. steps:
  176. - name: Clone
  177. id: checkout
  178. uses: actions/checkout@v4
  179. with:
  180. fetch-depth: 0
  181. - name: Determine source tag name
  182. id: srctag
  183. uses: ./.github/actions/get-tag-name
  184. env:
  185. BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
  186. - name: Create and push git tag
  187. env:
  188. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  189. run: |
  190. git tag ${{ steps.srctag.outputs.name }} || exit 0
  191. git push origin ${{ steps.srctag.outputs.name }} || exit 0