1
0

docker.yml 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. steps:
  34. - name: Check out the repo
  35. uses: actions/checkout@v3
  36. - name: Set up QEMU
  37. uses: docker/setup-qemu-action@v2
  38. - name: Set up Docker Buildx
  39. uses: docker/setup-buildx-action@v2
  40. - name: Log in to Docker Hub
  41. uses: docker/login-action@v2
  42. with:
  43. registry: ghcr.io
  44. username: ${{ github.repository_owner }}
  45. password: ${{ secrets.GITHUB_TOKEN }}
  46. # https://github.com/jlumbroso/free-disk-space/tree/54081f138730dfa15788a46383842cd2f914a1be#example
  47. - name: Free Disk Space (Ubuntu)
  48. uses: jlumbroso/free-disk-space@main
  49. with:
  50. # this might remove tools that are actually needed,
  51. # if set to "true" but frees about 6 GB
  52. tool-cache: false
  53. # all of these default to true, but feel free to set to
  54. # "false" if necessary for your workflow
  55. android: true
  56. dotnet: true
  57. haskell: true
  58. large-packages: true
  59. docker-images: true
  60. swap-storage: true
  61. - name: Determine tag name
  62. id: tag
  63. shell: bash
  64. run: |
  65. BUILD_NUMBER="$(git rev-list --count HEAD)"
  66. SHORT_HASH="$(git rev-parse --short=7 HEAD)"
  67. if [[ "${{ env.BRANCH_NAME }}" == "master" ]]; then
  68. echo "name=b${BUILD_NUMBER}" >> $GITHUB_OUTPUT
  69. else
  70. SAFE_NAME=$(echo "${{ env.BRANCH_NAME }}" | tr '/' '-')
  71. echo "name=${SAFE_NAME}-b${BUILD_NUMBER}-${SHORT_HASH}" >> $GITHUB_OUTPUT
  72. fi
  73. - name: Build and push Docker image (versioned)
  74. if: github.event_name == 'push'
  75. uses: docker/build-push-action@v4
  76. with:
  77. context: .
  78. push: true
  79. platforms: ${{ matrix.config.platforms }}
  80. tags: "ghcr.io/${{ github.repository_owner }}/llama.cpp:${{ matrix.config.tag }}-${{ env.COMMIT_SHA }}"
  81. file: ${{ matrix.config.dockerfile }}
  82. - name: Build and push Docker image (tagged)
  83. uses: docker/build-push-action@v4
  84. with:
  85. context: .
  86. push: ${{ github.event_name == 'push' }}
  87. platforms: ${{ matrix.config.platforms }}
  88. 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 }}"
  89. file: ${{ matrix.config.dockerfile }}