docker.yml 4.6 KB

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