docker.yml 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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-latest
  25. env:
  26. COMMIT_SHA: ${{ github.sha }}
  27. strategy:
  28. matrix:
  29. config:
  30. # Multi-stage build
  31. - { tag: "cpu", dockerfile: ".devops/cpu.Dockerfile", platforms: "linux/amd64,linux/arm64", full: true, light: true, server: true, freediskspace: false}
  32. - { tag: "cuda", dockerfile: ".devops/cuda.Dockerfile", platforms: "linux/amd64", full: true, light: true, server: true, freediskspace: false}
  33. - { tag: "musa", dockerfile: ".devops/musa.Dockerfile", platforms: "linux/amd64", full: true, light: true, server: true, freediskspace: false}
  34. - { tag: "intel", dockerfile: ".devops/intel.Dockerfile", platforms: "linux/amd64", full: true, light: true, server: true, freediskspace: false}
  35. - { tag: "vulkan", dockerfile: ".devops/vulkan.Dockerfile", platforms: "linux/amd64", full: true, light: true, server: true, freediskspace: false}
  36. # Note: the rocm images are failing due to a compiler error and are disabled until this is fixed to allow the workflow to complete
  37. #- {tag: "rocm", dockerfile: ".devops/rocm.Dockerfile", platforms: "linux/amd64,linux/arm64", full: true, light: true, server: true, freediskspace: true }
  38. steps:
  39. - name: Check out the repo
  40. uses: actions/checkout@v4
  41. with:
  42. fetch-depth: 0 # preserve git history, so we can determine the build number
  43. - name: Set up QEMU
  44. uses: docker/setup-qemu-action@v3
  45. - name: Set up Docker Buildx
  46. uses: docker/setup-buildx-action@v3
  47. - name: Log in to Docker Hub
  48. uses: docker/login-action@v2
  49. with:
  50. registry: ghcr.io
  51. username: ${{ github.repository_owner }}
  52. password: ${{ secrets.GITHUB_TOKEN }}
  53. - name: Determine tag name
  54. id: tag
  55. shell: bash
  56. run: |
  57. BUILD_NUMBER="$(git rev-list --count HEAD)"
  58. SHORT_HASH="$(git rev-parse --short=7 HEAD)"
  59. REPO_OWNER="${GITHUB_REPOSITORY_OWNER@L}" # to lower case
  60. REPO_NAME="${{ github.event.repository.name }}"
  61. # determine tag name postfix (build number, commit hash)
  62. if [[ "${{ env.GITHUB_BRANCH_NAME }}" == "master" ]]; then
  63. TAG_POSTFIX="-b${BUILD_NUMBER}"
  64. else
  65. SAFE_NAME=$(echo "${{ env.GITHUB_BRANCH_NAME }}" | tr '/' '-')
  66. TAG_POSTFIX="-${SAFE_NAME}-${SHORT_HASH}"
  67. fi
  68. # list all tags possible
  69. if [[ "${{ matrix.config.tag }}" == "cpu" ]]; then
  70. TYPE=""
  71. else
  72. TYPE="-${{ matrix.config.tag }}"
  73. fi
  74. PREFIX="ghcr.io/${REPO_OWNER}/${REPO_NAME}:"
  75. FULLTAGS="${PREFIX}full${TYPE},${PREFIX}full${TYPE}${TAG_POSTFIX}"
  76. LIGHTTAGS="${PREFIX}light${TYPE},${PREFIX}light${TYPE}${TAG_POSTFIX}"
  77. SERVERTAGS="${PREFIX}server${TYPE},${PREFIX}server${TYPE}${TAG_POSTFIX}"
  78. echo "full_output_tags=$FULLTAGS" >> $GITHUB_OUTPUT
  79. echo "light_output_tags=$LIGHTTAGS" >> $GITHUB_OUTPUT
  80. echo "server_output_tags=$SERVERTAGS" >> $GITHUB_OUTPUT
  81. echo "full_output_tags=$FULLTAGS" # print out for debugging
  82. echo "light_output_tags=$LIGHTTAGS" # print out for debugging
  83. echo "server_output_tags=$SERVERTAGS" # print out for debugging
  84. env:
  85. GITHUB_BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
  86. GITHUB_REPOSITORY_OWNER: '${{ github.repository_owner }}'
  87. - name: Free Disk Space (Ubuntu)
  88. if: ${{ matrix.config.free_disk_space == true }}
  89. uses: ggml-org/free-disk-space@v1.3.1
  90. with:
  91. # this might remove tools that are actually needed,
  92. # if set to "true" but frees about 6 GB
  93. tool-cache: false
  94. # all of these default to true, but feel free to set to
  95. # "false" if necessary for your workflow
  96. android: true
  97. dotnet: true
  98. haskell: true
  99. large-packages: true
  100. docker-images: true
  101. swap-storage: true
  102. - name: Build and push Full Docker image (tagged + versioned)
  103. if: ${{ (github.event_name == 'push' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') && matrix.config.full == true }}
  104. uses: docker/build-push-action@v6
  105. with:
  106. context: .
  107. push: true
  108. platforms: ${{ matrix.config.platforms }}
  109. # tag list is generated from step above
  110. tags: ${{ steps.tag.outputs.full_output_tags }}
  111. file: ${{ matrix.config.dockerfile }}
  112. target: full
  113. provenance: false
  114. # using github experimental cache
  115. cache-from: type=gha
  116. cache-to: type=gha,mode=max
  117. # return to this if the experimental github cache is having issues
  118. #cache-to: type=local,dest=/tmp/.buildx-cache
  119. #cache-from: type=local,src=/tmp/.buildx-cache
  120. - name: Build and push Light Docker image (tagged + versioned)
  121. if: ${{ (github.event_name == 'push' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') && matrix.config.light == true }}
  122. uses: docker/build-push-action@v6
  123. with:
  124. context: .
  125. push: true
  126. platforms: ${{ matrix.config.platforms }}
  127. # tag list is generated from step above
  128. tags: ${{ steps.tag.outputs.light_output_tags }}
  129. file: ${{ matrix.config.dockerfile }}
  130. target: light
  131. provenance: false
  132. # using github experimental cache
  133. cache-from: type=gha
  134. cache-to: type=gha,mode=max
  135. # return to this if the experimental github cache is having issues
  136. #cache-to: type=local,dest=/tmp/.buildx-cache
  137. #cache-from: type=local,src=/tmp/.buildx-cache
  138. - name: Build and push Server Docker image (tagged + versioned)
  139. if: ${{ (github.event_name == 'push' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') && matrix.config.server == true }}
  140. uses: docker/build-push-action@v6
  141. with:
  142. context: .
  143. push: true
  144. platforms: ${{ matrix.config.platforms }}
  145. # tag list is generated from step above
  146. tags: ${{ steps.tag.outputs.server_output_tags }}
  147. file: ${{ matrix.config.dockerfile }}
  148. target: server
  149. provenance: false
  150. # using github experimental cache
  151. cache-from: type=gha
  152. cache-to: type=gha,mode=max
  153. # return to this if the experimental github cache is having issues
  154. #cache-to: type=local,dest=/tmp/.buildx-cache
  155. #cache-from: type=local,src=/tmp/.buildx-cache