|
| 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 | + |
| 6 | +# GitHub recommends pinning actions to a commit SHA. |
| 7 | +# To get a newer version, you will need to update the SHA. |
| 8 | +# You can also reference a tag or branch, but the action may change without warning. |
| 9 | + |
| 10 | +name: Publish Docker image |
| 11 | + |
| 12 | +on: |
| 13 | + #pull_request: |
| 14 | + push: |
| 15 | + branches: |
| 16 | + - master |
| 17 | + paths: ['.github/workflows/docker.yml', '.devops/*.Dockerfile', '**/CMakeLists.txt', '**/Makefile', '**/*.h', '**/*.hpp', '**/*.c', '**/*.cpp', '**/*.cu', '**/*.cuh', '**/*.swift', '**/*.m', '**/*.metal'] |
| 18 | + |
| 19 | +concurrency: |
| 20 | + group: ${{ github.workflow }}-${{ github.head_ref && github.ref || github.run_id }} |
| 21 | + cancel-in-progress: true |
| 22 | + |
| 23 | +jobs: |
| 24 | + push_to_registry: |
| 25 | + name: Push Docker image to Docker Hub |
| 26 | + #if: github.event.pull_request.draft == false |
| 27 | + |
| 28 | + runs-on: ubuntu-latest |
| 29 | + env: |
| 30 | + COMMIT_SHA: ${{ github.sha }} |
| 31 | + strategy: |
| 32 | + matrix: |
| 33 | + config: |
| 34 | + - { tag: "light", dockerfile: ".devops/llama-cli.Dockerfile", platforms: "linux/amd64,linux/arm64" } |
| 35 | + - { tag: "server", dockerfile: ".devops/llama-server.Dockerfile", platforms: "linux/amd64,linux/arm64" } |
| 36 | + - { tag: "full", dockerfile: ".devops/full.Dockerfile", platforms: "linux/amd64,linux/arm64" } |
| 37 | + - { tag: "light-cuda", dockerfile: ".devops/llama-cli-cuda.Dockerfile", platforms: "linux/amd64" } |
| 38 | + - { tag: "server-cuda", dockerfile: ".devops/llama-server-cuda.Dockerfile", platforms: "linux/amd64" } |
| 39 | + - { tag: "full-cuda", dockerfile: ".devops/full-cuda.Dockerfile", platforms: "linux/amd64" } |
| 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 | + # 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. |
| 43 | + #- { tag: "full-rocm", dockerfile: ".devops/full-rocm.Dockerfile", platforms: "linux/amd64,linux/arm64" } |
| 44 | + - { tag: "light-intel", dockerfile: ".devops/llama-cli-intel.Dockerfile", platforms: "linux/amd64" } |
| 45 | + - { tag: "server-intel", dockerfile: ".devops/llama-server-intel.Dockerfile", platforms: "linux/amd64" } |
| 46 | + steps: |
| 47 | + - name: Check out the repo |
| 48 | + uses: actions/checkout@v4 |
| 49 | + |
| 50 | + - name: Set up QEMU |
| 51 | + uses: docker/setup-qemu-action@v2 |
| 52 | + |
| 53 | + - name: Set up Docker Buildx |
| 54 | + uses: docker/setup-buildx-action@v2 |
| 55 | + |
| 56 | + - name: Log in to Docker Hub |
| 57 | + uses: docker/login-action@v2 |
| 58 | + with: |
| 59 | + registry: ghcr.io |
| 60 | + username: ${{ github.repository_owner }} |
| 61 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 62 | + |
| 63 | + # https://github.com/jlumbroso/free-disk-space/tree/54081f138730dfa15788a46383842cd2f914a1be#example |
| 64 | + - name: Free Disk Space (Ubuntu) |
| 65 | + uses: jlumbroso/free-disk-space@main |
| 66 | + with: |
| 67 | + # this might remove tools that are actually needed, |
| 68 | + # if set to "true" but frees about 6 GB |
| 69 | + tool-cache: false |
| 70 | + |
| 71 | + # all of these default to true, but feel free to set to |
| 72 | + # "false" if necessary for your workflow |
| 73 | + android: true |
| 74 | + dotnet: true |
| 75 | + haskell: true |
| 76 | + large-packages: true |
| 77 | + docker-images: true |
| 78 | + swap-storage: true |
| 79 | + |
| 80 | + - name: Determine tag name |
| 81 | + id: tag |
| 82 | + shell: bash |
| 83 | + run: | |
| 84 | + BUILD_NUMBER="$(git rev-list --count HEAD)" |
| 85 | + SHORT_HASH="$(git rev-parse --short=7 HEAD)" |
| 86 | + if [[ "${{ env.BRANCH_NAME }}" == "master" ]]; then |
| 87 | + echo "name=b${BUILD_NUMBER}" >> $GITHUB_OUTPUT |
| 88 | + else |
| 89 | + SAFE_NAME=$(echo "${{ env.BRANCH_NAME }}" | tr '/' '-') |
| 90 | + echo "name=${SAFE_NAME}-b${BUILD_NUMBER}-${SHORT_HASH}" >> $GITHUB_OUTPUT |
| 91 | + fi |
| 92 | +
|
| 93 | + - name: Downcase github.repository_owner |
| 94 | + run: | |
| 95 | + echo "repository_owner_lowercase=${GITHUB_REPOSITORY_OWNER@L}" >> $GITHUB_ENV |
| 96 | + env: |
| 97 | + GITHUB_REPOSITORY_OWNER: '${{ github.repository_owner }}' |
| 98 | + |
| 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 | + 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 }}" |
| 107 | + file: ${{ matrix.config.dockerfile }} |
0 commit comments