1
0

docker.yml 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. workflow_dispatch: # allows manual triggering, useful for debugging
  16. concurrency:
  17. group: ${{ github.workflow }}-${{ github.head_ref && github.ref || github.run_id }}
  18. cancel-in-progress: true
  19. # Fine-grant permission
  20. # https://docs.github.com/en/actions/security-for-github-actions/security-guides/automatic-token-authentication#modifying-the-permissions-for-the-github_token
  21. permissions:
  22. packages: write
  23. jobs:
  24. push_to_registry:
  25. name: Push Docker image to Docker Hub
  26. #if: github.event.pull_request.draft == false
  27. runs-on: ubuntu-latest
  28. env:
  29. COMMIT_SHA: ${{ github.sha }}
  30. strategy:
  31. matrix:
  32. config:
  33. - { tag: "light", dockerfile: ".devops/llama-cli.Dockerfile", platforms: "linux/amd64,linux/arm64" }
  34. - { tag: "server", dockerfile: ".devops/llama-server.Dockerfile", platforms: "linux/amd64,linux/arm64" }
  35. - { tag: "full", dockerfile: ".devops/full.Dockerfile", platforms: "linux/amd64,linux/arm64" }
  36. - { tag: "light-cuda", dockerfile: ".devops/llama-cli-cuda.Dockerfile", platforms: "linux/amd64" }
  37. - { tag: "server-cuda", dockerfile: ".devops/llama-server-cuda.Dockerfile", platforms: "linux/amd64" }
  38. - { tag: "full-cuda", dockerfile: ".devops/full-cuda.Dockerfile", platforms: "linux/amd64" }
  39. # Note: the rocm images are failing due to a compiler error and are disabled until this is fixed to allow the workflow to complete
  40. #- { tag: "light-rocm", dockerfile: ".devops/llama-cli-rocm.Dockerfile", platforms: "linux/amd64,linux/arm64" }
  41. #- { tag: "server-rocm", dockerfile: ".devops/llama-server-rocm.Dockerfile", platforms: "linux/amd64,linux/arm64" }
  42. #- { tag: "full-rocm", dockerfile: ".devops/full-rocm.Dockerfile", platforms: "linux/amd64,linux/arm64" }
  43. - { tag: "light-intel", dockerfile: ".devops/llama-cli-intel.Dockerfile", platforms: "linux/amd64" }
  44. - { tag: "server-intel", dockerfile: ".devops/llama-server-intel.Dockerfile", platforms: "linux/amd64" }
  45. steps:
  46. - name: Check out the repo
  47. uses: actions/checkout@v4
  48. with:
  49. fetch-depth: 0 # preserve git history, so we can determine the build number
  50. - name: Set up QEMU
  51. uses: docker/setup-qemu-action@v2
  52. - name: Set up Docker Buildx
  53. uses: docker/setup-buildx-action@v2
  54. - name: Log in to Docker Hub
  55. uses: docker/login-action@v2
  56. with:
  57. registry: ghcr.io
  58. username: ${{ github.repository_owner }}
  59. password: ${{ secrets.GITHUB_TOKEN }}
  60. - name: Determine tag name
  61. id: tag
  62. shell: bash
  63. run: |
  64. BUILD_NUMBER="$(git rev-list --count HEAD)"
  65. SHORT_HASH="$(git rev-parse --short=7 HEAD)"
  66. REPO_OWNER="${GITHUB_REPOSITORY_OWNER@L}" # to lower case
  67. REPO_NAME="${{ github.event.repository.name }}"
  68. # determine tag name postfix (build number, commit hash)
  69. if [[ "${{ env.GITHUB_BRANCH_NAME }}" == "master" ]]; then
  70. TAG_POSTFIX="b${BUILD_NUMBER}"
  71. else
  72. SAFE_NAME=$(echo "${{ env.GITHUB_BRANCH_NAME }}" | tr '/' '-')
  73. TAG_POSTFIX="${SAFE_NAME}-${SHORT_HASH}"
  74. fi
  75. # list all tags possible
  76. TAGS=""
  77. TAGS="${TAGS}ghcr.io/${REPO_OWNER}/${REPO_NAME}:${{ matrix.config.tag }},"
  78. TAGS="${TAGS}ghcr.io/${REPO_OWNER}/${REPO_NAME}:${{ matrix.config.tag }}-${TAG_POSTFIX}"
  79. echo "output_tags=$TAGS" >> $GITHUB_OUTPUT
  80. echo "output_tags=$TAGS" # print out for debugging
  81. env:
  82. GITHUB_BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
  83. GITHUB_REPOSITORY_OWNER: '${{ github.repository_owner }}'
  84. # https://github.com/jlumbroso/free-disk-space/tree/54081f138730dfa15788a46383842cd2f914a1be#example
  85. - name: Free Disk Space (Ubuntu)
  86. uses: jlumbroso/free-disk-space@main
  87. with:
  88. # this might remove tools that are actually needed,
  89. # if set to "true" but frees about 6 GB
  90. tool-cache: false
  91. # all of these default to true, but feel free to set to
  92. # "false" if necessary for your workflow
  93. android: true
  94. dotnet: true
  95. haskell: true
  96. large-packages: true
  97. docker-images: true
  98. swap-storage: true
  99. - name: Build and push Docker image (tagged + versioned)
  100. if: github.event_name == 'push'
  101. uses: docker/build-push-action@v6
  102. with:
  103. context: .
  104. push: true
  105. platforms: ${{ matrix.config.platforms }}
  106. # tag list is generated from step above
  107. tags: ${{ steps.tag.outputs.output_tags }}
  108. file: ${{ matrix.config.dockerfile }}