docker.yml 7.7 KB

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