docker.yml 8.7 KB

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