Skip to content

Commit 34d6cf7

Browse files
authored
Add workflow to push a testing Docker image for amd64 (#3)
1 parent a1c7b2f commit 34d6cf7

File tree

1 file changed

+128
-0
lines changed

1 file changed

+128
-0
lines changed
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
name: release testing artifacts
2+
3+
on:
4+
push:
5+
branches:
6+
# Branch that we merge proposed changes to for internal testing.
7+
- testing
8+
workflow_dispatch:
9+
10+
permissions:
11+
contents: read
12+
packages: write
13+
14+
jobs:
15+
build-container-image:
16+
strategy:
17+
matrix:
18+
# Need a real arm64 runner to build llama.cpp since cross-compilation
19+
# and emulation aren't practical for it.
20+
# TODO: Add arm64 runner
21+
runner:
22+
- ubuntu-24.04
23+
runs-on: ${{ matrix.runner }}
24+
env:
25+
FINAL_IMAGE_REPO: ghcr.io/${{ github.repository }}/ollama
26+
steps:
27+
- uses: actions/checkout@v4
28+
with:
29+
submodules: recursive
30+
- name: Docker meta
31+
id: meta
32+
uses: docker/metadata-action@v5
33+
with:
34+
images: ${{ env.FINAL_IMAGE_REPO }}
35+
flavor: |
36+
latest=false
37+
tags: |
38+
type=ref
39+
type=sha,format=long
40+
- name: Set Version
41+
shell: bash
42+
run: |
43+
machine=$(uname -m)
44+
case ${machine} in
45+
x86_64) echo ARCH=amd64; echo PLATFORM_PAIR=linux-amd64 ;;
46+
aarch64) echo ARCH=arm64; echo PLATFORM_PAIR=linux-arm64 ;;
47+
esac >>$GITHUB_ENV
48+
echo GOFLAGS="'-ldflags=-w -s \"-X=github.com/ollama/ollama/version.Version=${{ env.DOCKER_METADATA_OUTPUT_VERSION }}\" \"-X=github.com/ollama/ollama/server.mode=release\"'" >>$GITHUB_ENV
49+
- name: Set up Docker Buildx
50+
uses: docker/setup-buildx-action@v3
51+
- name: Login to Docker Hub
52+
uses: docker/login-action@v3
53+
with:
54+
registry: ghcr.io
55+
username: ${{ github.actor }}
56+
password: ${{ secrets.GITHUB_TOKEN }}
57+
- name: Build and push by digest
58+
id: build
59+
uses: docker/build-push-action@v6
60+
with:
61+
context: '.'
62+
platforms: linux/${{ env.ARCH }}
63+
build-args: |
64+
GOFLAGS
65+
outputs: type=image,name=${{ env.FINAL_IMAGE_REPO }},push-by-digest=true,name-canonical=true,push=true
66+
- name: Export digest
67+
run: |
68+
mkdir -p /tmp/digests
69+
digest="${{ steps.build.outputs.digest }}"
70+
touch "/tmp/digests/${digest#sha256:}"
71+
- name: Upload digest
72+
uses: actions/upload-artifact@v4
73+
with:
74+
name: digests-${{ env.PLATFORM_PAIR }}
75+
path: /tmp/digests/*
76+
if-no-files-found: error
77+
retention-days: 1
78+
merge:
79+
runs-on: ubuntu-24.04
80+
needs:
81+
- build-container-image
82+
env:
83+
FINAL_IMAGE_REPO: ghcr.io/${{ github.repository }}/ollama
84+
steps:
85+
- uses: actions/checkout@v4
86+
with:
87+
submodules: recursive
88+
- name: Download digests
89+
uses: actions/download-artifact@v4
90+
with:
91+
path: /tmp/digests
92+
pattern: digests-*
93+
merge-multiple: true
94+
- name: Set up Docker Buildx
95+
uses: docker/setup-buildx-action@v3
96+
- name: Docker meta
97+
id: meta
98+
uses: docker/metadata-action@v5
99+
with:
100+
images: ${{ env.FINAL_IMAGE_REPO }}
101+
flavor: |
102+
latest=false
103+
tags: |
104+
type=ref
105+
type=sha,format=long
106+
- name: Set Version
107+
shell: bash
108+
run: |
109+
machine=$(uname -m)
110+
case ${machine} in
111+
x86_64) echo ARCH=amd64; echo PLATFORM_PAIR=linux-amd64 ;;
112+
aarch64) echo ARCH=arm64; echo PLATFORM_PAIR=linux-arm64 ;;
113+
esac >>$GITHUB_ENV
114+
echo GOFLAGS="'-ldflags=-w -s \"-X=github.com/ollama/ollama/version.Version=${{ env.DOCKER_METADATA_OUTPUT_VERSION }}\" \"-X=github.com/ollama/ollama/server.mode=release\"'" >>$GITHUB_ENV
115+
- name: Login to Docker Hub
116+
uses: docker/login-action@v3
117+
with:
118+
registry: ghcr.io
119+
username: ${{ github.actor }}
120+
password: ${{ secrets.GITHUB_TOKEN }}
121+
- name: Create manifest list and push
122+
working-directory: /tmp/digests
123+
run: |
124+
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
125+
$(printf '${{ env.FINAL_IMAGE_REPO }}@sha256:%s ' *)
126+
- name: Inspect image
127+
run: |
128+
docker buildx imagetools inspect ${{ env.FINAL_IMAGE_REPO }}:${{ steps.meta.outputs.version }}

0 commit comments

Comments
 (0)