1
0

docker.yml 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. pull_request:
  11. push:
  12. branches:
  13. - master
  14. jobs:
  15. push_to_registry:
  16. name: Push Docker image to Docker Hub
  17. if: github.event.pull_request.draft == false
  18. runs-on: ubuntu-latest
  19. env:
  20. COMMIT_SHA: ${{ github.sha }}
  21. strategy:
  22. matrix:
  23. config:
  24. - { tag: "light", dockerfile: ".devops/main.Dockerfile", platforms: "linux/amd64,linux/arm64" }
  25. - { tag: "full", dockerfile: ".devops/full.Dockerfile", platforms: "linux/amd64,linux/arm64" }
  26. # NOTE(canardletter): The CUDA builds on arm64 are very slow, so I
  27. # have disabled them for now until the reason why
  28. # is understood.
  29. - { tag: "light-cuda", dockerfile: ".devops/main-cuda.Dockerfile", platforms: "linux/amd64" }
  30. - { tag: "full-cuda", dockerfile: ".devops/full-cuda.Dockerfile", platforms: "linux/amd64" }
  31. - { tag: "light-rocm", dockerfile: ".devops/main-rocm.Dockerfile", platforms: "linux/amd64,linux/arm64" }
  32. - { tag: "full-rocm", dockerfile: ".devops/full-rocm.Dockerfile", platforms: "linux/amd64,linux/arm64" }
  33. - { tag: "light-intel", dockerfile: ".devops/main-intel.Dockerfile", platforms: "linux/amd64" }
  34. steps:
  35. - name: Check out the repo
  36. uses: actions/checkout@v3
  37. - name: Set up QEMU
  38. uses: docker/setup-qemu-action@v2
  39. - name: Set up Docker Buildx
  40. uses: docker/setup-buildx-action@v2
  41. - name: Log in to Docker Hub
  42. uses: docker/login-action@v2
  43. with:
  44. registry: ghcr.io
  45. username: ${{ github.repository_owner }}
  46. password: ${{ secrets.GITHUB_TOKEN }}
  47. # https://github.com/jlumbroso/free-disk-space/tree/54081f138730dfa15788a46383842cd2f914a1be#example
  48. - name: Free Disk Space (Ubuntu)
  49. uses: jlumbroso/free-disk-space@main
  50. with:
  51. # this might remove tools that are actually needed,
  52. # if set to "true" but frees about 6 GB
  53. tool-cache: false
  54. # all of these default to true, but feel free to set to
  55. # "false" if necessary for your workflow
  56. android: true
  57. dotnet: true
  58. haskell: true
  59. large-packages: true
  60. docker-images: true
  61. swap-storage: true
  62. - name: Determine tag name
  63. id: tag
  64. shell: bash
  65. run: |
  66. BUILD_NUMBER="$(git rev-list --count HEAD)"
  67. SHORT_HASH="$(git rev-parse --short=7 HEAD)"
  68. if [[ "${{ env.BRANCH_NAME }}" == "master" ]]; then
  69. echo "name=b${BUILD_NUMBER}" >> $GITHUB_OUTPUT
  70. else
  71. SAFE_NAME=$(echo "${{ env.BRANCH_NAME }}" | tr '/' '-')
  72. echo "name=${SAFE_NAME}-b${BUILD_NUMBER}-${SHORT_HASH}" >> $GITHUB_OUTPUT
  73. fi
  74. - name: Build and push Docker image (versioned)
  75. if: github.event_name == 'push'
  76. uses: docker/build-push-action@v4
  77. with:
  78. context: .
  79. push: true
  80. platforms: ${{ matrix.config.platforms }}
  81. tags: "ghcr.io/${{ github.repository_owner }}/llama.cpp:${{ matrix.config.tag }}-${{ env.COMMIT_SHA }}"
  82. file: ${{ matrix.config.dockerfile }}
  83. - name: Build and push Docker image (tagged)
  84. uses: docker/build-push-action@v4
  85. with:
  86. context: .
  87. push: ${{ github.event_name == 'push' }}
  88. platforms: ${{ matrix.config.platforms }}
  89. tags: "ghcr.io/${{ github.repository_owner }}/llama.cpp:${{ matrix.config.tag }},ghcr.io/${{ github.repository_owner }}/llama.cpp:${{ matrix.config.tag }}-${{ steps.tag.outputs.name }}"
  90. file: ${{ matrix.config.dockerfile }}