1
0

docker.yml 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. # Note: the rocm images are failing due to a compiler error and are disabled until this is fixed to allow the workflow to complete
  41. #- {tag: "rocm", dockerfile: ".devops/rocm.Dockerfile", platforms: "linux/amd64,linux/arm64", full: true, light: true, server: true, free_disk_space: true }
  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. uses: docker/setup-qemu-action@v3
  49. with:
  50. image: tonistiigi/binfmt:qemu-v7.0.0-28
  51. - name: Set up Docker Buildx
  52. uses: docker/setup-buildx-action@v3
  53. - name: Log in to Docker Hub
  54. uses: docker/login-action@v2
  55. with:
  56. registry: ghcr.io
  57. username: ${{ github.repository_owner }}
  58. password: ${{ secrets.GITHUB_TOKEN }}
  59. - name: Determine tag name
  60. id: tag
  61. shell: bash
  62. run: |
  63. BUILD_NUMBER="$(git rev-list --count HEAD)"
  64. SHORT_HASH="$(git rev-parse --short=7 HEAD)"
  65. REPO_OWNER="${GITHUB_REPOSITORY_OWNER@L}" # to lower case
  66. REPO_NAME="${{ github.event.repository.name }}"
  67. # determine tag name postfix (build number, commit hash)
  68. if [[ "${{ env.GITHUB_BRANCH_NAME }}" == "master" ]]; then
  69. TAG_POSTFIX="-b${BUILD_NUMBER}"
  70. else
  71. SAFE_NAME=$(echo "${{ env.GITHUB_BRANCH_NAME }}" | tr '/' '-')
  72. TAG_POSTFIX="-${SAFE_NAME}-${SHORT_HASH}"
  73. fi
  74. # list all tags possible
  75. if [[ "${{ matrix.config.tag }}" == "cpu" ]]; then
  76. TYPE=""
  77. else
  78. TYPE="-${{ matrix.config.tag }}"
  79. fi
  80. PREFIX="ghcr.io/${REPO_OWNER}/${REPO_NAME}:"
  81. FULLTAGS="${PREFIX}full${TYPE},${PREFIX}full${TYPE}${TAG_POSTFIX}"
  82. LIGHTTAGS="${PREFIX}light${TYPE},${PREFIX}light${TYPE}${TAG_POSTFIX}"
  83. SERVERTAGS="${PREFIX}server${TYPE},${PREFIX}server${TYPE}${TAG_POSTFIX}"
  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 "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_BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
  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. - name: Build and push Light Docker image (tagged + versioned)
  127. if: ${{ (github.event_name == 'push' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') && matrix.config.light == true }}
  128. uses: docker/build-push-action@v6
  129. with:
  130. context: .
  131. push: true
  132. platforms: ${{ matrix.config.platforms }}
  133. # tag list is generated from step above
  134. tags: ${{ steps.tag.outputs.light_output_tags }}
  135. file: ${{ matrix.config.dockerfile }}
  136. target: light
  137. provenance: false
  138. # using github experimental cache
  139. cache-from: type=gha
  140. cache-to: type=gha,mode=max
  141. # return to this if the experimental github cache is having issues
  142. #cache-to: type=local,dest=/tmp/.buildx-cache
  143. #cache-from: type=local,src=/tmp/.buildx-cache
  144. - name: Build and push Server Docker image (tagged + versioned)
  145. if: ${{ (github.event_name == 'push' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') && matrix.config.server == true }}
  146. uses: docker/build-push-action@v6
  147. with:
  148. context: .
  149. push: true
  150. platforms: ${{ matrix.config.platforms }}
  151. # tag list is generated from step above
  152. tags: ${{ steps.tag.outputs.server_output_tags }}
  153. file: ${{ matrix.config.dockerfile }}
  154. target: server
  155. provenance: false
  156. # using github experimental cache
  157. cache-from: type=gha
  158. cache-to: type=gha,mode=max
  159. # return to this if the experimental github cache is having issues
  160. #cache-to: type=local,dest=/tmp/.buildx-cache
  161. #cache-from: type=local,src=/tmp/.buildx-cache