Build native artifacts for testing #4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Mostly same as release.yaml but customized for pushing our testing branch to ghcr | |
# instead of main branch to docker hub | |
name: release testing artifacts | |
on: | |
push: | |
branches: | |
- testing | |
workflow_dispatch: | |
permissions: | |
contents: write | |
packages: write | |
jobs: | |
# Full build of the Mac assets | |
build-darwin: | |
runs-on: macos-14 | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set Version | |
shell: bash | |
run: | | |
echo "VERSION=${{ github.sha }}" >> $GITHUB_ENV | |
echo "RELEASE_VERSION=${{ github.sha }}" >> $GITHUB_ENV | |
- uses: actions/setup-go@v5 | |
with: | |
go-version-file: go.mod | |
cache: true | |
- name: Build Darwin | |
env: | |
SDKROOT: /Applications/Xcode_13.4.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk | |
DEVELOPER_DIR: /Applications/Xcode_13.4.1.app/Contents/Developer | |
run: | | |
./scripts/build_darwin.sh | |
- uses: actions/upload-artifact@v4 | |
with: | |
name: dist-darwin | |
path: | | |
dist/*arwin* | |
!dist/*-cov | |
# Linux x86 assets built using the container based build | |
build-linux-amd64: | |
runs-on: ubuntu-latest | |
env: | |
PLATFORM: linux/amd64 | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
submodules: recursive | |
- name: Set Version | |
shell: bash | |
run: echo "VERSION=${{ github.sha }}" >> $GITHUB_ENV | |
- run: | | |
./scripts/build_linux.sh | |
- uses: actions/upload-artifact@v4 | |
with: | |
name: dist-linux-amd64 | |
path: | | |
dist/*linux* | |
!dist/*-cov | |
# Linux ARM assets built using the container based build | |
# (at present, docker isn't pre-installed on arm ubunutu images) | |
build-linux-arm64: | |
runs-on: ollama01 | |
env: | |
PLATFORM: linux/arm64 | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
submodules: recursive | |
- name: Set Version | |
shell: bash | |
run: echo "VERSION=${{ github.sha }}" >> $GITHUB_ENV | |
- name: 'Install Docker' | |
run: | | |
# Add Docker's official GPG key: | |
env | |
uname -a | |
sudo apt-get update | |
sudo apt-get install -y ca-certificates curl | |
sudo install -m 0755 -d /etc/apt/keyrings | |
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc | |
sudo chmod a+r /etc/apt/keyrings/docker.asc | |
# Add the repository to Apt sources: | |
echo \ | |
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \ | |
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \ | |
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null | |
sudo apt-get update | |
sudo apt-get install -y docker-ce docker-ce-cli containerd.io | |
sudo usermod -aG docker $USER | |
sudo apt-get install acl | |
sudo setfacl --modify user:$USER:rw /var/run/docker.sock | |
- run: | | |
./scripts/build_linux.sh | |
- uses: actions/upload-artifact@v4 | |
with: | |
name: dist-linux-arm64 | |
path: | | |
dist/*linux* | |
!dist/*-cov | |
build-container-image: | |
strategy: | |
matrix: | |
runner: | |
- ollama01 # arm64 runner | |
- ubuntu-24.04 | |
runs-on: ${{ matrix.runner }} | |
env: | |
FINAL_IMAGE_REPO: ghcr.io/${{ github.repository }}/ollama | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
submodules: recursive | |
- name: 'Install Docker' | |
if: ${{ matrix.runner == 'ollama01' }} | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y ca-certificates curl | |
sudo install -m 0755 -d /etc/apt/keyrings | |
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc | |
sudo chmod a+r /etc/apt/keyrings/docker.asc | |
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \ | |
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \ | |
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null | |
sudo apt-get update | |
sudo apt-get install -y docker-ce docker-ce-cli containerd.io | |
sudo usermod -aG docker $USER | |
sudo apt-get install acl | |
sudo setfacl --modify user:$USER:rw /var/run/docker.sock | |
- name: Docker meta | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: ${{ env.FINAL_IMAGE_REPO }} | |
flavor: | | |
latest=false | |
tags: | | |
type=ref,event=branch | |
type=sha,format=long | |
- name: Set Version | |
shell: bash | |
run: | | |
machine=$(uname -m) | |
case ${machine} in | |
x86_64) echo ARCH=amd64; echo PLATFORM_PAIR=linux-amd64 ;; | |
aarch64) echo ARCH=arm64; echo PLATFORM_PAIR=linux-arm64 ;; | |
esac >>$GITHUB_ENV | |
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 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to ghcr | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build and push by digest | |
id: build | |
uses: docker/build-push-action@v6 | |
with: | |
context: '.' | |
platforms: linux/${{ env.ARCH }} | |
build-args: | | |
GOFLAGS | |
outputs: type=image,name=${{ env.FINAL_IMAGE_REPO }},push-by-digest=true,name-canonical=true,push=true | |
- name: Export digest | |
run: | | |
mkdir -p /tmp/digests | |
digest="${{ steps.build.outputs.digest }}" | |
touch "/tmp/digests/${digest#sha256:}" | |
- name: Upload digest | |
uses: actions/upload-artifact@v4 | |
with: | |
name: digests-${{ env.PLATFORM_PAIR }} | |
path: /tmp/digests/* | |
if-no-files-found: error | |
retention-days: 1 | |
merge: | |
runs-on: ubuntu-24.04 | |
needs: | |
- build-container-image | |
env: | |
FINAL_IMAGE_REPO: ghcr.io/${{ github.repository }}/ollama | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
submodules: recursive | |
- name: Download digests | |
uses: actions/download-artifact@v4 | |
with: | |
path: /tmp/digests | |
pattern: digests-* | |
merge-multiple: true | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Docker meta | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: ${{ env.FINAL_IMAGE_REPO }} | |
flavor: | | |
latest=false | |
tags: | | |
type=ref,event=branch | |
type=sha,format=long | |
- name: Set Version | |
shell: bash | |
run: | | |
machine=$(uname -m) | |
case ${machine} in | |
x86_64) echo ARCH=amd64; echo PLATFORM_PAIR=linux-amd64 ;; | |
aarch64) echo ARCH=arm64; echo PLATFORM_PAIR=linux-arm64 ;; | |
esac >>$GITHUB_ENV | |
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 | |
- name: Login to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Create manifest list and push | |
working-directory: /tmp/digests | |
run: | | |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ | |
$(printf '${{ env.FINAL_IMAGE_REPO }}@sha256:%s ' *) | |
- name: Inspect image | |
run: | | |
docker buildx imagetools inspect ${{ env.FINAL_IMAGE_REPO }}:${{ steps.meta.outputs.version }} | |
# Aggregate all the assets and ship a release | |
release: | |
needs: | |
- build-darwin | |
- build-linux-amd64 | |
- build-linux-arm64 | |
runs-on: linux | |
permissions: | |
contents: write | |
env: | |
GH_TOKEN: ${{ github.token }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set Version | |
shell: bash | |
run: | | |
echo "VERSION=${{ github.sha }}" >> $GITHUB_ENV | |
echo "RELEASE_VERSION=${{ github.sha }}" >> $GITHUB_ENV | |
- name: Retrieve built artifact | |
uses: actions/download-artifact@v4 | |
with: | |
path: dist | |
pattern: dist-* | |
merge-multiple: true | |
- run: | | |
ls -lh dist/ | |
(cd dist; find . -type f | xargs sha256sum > ../sha256sum.txt) | |
mv sha256sum.txt dist/ | |
cat dist/sha256sum.txt | |
- name: Create or update Release | |
run: | | |
echo "Looking for existing release for ${{ env.RELEASE_VERSION }}" | |
OLD_TAG=$(gh release ls --json name,tagName | jq -r ".[] | select(.name == \"${{ env.RELEASE_VERSION }}\") | .tagName") | |
if [ -n "$OLD_TAG" ]; then | |
echo "Updating release ${{ env.RELEASE_VERSION }} to point to new tag ${{ github.sha }}" | |
gh release edit ${OLD_TAG} --tag ${{ github.sha }} | |
else | |
echo "Creating new release ${{ env.RELEASE_VERSION }} pointing to tag ${{ github.sha }}" | |
gh release create ${{ github.sha }} \ | |
--title ${{ env.RELEASE_VERSION }} \ | |
--draft \ | |
--generate-notes \ | |
--prerelease | |
fi | |
echo "Uploading artifacts for tag ${{ github.sha }}" | |
gh release upload ${{ github.sha }} dist/* --clobber |