docker.yml 5.6 KB

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