202 lines
7.5 KiB
YAML
202 lines
7.5 KiB
YAML
# This workflow builds and pushes the gateway, ui, and evaluations docker images to Docker Hub
|
|
# when we tag a release.
|
|
|
|
# SECURITY NOTE: We should disable all caches when building a public release to mitigate cache poisoning attacks.
|
|
|
|
name: Publish docker images
|
|
|
|
permissions: {}
|
|
|
|
on:
|
|
workflow_dispatch:
|
|
workflow_call:
|
|
inputs:
|
|
is_dev:
|
|
description: "Whether to use -dev suffix for container names"
|
|
type: boolean
|
|
required: false
|
|
default: true
|
|
secrets:
|
|
DOCKERHUB_DANGEROUS_TOKEN:
|
|
required: true
|
|
release:
|
|
types: [released]
|
|
|
|
concurrency:
|
|
group: docker-hub-publish-${{ github.event.pull_request.number || github.ref || github.run_id }}
|
|
cancel-in-progress: false
|
|
|
|
jobs:
|
|
build:
|
|
name: Build and push Docker image to Docker Hub
|
|
runs-on: ${{ matrix.platform.runner }}
|
|
timeout-minutes: 90
|
|
environment: dockerhub-publish
|
|
if: github.repository == 'tensorzero/tensorzero'
|
|
strategy:
|
|
matrix:
|
|
platform:
|
|
- runner: ubuntu-24.04
|
|
target: linux/amd64
|
|
- runner: ubuntu-24.04-arm
|
|
target: linux/arm64
|
|
container:
|
|
# Set the container name to a '-dev' name when this workflow is invoked by workflow_call with is_dev=true
|
|
# Otherwise, use the unsuffixed name (which will be invoked by a release or manual dispatch)
|
|
# Unfortunately, we can't use 'env' in 'strategy.matrix'
|
|
- name: ${{ inputs.is_dev && 'ui-dev' || 'ui' }}
|
|
path: ui
|
|
- name: ${{ inputs.is_dev && 'gateway-dev' || 'gateway' }}
|
|
path: crates/gateway
|
|
- name: ${{ inputs.is_dev && 'evaluations-dev' || 'evaluations' }}
|
|
path: crates/evaluations
|
|
|
|
permissions:
|
|
packages: write # Required to publish package or container metadata.
|
|
contents: read # Required for checkout or repository metadata reads.
|
|
attestations: write # Required to publish artifact attestations.
|
|
id-token: write # Required for OIDC-backed build or publish tooling.
|
|
steps:
|
|
- name: Check out the repo
|
|
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
|
with:
|
|
persist-credentials: false
|
|
|
|
- name: Prepare
|
|
env:
|
|
PLATFORM_TARGET: ${{ matrix.platform.target }}
|
|
run: |
|
|
platform="$PLATFORM_TARGET"
|
|
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
|
|
|
|
- name: Login to Docker Hub
|
|
uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0
|
|
with:
|
|
username: tensorzero
|
|
password: ${{ secrets.DOCKERHUB_DANGEROUS_TOKEN }}
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3.12.0
|
|
|
|
- name: Install Namespace CLI
|
|
uses: namespacelabs/nscloud-setup@f378676225212387f1283f4da878712af2c4cd60 # v0.0.11
|
|
|
|
- name: Configure Namespace-powered Buildx
|
|
uses: namespacelabs/nscloud-setup-buildx-action@91c2e6537780e3b092cb8476406be99a8f91bd5e # v0.0.20
|
|
with:
|
|
wait-for-builder: true
|
|
|
|
- name: Extract metadata (tags, labels) for Docker
|
|
id: meta
|
|
uses: docker/metadata-action@c299e40c65443455700f0fdfc63efafe5b349051 # v5.10.0
|
|
with:
|
|
images: ${{ matrix.container.name }}
|
|
|
|
- name: Build and push Docker image
|
|
id: push
|
|
uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2
|
|
with:
|
|
platforms: ${{ matrix.platform.target }}
|
|
file: ./${{ matrix.container.path }}/Dockerfile
|
|
# This is required to make '.git' available in the build context:
|
|
# https://github.com/docker/build-push-action/issues/513#issuecomment-987951050
|
|
context: .
|
|
push: true
|
|
provenance: mode=max
|
|
outputs: type=image,push-by-digest=true,name-canonical=true,push=true
|
|
tags: tensorzero/${{ matrix.container.name }}
|
|
labels: ${{ steps.meta.outputs.labels }}
|
|
sbom: true
|
|
no-cache: ${{ github.event_name == 'release' }}
|
|
# Use debug builds for dev images
|
|
build-args: |
|
|
PROFILE=${{ inputs.is_dev && 'dev' || 'performance' }}
|
|
DEBUG_BUILD=${{ inputs.is_dev && '1' || '0' }}
|
|
|
|
- name: Export digest
|
|
env:
|
|
PUSH_DIGEST: ${{ steps.push.outputs.digest }}
|
|
run: |
|
|
mkdir -p "$RUNNER_TEMP/digests"
|
|
digest="$PUSH_DIGEST"
|
|
touch "$RUNNER_TEMP/digests/${digest#sha256:}"
|
|
|
|
- name: Upload digest
|
|
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
|
|
with:
|
|
name: digests-${{ matrix.container.name }}-${{ env.PLATFORM_PAIR }}
|
|
path: ${{ runner.temp }}/digests/*
|
|
if-no-files-found: error
|
|
retention-days: 1
|
|
|
|
merge:
|
|
name: merge
|
|
permissions:
|
|
actions: read # Required to read workflow run, cache, or artifact metadata.
|
|
environment: dockerhub-publish
|
|
if: github.repository == 'tensorzero/tensorzero'
|
|
strategy:
|
|
matrix:
|
|
container:
|
|
- name: ${{ inputs.is_dev && 'ui-dev' || 'ui' }}
|
|
- name: ${{ inputs.is_dev && 'gateway-dev' || 'gateway' }}
|
|
- name: ${{ inputs.is_dev && 'evaluations-dev' || 'evaluations' }}
|
|
runs-on: ubuntu-latest
|
|
timeout-minutes: 30
|
|
needs:
|
|
- build
|
|
steps:
|
|
- name: Download digests
|
|
uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6.0.0
|
|
with:
|
|
path: ${{ runner.temp }}/digests
|
|
pattern: digests-${{ matrix.container.name }}-*
|
|
merge-multiple: true
|
|
|
|
- name: Login to Docker Hub
|
|
uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0
|
|
with:
|
|
username: tensorzero
|
|
password: ${{ secrets.DOCKERHUB_DANGEROUS_TOKEN }}
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3.12.0
|
|
|
|
- name: Docker meta
|
|
id: meta
|
|
uses: docker/metadata-action@c299e40c65443455700f0fdfc63efafe5b349051 # v5.10.0
|
|
with:
|
|
images: tensorzero/${{ matrix.container.name }}
|
|
flavor: |
|
|
latest=false
|
|
tags: |
|
|
type=ref,event=tag,
|
|
type=sha,format=long,enable=${{ inputs.is_dev && 'true' || 'false' }}
|
|
type=raw,value=latest,enable=${{ github.event_name == 'release' && github.event.prerelease == false }}
|
|
|
|
- name: Create manifest list and push
|
|
working-directory: ${{ runner.temp }}/digests
|
|
run: |
|
|
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
|
|
$(printf "tensorzero/${MATRIX_CONTAINER_NAME}@sha256:%s " *)
|
|
env:
|
|
MATRIX_CONTAINER_NAME: ${{ matrix.container.name }}
|
|
|
|
- name: Wait for image to be available on Docker Hub
|
|
run: |
|
|
IMAGE="tensorzero/${MATRIX_CONTAINER_NAME}:${STEPS_META_OUTPUTS_VERSION}"
|
|
echo "Waiting for ${IMAGE} to be available on Docker Hub..."
|
|
for i in $(seq 1 30); do
|
|
if docker manifest inspect "${IMAGE}" > /dev/null 2>&1; then
|
|
echo "Image ${IMAGE} is available on Docker Hub"
|
|
exit 0
|
|
fi
|
|
echo "Attempt ${i}/30: Image not yet available, waiting 10s..."
|
|
sleep 10
|
|
done
|
|
echo "Timed out waiting for ${IMAGE} to appear on Docker Hub"
|
|
exit 1
|
|
env:
|
|
MATRIX_CONTAINER_NAME: ${{ matrix.container.name }}
|
|
STEPS_META_OUTPUTS_VERSION: ${{ steps.meta.outputs.version }}
|