docker.yml 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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. # Note: the intel images are failing due to an out of disk space error
  39. # - { tag: "intel", dockerfile: ".devops/intel.Dockerfile", platforms: "linux/amd64", full: true, light: true, server: true, free_disk_space: false }
  40. - { tag: "vulkan", dockerfile: ".devops/vulkan.Dockerfile", platforms: "linux/amd64", 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 tag name
  61. id: tag
  62. shell: bash
  63. run: |
  64. BUILD_NUMBER="$(git rev-list --count HEAD)"
  65. SHORT_HASH="$(git rev-parse --short=7 HEAD)"
  66. REPO_OWNER="${GITHUB_REPOSITORY_OWNER@L}" # to lower case
  67. REPO_NAME="${{ github.event.repository.name }}"
  68. # determine tag name postfix (build number, commit hash)
  69. if [[ "${{ env.GITHUB_BRANCH_NAME }}" == "master" ]]; then
  70. TAG_POSTFIX="-b${BUILD_NUMBER}"
  71. else
  72. SAFE_NAME=$(echo "${{ env.GITHUB_BRANCH_NAME }}" | tr '/' '-')
  73. TAG_POSTFIX="-${SAFE_NAME}-${SHORT_HASH}"
  74. fi
  75. # list all tags possible
  76. if [[ "${{ matrix.config.tag }}" == "cpu" ]]; then
  77. TYPE=""
  78. else
  79. TYPE="-${{ matrix.config.tag }}"
  80. fi
  81. PREFIX="ghcr.io/${REPO_OWNER}/${REPO_NAME}:"
  82. FULLTAGS="${PREFIX}full${TYPE},${PREFIX}full${TYPE}${TAG_POSTFIX}"
  83. LIGHTTAGS="${PREFIX}light${TYPE},${PREFIX}light${TYPE}${TAG_POSTFIX}"
  84. SERVERTAGS="${PREFIX}server${TYPE},${PREFIX}server${TYPE}${TAG_POSTFIX}"
  85. echo "full_output_tags=$FULLTAGS" >> $GITHUB_OUTPUT
  86. echo "light_output_tags=$LIGHTTAGS" >> $GITHUB_OUTPUT
  87. echo "server_output_tags=$SERVERTAGS" >> $GITHUB_OUTPUT
  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_BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
  93. GITHUB_REPOSITORY_OWNER: '${{ github.repository_owner }}'
  94. - name: Free Disk Space (Ubuntu)
  95. if: ${{ matrix.config.free_disk_space == true }}
  96. uses: ggml-org/free-disk-space@v1.3.1
  97. with:
  98. # this might remove tools that are actually needed,
  99. # if set to "true" but frees about 6 GB
  100. tool-cache: false
  101. # all of these default to true, but feel free to set to
  102. # "false" if necessary for your workflow
  103. android: true
  104. dotnet: true
  105. haskell: true
  106. large-packages: true
  107. docker-images: true
  108. swap-storage: true
  109. - name: Build and push Full Docker image (tagged + versioned)
  110. if: ${{ (github.event_name == 'push' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') && matrix.config.full == true }}
  111. uses: docker/build-push-action@v6
  112. with:
  113. context: .
  114. push: true
  115. platforms: ${{ matrix.config.platforms }}
  116. # tag list is generated from step above
  117. tags: ${{ steps.tag.outputs.full_output_tags }}
  118. file: ${{ matrix.config.dockerfile }}
  119. target: full
  120. provenance: false
  121. # using github experimental cache
  122. cache-from: type=gha
  123. cache-to: type=gha,mode=max
  124. # return to this if the experimental github cache is having issues
  125. #cache-to: type=local,dest=/tmp/.buildx-cache
  126. #cache-from: type=local,src=/tmp/.buildx-cache
  127. - name: Build and push Light Docker image (tagged + versioned)
  128. if: ${{ (github.event_name == 'push' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') && matrix.config.light == true }}
  129. uses: docker/build-push-action@v6
  130. with:
  131. context: .
  132. push: true
  133. platforms: ${{ matrix.config.platforms }}
  134. # tag list is generated from step above
  135. tags: ${{ steps.tag.outputs.light_output_tags }}
  136. file: ${{ matrix.config.dockerfile }}
  137. target: light
  138. provenance: false
  139. # using github experimental cache
  140. cache-from: type=gha
  141. cache-to: type=gha,mode=max
  142. # return to this if the experimental github cache is having issues
  143. #cache-to: type=local,dest=/tmp/.buildx-cache
  144. #cache-from: type=local,src=/tmp/.buildx-cache
  145. - name: Build and push Server Docker image (tagged + versioned)
  146. if: ${{ (github.event_name == 'push' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') && matrix.config.server == true }}
  147. uses: docker/build-push-action@v6
  148. with:
  149. context: .
  150. push: true
  151. platforms: ${{ matrix.config.platforms }}
  152. # tag list is generated from step above
  153. tags: ${{ steps.tag.outputs.server_output_tags }}
  154. file: ${{ matrix.config.dockerfile }}
  155. target: server
  156. provenance: false
  157. # using github experimental cache
  158. cache-from: type=gha
  159. cache-to: type=gha,mode=max
  160. # return to this if the experimental github cache is having issues
  161. #cache-to: type=local,dest=/tmp/.buildx-cache
  162. #cache-from: type=local,src=/tmp/.buildx-cache