docker.yml 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. - { tag: "cpu", dockerfile: ".devops/cpu.Dockerfile", platforms: "linux/amd64,linux/arm64", full: true, light: true, server: true, freediskspace: false}
  33. - { tag: "cuda", dockerfile: ".devops/cuda.Dockerfile", platforms: "linux/amd64", full: true, light: true, server: true, freediskspace: false}
  34. - { tag: "musa", dockerfile: ".devops/musa.Dockerfile", platforms: "linux/amd64", full: true, light: true, server: true, freediskspace: false}
  35. - { tag: "intel", dockerfile: ".devops/intel.Dockerfile", platforms: "linux/amd64", full: true, light: true, server: true, freediskspace: false}
  36. - { tag: "vulkan", dockerfile: ".devops/vulkan.Dockerfile", platforms: "linux/amd64", full: true, light: true, server: true, freediskspace: false}
  37. # Note: the rocm images are failing due to a compiler error and are disabled until this is fixed to allow the workflow to complete
  38. #- {tag: "rocm", dockerfile: ".devops/rocm.Dockerfile", platforms: "linux/amd64,linux/arm64", full: true, light: true, server: true, freediskspace: true }
  39. steps:
  40. - name: Check out the repo
  41. uses: actions/checkout@v4
  42. with:
  43. fetch-depth: 0 # preserve git history, so we can determine the build number
  44. - name: Set up QEMU
  45. uses: docker/setup-qemu-action@v3
  46. with:
  47. image: tonistiigi/binfmt:qemu-v7.0.0-28
  48. - name: Set up Docker Buildx
  49. uses: docker/setup-buildx-action@v3
  50. - name: Log in to Docker Hub
  51. uses: docker/login-action@v2
  52. with:
  53. registry: ghcr.io
  54. username: ${{ github.repository_owner }}
  55. password: ${{ secrets.GITHUB_TOKEN }}
  56. - name: Determine tag name
  57. id: tag
  58. shell: bash
  59. run: |
  60. BUILD_NUMBER="$(git rev-list --count HEAD)"
  61. SHORT_HASH="$(git rev-parse --short=7 HEAD)"
  62. REPO_OWNER="${GITHUB_REPOSITORY_OWNER@L}" # to lower case
  63. REPO_NAME="${{ github.event.repository.name }}"
  64. # determine tag name postfix (build number, commit hash)
  65. if [[ "${{ env.GITHUB_BRANCH_NAME }}" == "master" ]]; then
  66. TAG_POSTFIX="-b${BUILD_NUMBER}"
  67. else
  68. SAFE_NAME=$(echo "${{ env.GITHUB_BRANCH_NAME }}" | tr '/' '-')
  69. TAG_POSTFIX="-${SAFE_NAME}-${SHORT_HASH}"
  70. fi
  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}${TAG_POSTFIX}"
  79. LIGHTTAGS="${PREFIX}light${TYPE},${PREFIX}light${TYPE}${TAG_POSTFIX}"
  80. SERVERTAGS="${PREFIX}server${TYPE},${PREFIX}server${TYPE}${TAG_POSTFIX}"
  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_BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
  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