1
0

docker.yml 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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. # Note: the rocm images are failing due to a compiler error and are disabled until this is fixed to allow the workflow to complete
  42. #- {tag: "rocm", dockerfile: ".devops/rocm.Dockerfile", platforms: "linux/amd64,linux/arm64", full: true, light: true, server: true, free_disk_space: true }
  43. steps:
  44. - name: Check out the repo
  45. uses: actions/checkout@v4
  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@v2
  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. # list all tags possible
  73. if [[ "${{ matrix.config.tag }}" == "cpu" ]]; then
  74. TYPE=""
  75. else
  76. TYPE="-${{ matrix.config.tag }}"
  77. fi
  78. PREFIX="ghcr.io/${REPO_OWNER}/${REPO_NAME}:"
  79. CACHETAGS="${PREFIX}buildcache${TYPE}"
  80. FULLTAGS="${PREFIX}full${TYPE},${PREFIX}full${TYPE}-${{ steps.srctag.outputs.name }}"
  81. LIGHTTAGS="${PREFIX}light${TYPE},${PREFIX}light${TYPE}-${{ steps.srctag.outputs.name }}"
  82. SERVERTAGS="${PREFIX}server${TYPE},${PREFIX}server${TYPE}-${{ steps.srctag.outputs.name }}"
  83. echo "cache_output_tags=$CACHETAGS" >> $GITHUB_OUTPUT
  84. echo "full_output_tags=$FULLTAGS" >> $GITHUB_OUTPUT
  85. echo "light_output_tags=$LIGHTTAGS" >> $GITHUB_OUTPUT
  86. echo "server_output_tags=$SERVERTAGS" >> $GITHUB_OUTPUT
  87. echo "cache_output_tags=$CACHETAGS" # print out for debugging
  88. echo "full_output_tags=$FULLTAGS" # print out for debugging
  89. echo "light_output_tags=$LIGHTTAGS" # print out for debugging
  90. echo "server_output_tags=$SERVERTAGS" # print out for debugging
  91. env:
  92. GITHUB_REPOSITORY_OWNER: '${{ github.repository_owner }}'
  93. - name: Free Disk Space (Ubuntu)
  94. if: ${{ matrix.config.free_disk_space == true }}
  95. uses: ggml-org/free-disk-space@v1.3.1
  96. with:
  97. # this might remove tools that are actually needed,
  98. # if set to "true" but frees about 6 GB
  99. tool-cache: false
  100. # all of these default to true, but feel free to set to
  101. # "false" if necessary for your workflow
  102. android: true
  103. dotnet: true
  104. haskell: true
  105. large-packages: true
  106. docker-images: true
  107. swap-storage: true
  108. - name: Build and push Full Docker image (tagged + versioned)
  109. if: ${{ (github.event_name == 'push' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') && matrix.config.full == true }}
  110. uses: docker/build-push-action@v6
  111. with:
  112. context: .
  113. push: true
  114. platforms: ${{ matrix.config.platforms }}
  115. # tag list is generated from step above
  116. tags: ${{ steps.tag.outputs.full_output_tags }}
  117. file: ${{ matrix.config.dockerfile }}
  118. target: full
  119. provenance: false
  120. # using github experimental cache
  121. #cache-from: type=gha
  122. #cache-to: type=gha,mode=max
  123. # return to this if the experimental github cache is having issues
  124. #cache-to: type=local,dest=/tmp/.buildx-cache
  125. #cache-from: type=local,src=/tmp/.buildx-cache
  126. # using registry cache (no storage limit)
  127. cache-from: type=registry,ref=${{ steps.tag.outputs.cache_output_tags }}
  128. cache-to: type=registry,ref=${{ steps.tag.outputs.cache_output_tags }},mode=max
  129. - name: Build and push Light Docker image (tagged + versioned)
  130. if: ${{ (github.event_name == 'push' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') && matrix.config.light == true }}
  131. uses: docker/build-push-action@v6
  132. with:
  133. context: .
  134. push: true
  135. platforms: ${{ matrix.config.platforms }}
  136. # tag list is generated from step above
  137. tags: ${{ steps.tag.outputs.light_output_tags }}
  138. file: ${{ matrix.config.dockerfile }}
  139. target: light
  140. provenance: false
  141. # using github experimental cache
  142. #cache-from: type=gha
  143. #cache-to: type=gha,mode=max
  144. # return to this if the experimental github cache is having issues
  145. #cache-to: type=local,dest=/tmp/.buildx-cache
  146. #cache-from: type=local,src=/tmp/.buildx-cache
  147. # using registry cache (no storage limit)
  148. cache-from: type=registry,ref=${{ steps.tag.outputs.cache_output_tags }}
  149. cache-to: type=registry,ref=${{ steps.tag.outputs.cache_output_tags }},mode=max
  150. - name: Build and push Server Docker image (tagged + versioned)
  151. if: ${{ (github.event_name == 'push' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') && matrix.config.server == true }}
  152. uses: docker/build-push-action@v6
  153. with:
  154. context: .
  155. push: true
  156. platforms: ${{ matrix.config.platforms }}
  157. # tag list is generated from step above
  158. tags: ${{ steps.tag.outputs.server_output_tags }}
  159. file: ${{ matrix.config.dockerfile }}
  160. target: server
  161. provenance: false
  162. # using github experimental cache
  163. #cache-from: type=gha
  164. #cache-to: type=gha,mode=max
  165. # return to this if the experimental github cache is having issues
  166. #cache-to: type=local,dest=/tmp/.buildx-cache
  167. #cache-from: type=local,src=/tmp/.buildx-cache
  168. # using registry cache (no storage limit)
  169. cache-from: type=registry,ref=${{ steps.tag.outputs.cache_output_tags }}
  170. cache-to: type=registry,ref=${{ steps.tag.outputs.cache_output_tags }},mode=max
  171. create_tag:
  172. name: Create and push git tag
  173. runs-on: ubuntu-22.04
  174. permissions:
  175. contents: write
  176. steps:
  177. - name: Clone
  178. id: checkout
  179. uses: actions/checkout@v4
  180. with:
  181. fetch-depth: 0
  182. - name: Determine source tag name
  183. id: srctag
  184. uses: ./.github/actions/get-tag-name
  185. env:
  186. BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
  187. - name: Create and push git tag
  188. env:
  189. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  190. run: |
  191. git tag ${{ steps.srctag.outputs.name }} || exit 0
  192. git push origin ${{ steps.srctag.outputs.name }} || exit 0