mirror of
https://github.com/googleapis/genai-toolbox.git
synced 2026-01-09 15:38:08 -05:00
- Support CGO cross compilation for multiple architectures using Zig. - Download and link MacOSX SDK as needed by the MacOSX cross compilation. There is no official release for MacOSC SDK so I had to download from a third party repo. - Update dockerfile from using `gcr.io/distroless/static:nonroot` to `gcr.io/distroless/cc-debian12:nonroot` for C libraries that is needed for dynamic linking.
356 lines
14 KiB
YAML
356 lines
14 KiB
YAML
# Copyright 2024 Google LLC
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
|
|
steps:
|
|
- id: "build-docker"
|
|
name: "gcr.io/cloud-builders/docker"
|
|
waitFor: ['-']
|
|
script: |
|
|
#!/usr/bin/env bash
|
|
export VERSION=$(cat ./cmd/version.txt)
|
|
docker buildx create --name container-builder --driver docker-container --bootstrap --use
|
|
|
|
export TAGS="-t ${_DOCKER_URI}:$VERSION"
|
|
if [[ $_PUSH_LATEST == 'true' ]]; then
|
|
export TAGS="$TAGS -t ${_DOCKER_URI}:latest"
|
|
fi
|
|
docker buildx build --platform linux/amd64,linux/arm64 --build-arg BUILD_TYPE=container.release --build-arg COMMIT_SHA=$(git rev-parse --short HEAD) $TAGS --push .
|
|
|
|
- id: "install-dependencies"
|
|
name: golang:1
|
|
waitFor: ['-']
|
|
env:
|
|
- 'GOPATH=/gopath'
|
|
volumes:
|
|
- name: 'go'
|
|
path: '/gopath'
|
|
script: |
|
|
go get -d ./...
|
|
|
|
- id: "install-zig"
|
|
name: golang:1
|
|
waitFor: ['-']
|
|
volumes:
|
|
- name: 'zig'
|
|
path: '/zig-tools'
|
|
script: |
|
|
#!/usr/bin/env bash
|
|
set -e
|
|
apt-get update && apt-get install -y xz-utils
|
|
curl -fL "https://ziglang.org/download/0.15.2/zig-x86_64-linux-0.15.2.tar.xz" -o zig.tar.xz
|
|
tar -xf zig.tar.xz -C /zig-tools --strip-components=1
|
|
|
|
- id: "install-macos-sdk"
|
|
name: golang:1
|
|
waitFor: ['-']
|
|
volumes:
|
|
- name: 'macos-sdk'
|
|
path: '/macos-sdk'
|
|
script: |
|
|
#!/usr/bin/env bash
|
|
set -e
|
|
apt-get update && apt-get install -y xz-utils
|
|
echo "Downloading macOS 14.5 SDK..."
|
|
curl -fL -o sdk.tar.xz https://github.com/alexey-lysiuk/macos-sdk/releases/download/14.5/MacOSX14.5.tar.xz
|
|
|
|
mkdir -p /macos-sdk/MacOSX14.5.sdk
|
|
echo "Unpacking macOS 14.5 SDK..."
|
|
tar -xf sdk.tar.xz -C /macos-sdk/MacOSX14.5.sdk --strip-components=1
|
|
|
|
- id: "build-linux-amd64"
|
|
name: golang:1
|
|
waitFor:
|
|
- "install-dependencies"
|
|
- "install-zig"
|
|
env:
|
|
- 'GOPATH=/gopath'
|
|
- 'CGO_ENABLED=1'
|
|
- 'GOOS=linux'
|
|
- 'GOARCH=amd64'
|
|
- 'CC=/zig-tools/zig cc -target x86_64-linux-gnu'
|
|
- 'CXX=/zig-tools/zig c++ -target x86_64-linux-gnu'
|
|
volumes:
|
|
- name: 'go'
|
|
path: '/gopath'
|
|
- name: 'zig'
|
|
path: '/zig-tools'
|
|
script: |
|
|
#!/usr/bin/env bash
|
|
go build -ldflags "-X github.com/googleapis/genai-toolbox/cmd.buildType=binary -X github.com/googleapis/genai-toolbox/cmd.commitSha=$(git rev-parse --short HEAD)" -o toolbox.linux.amd64
|
|
|
|
- id: "store-linux-amd64"
|
|
name: "gcr.io/cloud-builders/gcloud:latest"
|
|
waitFor:
|
|
- "build-linux-amd64"
|
|
script: |
|
|
#!/usr/bin/env bash
|
|
export VERSION=v$(cat ./cmd/version.txt)
|
|
gcloud storage cp toolbox.linux.amd64 gs://$_BUCKET_NAME/$VERSION/linux/amd64/toolbox
|
|
|
|
- id: "build-linux-amd64-geminicli"
|
|
name: golang:1
|
|
waitFor:
|
|
- "install-dependencies"
|
|
- "install-zig"
|
|
env:
|
|
- 'GOPATH=/gopath'
|
|
- 'CGO_ENABLED=1'
|
|
- 'GOOS=linux'
|
|
- 'GOARCH=amd64'
|
|
- 'CC=/zig-tools/zig cc -target x86_64-linux-gnu'
|
|
- 'CXX=/zig-tools/zig c++ -target x86_64-linux-gnu'
|
|
volumes:
|
|
- name: 'go'
|
|
path: '/gopath'
|
|
- name: 'zig'
|
|
path: '/zig-tools'
|
|
script: |
|
|
#!/usr/bin/env bash
|
|
go build -ldflags "-X github.com/googleapis/genai-toolbox/cmd.buildType=geminicli.binary -X github.com/googleapis/genai-toolbox/cmd.commitSha=$(git rev-parse --short HEAD)" -o toolbox.geminicli.linux.amd64
|
|
|
|
- id: "store-linux-amd64-geminicli"
|
|
name: "gcr.io/cloud-builders/gcloud:latest"
|
|
waitFor:
|
|
- "build-linux-amd64-geminicli"
|
|
script: |
|
|
#!/usr/bin/env bash
|
|
export VERSION=v$(cat ./cmd/version.txt)
|
|
gcloud storage cp toolbox.geminicli.linux.amd64 gs://$_BUCKET_NAME/geminicli/$VERSION/linux/amd64/toolbox
|
|
|
|
- id: "build-darwin-arm64"
|
|
name: golang:1
|
|
waitFor:
|
|
- "install-dependencies"
|
|
- "install-zig"
|
|
- "install-macos-sdk"
|
|
env:
|
|
- 'GOPATH=/gopath'
|
|
- 'CGO_ENABLED=1'
|
|
- 'GOOS=darwin'
|
|
- 'GOARCH=arm64'
|
|
- 'SDK_PATH=/macos-sdk/MacOSX14.5.sdk'
|
|
- 'MACOS_MIN_VER=10.14'
|
|
- 'CGO_LDFLAGS=-mmacosx-version-min=10.14 --sysroot /macos-sdk/MacOSX14.5.sdk -F/macos-sdk/MacOSX14.5.sdk/System/Library/Frameworks -L/usr/lib'
|
|
- 'COMMON_FLAGS=-mmacosx-version-min=10.14 -target aarch64-macos.11.0.0-none -isysroot /macos-sdk/MacOSX14.5.sdk -iwithsysroot /usr/include -iframeworkwithsysroot /System/Library/Frameworks'
|
|
- 'CC=/zig-tools/zig cc -mmacosx-version-min=10.14 -target aarch64-macos.11.0.0-none -isysroot /macos-sdk/MacOSX14.5.sdk -iwithsysroot /usr/include -iframeworkwithsysroot /System/Library/Frameworks'
|
|
- 'CXX=/zig-tools/zig c++ -mmacosx-version-min=10.14 -target aarch64-macos.11.0.0-none -isysroot /macos-sdk/MacOSX14.5.sdk -iwithsysroot /usr/include -iframeworkwithsysroot /System/Library/Frameworks'
|
|
volumes:
|
|
- name: 'go'
|
|
path: '/gopath'
|
|
- name: 'zig'
|
|
path: '/zig-tools'
|
|
- name: 'macos-sdk'
|
|
path: '/macos-sdk'
|
|
script: |
|
|
#!/usr/bin/env bash
|
|
go build -trimpath -buildmode=pie -ldflags "-s -w -X github.com/googleapis/genai-toolbox/cmd.buildType=binary -X github.com/googleapis/genai-toolbox/cmd.commitSha=$(git rev-parse --short HEAD)" -o toolbox.darwin.arm64
|
|
|
|
- id: "store-darwin-arm64"
|
|
name: "gcr.io/cloud-builders/gcloud:latest"
|
|
waitFor:
|
|
- "build-darwin-arm64"
|
|
script: |
|
|
#!/usr/bin/env bash
|
|
export VERSION=v$(cat ./cmd/version.txt)
|
|
gcloud storage cp toolbox.darwin.arm64 \
|
|
gs://$_BUCKET_NAME/$VERSION/darwin/arm64/toolbox
|
|
|
|
- id: "build-darwin-arm64-geminicli"
|
|
name: golang:1
|
|
waitFor:
|
|
- "install-dependencies"
|
|
- "install-zig"
|
|
- "install-macos-sdk"
|
|
env:
|
|
- 'GOPATH=/gopath'
|
|
- 'CGO_ENABLED=1'
|
|
- 'GOOS=darwin'
|
|
- 'GOARCH=arm64'
|
|
- 'SDK_PATH=/macos-sdk/MacOSX14.5.sdk'
|
|
- 'MACOS_MIN_VER=10.14'
|
|
- 'CGO_LDFLAGS=-mmacosx-version-min=10.14 --sysroot /macos-sdk/MacOSX14.5.sdk -F/macos-sdk/MacOSX14.5.sdk/System/Library/Frameworks -L/usr/lib'
|
|
- 'COMMON_FLAGS=-mmacosx-version-min=10.14 -target aarch64-macos.11.0.0-none -isysroot /macos-sdk/MacOSX14.5.sdk -iwithsysroot /usr/include -iframeworkwithsysroot /System/Library/Frameworks'
|
|
- 'CC=/zig-tools/zig cc -mmacosx-version-min=10.14 -target aarch64-macos.11.0.0-none -isysroot /macos-sdk/MacOSX14.5.sdk -iwithsysroot /usr/include -iframeworkwithsysroot /System/Library/Frameworks'
|
|
- 'CXX=/zig-tools/zig c++ -mmacosx-version-min=10.14 -target aarch64-macos.11.0.0-none -isysroot /macos-sdk/MacOSX14.5.sdk -iwithsysroot /usr/include -iframeworkwithsysroot /System/Library/Frameworks'
|
|
volumes:
|
|
- name: 'go'
|
|
path: '/gopath'
|
|
- name: 'zig'
|
|
path: '/zig-tools'
|
|
- name: 'macos-sdk'
|
|
path: '/macos-sdk'
|
|
script: |
|
|
#!/usr/bin/env bash
|
|
go build -trimpath -buildmode=pie -ldflags "-s -w -X github.com/googleapis/genai-toolbox/cmd.buildType=geminicli.binary -X github.com/googleapis/genai-toolbox/cmd.commitSha=$(git rev-parse --short HEAD)" -o toolbox.geminicli.darwin.arm64
|
|
|
|
- id: "store-darwin-arm64-geminicli"
|
|
name: "gcr.io/cloud-builders/gcloud:latest"
|
|
waitFor:
|
|
- "build-darwin-arm64-geminicli"
|
|
script: |
|
|
#!/usr/bin/env bash
|
|
export VERSION=v$(cat ./cmd/version.txt)
|
|
gcloud storage cp toolbox.geminicli.darwin.arm64 gs://$_BUCKET_NAME/geminicli/$VERSION/darwin/arm64/toolbox
|
|
|
|
- id: "build-darwin-amd64"
|
|
name: golang:1
|
|
waitFor:
|
|
- "install-dependencies"
|
|
- "install-zig"
|
|
- "install-macos-sdk"
|
|
env:
|
|
- 'GOPATH=/gopath'
|
|
- 'CGO_ENABLED=1'
|
|
- 'GOOS=darwin'
|
|
- 'GOARCH=amd64'
|
|
- 'SDK_PATH=/macos-sdk/MacOSX14.5.sdk'
|
|
- 'MACOS_MIN_VER=10.14'
|
|
- 'CGO_LDFLAGS=-mmacosx-version-min=10.14 --sysroot /macos-sdk/MacOSX14.5.sdk -F/macos-sdk/MacOSX14.5.sdk/System/Library/Frameworks -L/usr/lib'
|
|
- 'COMMON_FLAGS=-mmacosx-version-min=10.14 -target x86_64-macos.11.0.0-none -isysroot /macos-sdk/MacOSX14.5.sdk -iwithsysroot /usr/include -iframeworkwithsysroot /System/Library/Frameworks'
|
|
- 'CC=/zig-tools/zig cc -mmacosx-version-min=10.14 -target x86_64-macos.11.0.0-none -isysroot /macos-sdk/MacOSX14.5.sdk -iwithsysroot /usr/include -iframeworkwithsysroot /System/Library/Frameworks'
|
|
- 'CXX=/zig-tools/zig c++ -mmacosx-version-min=10.14 -target x86_64-macos.11.0.0-none -isysroot /macos-sdk/MacOSX14.5.sdk -iwithsysroot /usr/include -iframeworkwithsysroot /System/Library/Frameworks'
|
|
volumes:
|
|
- name: 'go'
|
|
path: '/gopath'
|
|
- name: 'zig'
|
|
path: '/zig-tools'
|
|
- name: 'macos-sdk'
|
|
path: '/macos-sdk'
|
|
script: |
|
|
#!/usr/bin/env bash
|
|
go build -trimpath -buildmode=pie -ldflags "-s -w -X github.com/googleapis/genai-toolbox/cmd.buildType=binary -X github.com/googleapis/genai-toolbox/cmd.commitSha=$(git rev-parse --short HEAD)" -o toolbox.darwin.amd64
|
|
|
|
- id: "store-darwin-amd64"
|
|
name: "gcr.io/cloud-builders/gcloud:latest"
|
|
waitFor:
|
|
- "build-darwin-amd64"
|
|
script: |
|
|
#!/usr/bin/env bash
|
|
export VERSION=v$(cat ./cmd/version.txt)
|
|
gcloud storage cp toolbox.darwin.amd64 gs://$_BUCKET_NAME/$VERSION/darwin/amd64/toolbox
|
|
|
|
- id: "build-darwin-amd64-geminicli"
|
|
name: golang:1
|
|
waitFor:
|
|
- "install-dependencies"
|
|
- "install-zig"
|
|
- "install-macos-sdk"
|
|
env:
|
|
- 'GOPATH=/gopath'
|
|
- 'CGO_ENABLED=1'
|
|
- 'GOOS=darwin'
|
|
- 'GOARCH=amd64'
|
|
- 'SDK_PATH=/macos-sdk/MacOSX14.5.sdk'
|
|
- 'MACOS_MIN_VER=10.14'
|
|
- 'CGO_LDFLAGS=-mmacosx-version-min=10.14 --sysroot /macos-sdk/MacOSX14.5.sdk -F/macos-sdk/MacOSX14.5.sdk/System/Library/Frameworks -L/usr/lib'
|
|
- 'COMMON_FLAGS=-mmacosx-version-min=10.14 -target x86_64-macos.11.0.0-none -isysroot /macos-sdk/MacOSX14.5.sdk -iwithsysroot /usr/include -iframeworkwithsysroot /System/Library/Frameworks'
|
|
- 'CC=/zig-tools/zig cc -mmacosx-version-min=10.14 -target x86_64-macos.11.0.0-none -isysroot /macos-sdk/MacOSX14.5.sdk -iwithsysroot /usr/include -iframeworkwithsysroot /System/Library/Frameworks'
|
|
- 'CXX=/zig-tools/zig c++ -mmacosx-version-min=10.14 -target x86_64-macos.11.0.0-none -isysroot /macos-sdk/MacOSX14.5.sdk -iwithsysroot /usr/include -iframeworkwithsysroot /System/Library/Frameworks'
|
|
volumes:
|
|
- name: 'go'
|
|
path: '/gopath'
|
|
- name: 'zig'
|
|
path: '/zig-tools'
|
|
- name: 'macos-sdk'
|
|
path: '/macos-sdk'
|
|
script: |
|
|
#!/usr/bin/env bash
|
|
go build -trimpath -buildmode=pie -ldflags "-s -w -X github.com/googleapis/genai-toolbox/cmd.buildType=geminicli.binary -X github.com/googleapis/genai-toolbox/cmd.commitSha=$(git rev-parse --short HEAD)" -o toolbox.geminicli.darwin.amd64
|
|
|
|
- id: "store-darwin-amd64-geminicli"
|
|
name: "gcr.io/cloud-builders/gcloud:latest"
|
|
waitFor:
|
|
- "build-darwin-amd64-geminicli"
|
|
script: |
|
|
#!/usr/bin/env bash
|
|
export VERSION=v$(cat ./cmd/version.txt)
|
|
gcloud storage cp toolbox.geminicli.darwin.amd64 \
|
|
gs://$_BUCKET_NAME/geminicli/$VERSION/darwin/amd64/toolbox
|
|
|
|
- id: "build-windows-amd64"
|
|
name: golang:1
|
|
waitFor:
|
|
- "install-dependencies"
|
|
- "install-zig"
|
|
env:
|
|
- 'GOPATH=/gopath'
|
|
- 'CGO_ENABLED=1'
|
|
- 'GOOS=windows'
|
|
- 'GOARCH=amd64'
|
|
- 'CC=/zig-tools/zig cc -target x86_64-windows-gnu'
|
|
- 'CXX=/zig-tools/zig c++ -target x86_64-windows-gnu'
|
|
volumes:
|
|
- name: 'go'
|
|
path: '/gopath'
|
|
- name: 'zig'
|
|
path: '/zig-tools'
|
|
script: |
|
|
#!/usr/bin/env bash
|
|
go build -ldflags "-X github.com/googleapis/genai-toolbox/cmd.buildType=binary -X github.com/googleapis/genai-toolbox/cmd.commitSha=$(git rev-parse --short HEAD)" -o toolbox.windows.amd64
|
|
|
|
- id: "store-windows-amd64"
|
|
name: "gcr.io/cloud-builders/gcloud:latest"
|
|
waitFor:
|
|
- "build-windows-amd64"
|
|
script: |
|
|
#!/usr/bin/env bash
|
|
export VERSION=v$(cat ./cmd/version.txt)
|
|
gcloud storage cp toolbox.windows.amd64 gs://$_BUCKET_NAME/$VERSION/windows/amd64/toolbox.exe
|
|
|
|
- id: "build-windows-amd64-geminicli"
|
|
name: golang:1
|
|
waitFor:
|
|
- "install-dependencies"
|
|
- "install-zig"
|
|
env:
|
|
- 'GOPATH=/gopath'
|
|
- 'CGO_ENABLED=1'
|
|
- 'GOOS=windows'
|
|
- 'GOARCH=amd64'
|
|
- 'CC=/zig-tools/zig cc -target x86_64-windows-gnu'
|
|
- 'CXX=/zig-tools/zig c++ -target x86_64-windows-gnu'
|
|
volumes:
|
|
- name: 'go'
|
|
path: '/gopath'
|
|
- name: 'zig'
|
|
path: '/zig-tools'
|
|
- name: 'macos-sdk'
|
|
path: '/macos-sdk'
|
|
script: |
|
|
#!/usr/bin/env bash
|
|
go build -ldflags "-X github.com/googleapis/genai-toolbox/cmd.buildType=geminicli.binary -X github.com/googleapis/genai-toolbox/cmd.commitSha=$(git rev-parse --short HEAD)" -o toolbox.geminicli.windows.amd64
|
|
|
|
- id: "store-windows-amd64-geminicli"
|
|
name: "gcr.io/cloud-builders/gcloud:latest"
|
|
waitFor:
|
|
- "build-windows-amd64-geminicli"
|
|
script: |
|
|
#!/usr/bin/env bash
|
|
export VERSION=v$(cat ./cmd/version.txt)
|
|
gcloud storage cp toolbox.geminicli.windows.amd64 gs://$_BUCKET_NAME/geminicli/$VERSION/windows/amd64/toolbox.exe
|
|
|
|
options:
|
|
automapSubstitutions: true
|
|
dynamicSubstitutions: true
|
|
logging: CLOUD_LOGGING_ONLY # Necessary for custom service account
|
|
pool:
|
|
name: projects/$PROJECT_ID/locations/us-central1/workerPools/run-release # to increase resource for running releases
|
|
|
|
|
|
substitutions:
|
|
_REGION: us-central1
|
|
_AR_HOSTNAME: ${_REGION}-docker.pkg.dev
|
|
_AR_REPO_NAME: toolbox
|
|
_BUCKET_NAME: genai-toolbox
|
|
_DOCKER_URI: ${_AR_HOSTNAME}/${PROJECT_ID}/${_AR_REPO_NAME}/toolbox
|
|
_PUSH_LATEST: "false" # Substituted in trigger |