echodict/llama.cpp
version https://git-lfs.github.com/spec/v1 oid sha256:cfc44b7ba25614df70e6b65e3341cae0310163bd32fd31a6b928a542df433faf size 30786
0773
1# This workflow uses actions that are not certified by GitHub.2# They are provided by a third-party and are governed by3# separate terms of service, privacy policy, and support4# 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 10name: Publish Docker image11 12on:13 workflow_dispatch: # allows manual triggering14 schedule:15 # Rebuild daily rather than on every push because it is expensive16 - cron: '12 4 * * *'17 18concurrency:19 group: ${{ github.workflow }}-${{ github.head_ref && github.ref || github.run_id }}20 cancel-in-progress: true21 22# Fine-grant permission23# https://docs.github.com/en/actions/security-for-github-actions/security-guides/automatic-token-authentication#modifying-the-permissions-for-the-github_token24permissions:25 packages: write26 27jobs:28 create_tag:29 name: Create and push git tag30 runs-on: ubuntu-slim31 permissions:32 contents: write33 outputs:34 source_tag: ${{ steps.srctag.outputs.name }}35 36 steps:37 - name: Clone38 id: checkout39 uses: actions/checkout@v640 with:41 fetch-depth: 042 43 - name: Determine source tag name44 id: srctag45 uses: ./.github/actions/get-tag-name46 env:47 BRANCH_NAME: ${{ github.head_ref || github.ref_name }}48 49 - name: Create and push git tag50 env:51 GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}52 run: |53 git tag ${{ steps.srctag.outputs.name }} || exit 054 git push origin ${{ steps.srctag.outputs.name }} || exit 055 56 prepare_matrices:57 name: Prepare Docker matrices58 runs-on: ubuntu-24.0459 outputs:60 build_matrix: ${{ steps.matrices.outputs.build_matrix }}61 merge_matrix: ${{ steps.matrices.outputs.merge_matrix }}62 63 steps:64 - name: Generate build and merge matrices65 id: matrices66 shell: bash67 run: |68 set -euo pipefail69 70 # Keep all build targets in one place and derive merge targets from it.71 cat > build-matrix.json <<'JSON'72 [73 { "tag": "cpu", "dockerfile": ".devops/cpu.Dockerfile", "platforms": "linux/amd64", "full": true, "light": true, "server": true, "free_disk_space": false, "runs_on": "ubuntu-24.04" },74 { "tag": "cpu", "dockerfile": ".devops/cpu.Dockerfile", "platforms": "linux/arm64", "full": true, "light": true, "server": true, "free_disk_space": false, "runs_on": "ubuntu-24.04-arm" },75 { "tag": "cpu", "dockerfile": ".devops/s390x.Dockerfile", "platforms": "linux/s390x", "full": true, "light": true, "server": true, "free_disk_space": false, "runs_on": "ubuntu-24.04-s390x" },76 { "tag": "cuda cuda12", "dockerfile": ".devops/cuda.Dockerfile", "cuda_version": "12.8.1", "platforms": "linux/amd64", "full": true, "light": true, "server": true, "free_disk_space": true, "runs_on": "ubuntu-24.04" },77 { "tag": "cuda cuda12", "dockerfile": ".devops/cuda.Dockerfile", "cuda_version": "12.8.1", "platforms": "linux/arm64", "full": true, "light": true, "server": true, "free_disk_space": true, "runs_on": "ubuntu-24.04-arm" },78 { "tag": "cuda13", "dockerfile": ".devops/cuda.Dockerfile", "cuda_version": "13.1.1", "platforms": "linux/amd64", "full": true, "light": true, "server": true, "free_disk_space": true, "runs_on": "ubuntu-24.04" },79 { "tag": "cuda13", "dockerfile": ".devops/cuda.Dockerfile", "cuda_version": "13.1.1", "platforms": "linux/arm64", "full": true, "light": true, "server": true, "free_disk_space": true, "runs_on": "ubuntu-24.04-arm" },80 { "tag": "musa", "dockerfile": ".devops/musa.Dockerfile", "platforms": "linux/amd64", "full": true, "light": true, "server": true, "free_disk_space": true, "runs_on": "ubuntu-24.04" },81 { "tag": "intel", "dockerfile": ".devops/intel.Dockerfile", "platforms": "linux/amd64", "full": true, "light": true, "server": true, "free_disk_space": true, "runs_on": "ubuntu-24.04" },82 { "tag": "vulkan", "dockerfile": ".devops/vulkan.Dockerfile", "platforms": "linux/amd64", "full": true, "light": true, "server": true, "free_disk_space": false, "runs_on": "ubuntu-24.04" },83 { "tag": "vulkan", "dockerfile": ".devops/vulkan.Dockerfile", "platforms": "linux/arm64", "full": true, "light": true, "server": true, "free_disk_space": false, "runs_on": "ubuntu-24.04-arm" },84 { "tag": "rocm", "dockerfile": ".devops/rocm.Dockerfile", "platforms": "linux/amd64", "full": true, "light": true, "server": true, "free_disk_space": true, "runs_on": "ubuntu-24.04" },85 { "tag": "openvino", "dockerfile": ".devops/openvino.Dockerfile", "platforms": "linux/amd64", "full": true, "light": true, "server": true, "free_disk_space": false, "runs_on": "ubuntu-24.04" }86 ]87 JSON88 89 BUILD_MATRIX="$(jq -c . build-matrix.json)"90 MERGE_MATRIX="$(jq -c '91 reduce .[] as $entry ({}; .[$entry.tag] |= (92 . // {93 tag: $entry.tag,94 arches: [],95 full: false,96 light: false,97 server: false98 }99 | .full = (.full or ($entry.full // false))100 | .light = (.light or ($entry.light // false))101 | .server = (.server or ($entry.server // false))102 | .arches += [($entry.platforms | sub("^linux/"; ""))]103 ))104 # Backward compatibility: s390x tags are aliases of cpu for the linux/s390x platform.105 | if (has("cpu") and (((.cpu.arches // []) | index("s390x")) != null)) then106 . + {107 s390x: {108 tag: "s390x",109 arches: ["s390x"],110 full: .cpu.full,111 light: .cpu.light,112 server: .cpu.server113 }114 }115 else116 .117 end118 | [.[] | .arches = (.arches | unique | sort | join(" "))]119 ' build-matrix.json)"120 121 echo "build_matrix=$BUILD_MATRIX" >> "$GITHUB_OUTPUT"122 echo "merge_matrix=$MERGE_MATRIX" >> "$GITHUB_OUTPUT"123 124 push_to_registry:125 name: Push Docker image to Docker Registry126 needs: [prepare_matrices, create_tag]127 128 runs-on: ${{ matrix.config.runs_on }}129 strategy:130 fail-fast: false131 matrix:132 config: ${{ fromJSON(needs.prepare_matrices.outputs.build_matrix) }}133 steps:134 - name: Check out the repo135 uses: actions/checkout@v6136 with:137 fetch-depth: 0138 ref: ${{ needs.create_tag.outputs.source_tag }}139 140 - name: Set up QEMU141 if: ${{ contains(matrix.config.platforms, 'linux/amd64') }}142 uses: docker/setup-qemu-action@ce360397dd3f832beb865e1373c09c0e9f86d70a # v4143 with:144 image: tonistiigi/binfmt:qemu-v10.2.1145 146 - name: Set up Docker Buildx147 uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4148 149 - name: Log in to Docker Registry150 uses: docker/login-action@b45d80f862d83dbcd57f89517bcf500b2ab88fb2 # v4151 with:152 registry: ghcr.io153 username: ${{ github.repository_owner }}154 password: ${{ secrets.GITHUB_TOKEN }}155 156 - name: Determine image metadata157 id: meta158 shell: bash159 run: |160 set -euo pipefail161 162 REPO_OWNER="${GITHUB_REPOSITORY_OWNER@L}" # to lower case163 REPO_NAME="${{ github.event.repository.name }}"164 IMAGE_REPO="ghcr.io/${REPO_OWNER}/${REPO_NAME}"165 PREFIX="${IMAGE_REPO}:"166 PLATFORM="${{ matrix.config.platforms }}"167 ARCH_SUFFIX="${PLATFORM#linux/}"168 169 # list all tags possible170 tags="${{ matrix.config.tag }}"171 for tag in $tags; do172 if [[ "$tag" == "cpu" ]]; then173 TYPE=""174 else175 TYPE="-$tag"176 fi177 CACHETAG="${PREFIX}buildcache${TYPE}-${ARCH_SUFFIX}"178 done179 180 SAFE_TAGS="$(echo "$tags" | tr ' ' '_')"181 182 echo "image_repo=$IMAGE_REPO" >> $GITHUB_OUTPUT183 echo "arch_suffix=$ARCH_SUFFIX" >> $GITHUB_OUTPUT184 echo "cache_output_tag=$CACHETAG" >> $GITHUB_OUTPUT185 echo "digest_artifact_suffix=${SAFE_TAGS}-${ARCH_SUFFIX}" >> $GITHUB_OUTPUT186 echo "cache_output_tag=$CACHETAG" # print out for debugging187 env:188 GITHUB_REPOSITORY_OWNER: '${{ github.repository_owner }}'189 190 - name: Free Disk Space (Ubuntu)191 if: ${{ matrix.config.free_disk_space == true }}192 uses: ggml-org/free-disk-space@v1.3.1193 with:194 # this might remove tools that are actually needed,195 # if set to "true" but frees about 6 GB196 tool-cache: false197 198 # all of these default to true, but feel free to set to199 # "false" if necessary for your workflow200 android: true201 dotnet: true202 haskell: true203 large-packages: true204 docker-images: true205 swap-storage: true206 207 - name: Build and push Full Docker image by digest208 id: build_full209 if: ${{ (github.event_name == 'push' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') && matrix.config.full == true }}210 uses: docker/build-push-action@d08e5c354a6adb9ed34480a06d141179aa583294 # v7211 with:212 context: .213 platforms: ${{ matrix.config.platforms }}214 outputs: type=image,name=${{ steps.meta.outputs.image_repo }},push-by-digest=true,name-canonical=true,push=true215 file: ${{ matrix.config.dockerfile }}216 target: full217 provenance: false218 build-args: |219 ${{ matrix.config.ubuntu_version && format('UBUNTU_VERSION={0}', matrix.config.ubuntu_version) || '' }}220 ${{ matrix.config.cuda_version && format('CUDA_VERSION={0}', matrix.config.cuda_version) || '' }}221 # using github experimental cache222 #cache-from: type=gha223 #cache-to: type=gha,mode=max224 # return to this if the experimental github cache is having issues225 #cache-to: type=local,dest=/tmp/.buildx-cache226 #cache-from: type=local,src=/tmp/.buildx-cache227 # using registry cache (no storage limit)228 cache-from: type=registry,ref=${{ steps.meta.outputs.cache_output_tag }}229 cache-to: type=registry,ref=${{ steps.meta.outputs.cache_output_tag }},mode=max230 231 - name: Build and push Light Docker image by digest232 id: build_light233 if: ${{ (github.event_name == 'push' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') && matrix.config.light == true }}234 uses: docker/build-push-action@d08e5c354a6adb9ed34480a06d141179aa583294 # v7235 with:236 context: .237 platforms: ${{ matrix.config.platforms }}238 outputs: type=image,name=${{ steps.meta.outputs.image_repo }},push-by-digest=true,name-canonical=true,push=true239 file: ${{ matrix.config.dockerfile }}240 target: light241 provenance: false242 build-args: |243 ${{ matrix.config.ubuntu_version && format('UBUNTU_VERSION={0}', matrix.config.ubuntu_version) || '' }}244 ${{ matrix.config.cuda_version && format('CUDA_VERSION={0}', matrix.config.cuda_version) || '' }}245 # using github experimental cache246 #cache-from: type=gha247 #cache-to: type=gha,mode=max248 # return to this if the experimental github cache is having issues249 #cache-to: type=local,dest=/tmp/.buildx-cache250 #cache-from: type=local,src=/tmp/.buildx-cache251 # using registry cache (no storage limit)252 cache-from: type=registry,ref=${{ steps.meta.outputs.cache_output_tag }}253 cache-to: type=registry,ref=${{ steps.meta.outputs.cache_output_tag }},mode=max254 255 - name: Build and push Server Docker image by digest256 id: build_server257 if: ${{ (github.event_name == 'push' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') && matrix.config.server == true }}258 uses: docker/build-push-action@d08e5c354a6adb9ed34480a06d141179aa583294 # v7259 with:260 context: .261 platforms: ${{ matrix.config.platforms }}262 outputs: type=image,name=${{ steps.meta.outputs.image_repo }},push-by-digest=true,name-canonical=true,push=true263 file: ${{ matrix.config.dockerfile }}264 target: server265 provenance: false266 build-args: |267 ${{ matrix.config.ubuntu_version && format('UBUNTU_VERSION={0}', matrix.config.ubuntu_version) || '' }}268 ${{ matrix.config.cuda_version && format('CUDA_VERSION={0}', matrix.config.cuda_version) || '' }}269 # using github experimental cache270 #cache-from: type=gha271 #cache-to: type=gha,mode=max272 # return to this if the experimental github cache is having issues273 #cache-to: type=local,dest=/tmp/.buildx-cache274 #cache-from: type=local,src=/tmp/.buildx-cache275 # using registry cache (no storage limit)276 cache-from: type=registry,ref=${{ steps.meta.outputs.cache_output_tag }}277 cache-to: type=registry,ref=${{ steps.meta.outputs.cache_output_tag }},mode=max278 279 - name: Export digest metadata280 shell: bash281 run: |282 set -euo pipefail283 284 TAGS="${{ matrix.config.tag }}"285 ARCH_SUFFIX="${{ steps.meta.outputs.arch_suffix }}"286 DIGEST_FILE="/tmp/digests/${{ steps.meta.outputs.digest_artifact_suffix }}.tsv"287 mkdir -p /tmp/digests288 289 add_digest_rows() {290 local image_type="$1"291 local digest="$2"292 293 if [[ -z "$digest" ]]; then294 echo "Missing digest for image_type=${image_type}" >&2295 exit 1296 fi297 298 for tag in $TAGS; do299 printf '%s\t%s\t%s\t%s\n' "$tag" "$ARCH_SUFFIX" "$image_type" "$digest" >> "$DIGEST_FILE"300 done301 }302 303 if [[ "${{ matrix.config.full }}" == "true" ]]; then304 add_digest_rows "full" "${{ steps.build_full.outputs.digest }}"305 fi306 307 if [[ "${{ matrix.config.light }}" == "true" ]]; then308 add_digest_rows "light" "${{ steps.build_light.outputs.digest }}"309 fi310 311 if [[ "${{ matrix.config.server }}" == "true" ]]; then312 add_digest_rows "server" "${{ steps.build_server.outputs.digest }}"313 fi314 315 - name: Upload digest metadata316 uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7317 with:318 name: digests-${{ steps.meta.outputs.digest_artifact_suffix }}319 path: /tmp/digests/${{ steps.meta.outputs.digest_artifact_suffix }}.tsv320 if-no-files-found: error321 322 merge_arch_tags:323 name: Create shared tags from digests324 needs: [prepare_matrices, push_to_registry, create_tag]325 runs-on: ubuntu-24.04326 strategy:327 fail-fast: false328 matrix:329 config: ${{ fromJSON(needs.prepare_matrices.outputs.merge_matrix) }}330 331 steps:332 - name: Check out the repo333 uses: actions/checkout@v6334 with:335 fetch-depth: 0336 337 - name: Download digest metadata338 uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8339 with:340 pattern: digests-*341 path: /tmp/digests342 merge-multiple: true343 344 - name: Set up Docker Buildx345 uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4346 347 - name: Log in to Docker Registry348 uses: docker/login-action@b45d80f862d83dbcd57f89517bcf500b2ab88fb2 # v4349 with:350 registry: ghcr.io351 username: ${{ github.repository_owner }}352 password: ${{ secrets.GITHUB_TOKEN }}353 354 - name: Create tags from digests355 shell: bash356 run: |357 set -euo pipefail358 359 REPO_OWNER="${GITHUB_REPOSITORY_OWNER@L}" # to lower case360 REPO_NAME="${{ github.event.repository.name }}"361 IMAGE_REPO="ghcr.io/${REPO_OWNER}/${REPO_NAME}"362 PREFIX="${IMAGE_REPO}:"363 SRC_TAG="${{ needs.create_tag.outputs.source_tag }}"364 TAGS="${{ matrix.config.tag }}"365 ARCHES="${{ matrix.config.arches }}"366 DIGEST_GLOB="/tmp/digests/*.tsv"367 368 if ! ls ${DIGEST_GLOB} >/dev/null 2>&1; then369 echo "No digest metadata found in /tmp/digests" >&2370 exit 1371 fi372 373 if [[ -z "$SRC_TAG" ]]; then374 echo "Missing source tag from create_tag" >&2375 exit 1376 fi377 378 find_digest() {379 local tag_name="$1"380 local arch="$2"381 local image_type="$3"382 local digest383 384 digest="$(awk -F '\t' -v t="$tag_name" -v a="$arch" -v i="$image_type" '$1 == t && $2 == a && $3 == i { print $4; exit }' ${DIGEST_GLOB})"385 386 # Backward compatibility: s390x tags are aliases of cpu for the linux/s390x platform.387 if [[ -z "$digest" && "$tag_name" == "s390x" && "$arch" == "s390x" ]]; then388 digest="$(awk -F '\t' -v t="cpu" -v a="$arch" -v i="$image_type" '$1 == t && $2 == a && $3 == i { print $4; exit }' ${DIGEST_GLOB})"389 fi390 391 if [[ -z "$digest" ]]; then392 echo "Missing digest for tag=${tag_name} arch=${arch} image_type=${image_type}" >&2393 exit 1394 fi395 396 echo "$digest"397 }398 399 create_manifest_tags() {400 local image_type="$1"401 local tag_name="$2"402 local suffix="$3"403 404 local merged_tag="${PREFIX}${image_type}${suffix}"405 local merged_versioned_tag="${merged_tag}-${SRC_TAG}"406 407 local refs=()408 409 for arch in $ARCHES; do410 local digest411 digest="$(find_digest "$tag_name" "$arch" "$image_type")"412 refs+=("${IMAGE_REPO}@${digest}")413 done414 415 echo "Creating ${merged_tag} from ${refs[*]}"416 docker buildx imagetools create --tag "${merged_tag}" "${refs[@]}"417 418 echo "Creating ${merged_versioned_tag} from ${refs[*]}"419 docker buildx imagetools create --tag "${merged_versioned_tag}" "${refs[@]}"420 }421 422 for tag in $TAGS; do423 if [[ "$tag" == "cpu" ]]; then424 TYPE=""425 else426 TYPE="-$tag"427 fi428 429 if [[ "${{ matrix.config.full }}" == "true" ]]; then430 create_manifest_tags "full" "$tag" "$TYPE"431 fi432 433 if [[ "${{ matrix.config.light }}" == "true" ]]; then434 create_manifest_tags "light" "$tag" "$TYPE"435 fi436 437 if [[ "${{ matrix.config.server }}" == "true" ]]; then438 create_manifest_tags "server" "$tag" "$TYPE"439 fi440 done441 env:442 GITHUB_REPOSITORY_OWNER: '${{ github.repository_owner }}'443 