docker.yml 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. paths: ['.github/workflows/docker.yml', '.devops/*.Dockerfile', '**/CMakeLists.txt', '**/Makefile', '**/*.h', '**/*.hpp', '**/*.c', '**/*.cpp', '**/*.cu', '**/*.cuh', '**/*.swift', '**/*.m', '**/*.metal']
  15. concurrency:
  16. group: ${{ github.workflow }}-${{ github.head_ref && github.ref || github.run_id }}
  17. cancel-in-progress: true
  18. jobs:
  19. push_to_registry:
  20. name: Push Docker image to Docker Hub
  21. #if: github.event.pull_request.draft == false
  22. runs-on: ubuntu-latest
  23. env:
  24. COMMIT_SHA: ${{ github.sha }}
  25. strategy:
  26. matrix:
  27. config:
  28. - { tag: "light", dockerfile: ".devops/llama-cli.Dockerfile", platforms: "linux/amd64,linux/arm64" }
  29. - { tag: "server", dockerfile: ".devops/llama-server.Dockerfile", platforms: "linux/amd64,linux/arm64" }
  30. - { tag: "full", dockerfile: ".devops/full.Dockerfile", platforms: "linux/amd64,linux/arm64" }
  31. - { tag: "light-cuda", dockerfile: ".devops/llama-cli-cuda.Dockerfile", platforms: "linux/amd64" }
  32. - { tag: "server-cuda", dockerfile: ".devops/llama-server-cuda.Dockerfile", platforms: "linux/amd64" }
  33. - { tag: "full-cuda", dockerfile: ".devops/full-cuda.Dockerfile", platforms: "linux/amd64" }
  34. - { tag: "light-rocm", dockerfile: ".devops/llama-cli-rocm.Dockerfile", platforms: "linux/amd64,linux/arm64" }
  35. - { tag: "server-rocm", dockerfile: ".devops/llama-server-rocm.Dockerfile", platforms: "linux/amd64,linux/arm64" }
  36. # Note: the full-rocm image is failing due to a "no space left on device" error. It is disabled for now to allow the workflow to complete.
  37. #- { tag: "full-rocm", dockerfile: ".devops/full-rocm.Dockerfile", platforms: "linux/amd64,linux/arm64" }
  38. - { tag: "light-intel", dockerfile: ".devops/llama-cli-intel.Dockerfile", platforms: "linux/amd64" }
  39. - { tag: "server-intel", dockerfile: ".devops/llama-server-intel.Dockerfile", platforms: "linux/amd64" }
  40. steps:
  41. - name: Check out the repo
  42. uses: actions/checkout@v4
  43. - name: Set up QEMU
  44. uses: docker/setup-qemu-action@v2
  45. - name: Set up Docker Buildx
  46. uses: docker/setup-buildx-action@v2
  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. # https://github.com/jlumbroso/free-disk-space/tree/54081f138730dfa15788a46383842cd2f914a1be#example
  54. - name: Free Disk Space (Ubuntu)
  55. uses: jlumbroso/free-disk-space@main
  56. with:
  57. # this might remove tools that are actually needed,
  58. # if set to "true" but frees about 6 GB
  59. tool-cache: false
  60. # all of these default to true, but feel free to set to
  61. # "false" if necessary for your workflow
  62. android: true
  63. dotnet: true
  64. haskell: true
  65. large-packages: true
  66. docker-images: true
  67. swap-storage: true
  68. - name: Determine tag name
  69. id: tag
  70. shell: bash
  71. run: |
  72. BUILD_NUMBER="$(git rev-list --count HEAD)"
  73. SHORT_HASH="$(git rev-parse --short=7 HEAD)"
  74. if [[ "${{ env.BRANCH_NAME }}" == "master" ]]; then
  75. echo "name=b${BUILD_NUMBER}" >> $GITHUB_OUTPUT
  76. else
  77. SAFE_NAME=$(echo "${{ env.BRANCH_NAME }}" | tr '/' '-')
  78. echo "name=${SAFE_NAME}-b${BUILD_NUMBER}-${SHORT_HASH}" >> $GITHUB_OUTPUT
  79. fi
  80. - name: Downcase github.repository_owner
  81. run: |
  82. echo "repository_owner_lowercase=${GITHUB_REPOSITORY_OWNER@L}" >> $GITHUB_ENV
  83. env:
  84. GITHUB_REPOSITORY_OWNER: '${{ github.repository_owner }}'
  85. - name: Build and push Docker image (tagged + versioned)
  86. if: github.event_name == 'push'
  87. uses: docker/build-push-action@v6
  88. with:
  89. context: .
  90. push: true
  91. platforms: ${{ matrix.config.platforms }}
  92. tags: "ghcr.io/${{ env.repository_owner_lowercase }}/llama.cpp:${{ matrix.config.tag }}-${{ env.COMMIT_SHA }},ghcr.io/${{ env.repository_owner_lowercase }}/llama.cpp:${{ matrix.config.tag }},ghcr.io/${{ env.repository_owner_lowercase }}/llama.cpp:${{ matrix.config.tag }}-${{ steps.tag.outputs.name }}"
  93. file: ${{ matrix.config.dockerfile }}