docker.yml 4.8 KB

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