From bc1517b04830402b481f53a6d2cd2e8e63b49790 Mon Sep 17 00:00:00 2001 From: Anuraag Agrawal Date: Thu, 3 Oct 2024 14:24:01 +0900 Subject: [PATCH] Build native artifacts for testing --- .github/workflows/release-testing.yaml | 141 ++++++++++++++++++++++++- Dockerfile | 2 - 2 files changed, 140 insertions(+), 3 deletions(-) diff --git a/.github/workflows/release-testing.yaml b/.github/workflows/release-testing.yaml index 3cd8c0593c5..a9d96a54c3f 100644 --- a/.github/workflows/release-testing.yaml +++ b/.github/workflows/release-testing.yaml @@ -9,10 +9,102 @@ on: workflow_dispatch: permissions: - contents: read + contents: write packages: write jobs: + # Full build of the Mac assets + build-darwin: + runs-on: macos-12 + 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: @@ -141,3 +233,50 @@ jobs: - 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 diff --git a/Dockerfile b/Dockerfile index 10b61497473..a267a9ad28c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -71,8 +71,6 @@ RUN --mount=type=cache,target=/root/.ccache \ go build -trimpath -o dist/linux-amd64/bin/ollama . RUN cd dist/linux-$GOARCH && \ tar --exclude runners -cf - . | pigz --best > ../ollama-linux-$GOARCH.tgz -RUN cd dist/linux-$GOARCH-rocm && \ - tar -cf - . | pigz --best > ../ollama-linux-$GOARCH-rocm.tgz FROM --platform=linux/arm64 cpu-build-arm64 AS build-arm64 ENV CGO_ENABLED=1