docker.yml 8.5 KB

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