Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 26 additions & 9 deletions .github/actions/build-push-image/action.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Build and push image
description: >-
Shared tail for the container image builds: buildx setup, ghcr.io login, and a
gated build/push (publish only on main) with GitHub Actions layer cache.
gated build/push (publish on main, or on request) with GitHub Actions layer cache.
Callers do their own checkout / values.yaml read / upstream clone as normal
steps before calling this.

Expand Down Expand Up @@ -30,6 +30,13 @@ inputs:
description: Optional extra tag pushed with :latest and :sha-<commit> (e.g. the upstream version)
required: false
default: ""
publish:
description: >-
'true' also publishes from a branch (a manual run), tagged only
:sha-<commit>; :latest and extra_tag move only from main.
Empty -> publish only on main.
required: false
default: ""
platform:
description: >-
One platform to build (e.g. linux/arm64) on a runner of that architecture.
Expand All @@ -53,23 +60,33 @@ runs:
run: |
owner=${OWNER,,}
echo "owner=$owner" >> "$GITHUB_OUTPUT"
publish=false
if [ "$PUBLISH" = true ] || { [ "$EVENT" != pull_request ] && [ "$REF" = refs/heads/main ]; }; then
publish=true
fi
echo "publish=$publish" >> "$GITHUB_OUTPUT"
{
echo "tags<<EOF"
echo "ghcr.io/$owner/$IMAGE:latest"
echo "ghcr.io/$owner/$IMAGE:sha-$SHA"
if [ -n "$EXTRA_TAG" ]; then echo "ghcr.io/$owner/$IMAGE:$EXTRA_TAG"; fi
if [ "$REF" = refs/heads/main ]; then
echo "ghcr.io/$owner/$IMAGE:latest"
if [ -n "$EXTRA_TAG" ]; then echo "ghcr.io/$owner/$IMAGE:$EXTRA_TAG"; fi
fi
echo "EOF"
} >> "$GITHUB_OUTPUT"
env:
OWNER: ${{ github.repository_owner }}
IMAGE: ${{ inputs.image_name }}
SHA: ${{ github.sha }}
EXTRA_TAG: ${{ inputs.extra_tag }}
PUBLISH: ${{ inputs.publish }}
EVENT: ${{ github.event_name }}
REF: ${{ github.ref }}

- uses: docker/setup-buildx-action@v3

- name: Log in to ghcr.io
if: ${{ github.event_name != 'pull_request' && github.ref == 'refs/heads/main' }}
if: ${{ steps.meta.outputs.publish == 'true' }}
uses: docker/login-action@v3
with:
registry: ghcr.io
Expand All @@ -84,15 +101,15 @@ runs:
context: ${{ inputs.context }}
file: ${{ inputs.dockerfile }}
build-args: ${{ inputs.build_args }}
push: ${{ github.event_name != 'pull_request' && github.ref == 'refs/heads/main' }}
push: ${{ steps.meta.outputs.publish == 'true' }}
tags: ${{ steps.meta.outputs.tags }}
labels: org.opencontainers.image.source=https://github.com/${{ github.repository }}
cache-from: type=gha,scope=${{ inputs.cache_scope }}
cache-to: type=gha,mode=max,scope=${{ inputs.cache_scope }},ignore-error=true
provenance: false

- uses: ./.github/actions/verify-public-image
if: ${{ inputs.platform == '' && github.event_name != 'pull_request' && github.ref == 'refs/heads/main' }}
if: ${{ inputs.platform == '' && steps.meta.outputs.publish == 'true' }}
with:
image: ghcr.io/${{ steps.meta.outputs.owner }}/${{ inputs.image_name }}:sha-${{ github.sha }}

Expand All @@ -115,13 +132,13 @@ runs:
platforms: ${{ inputs.platform }}
tags: ghcr.io/${{ steps.meta.outputs.owner }}/${{ inputs.image_name }}
labels: org.opencontainers.image.source=https://github.com/${{ github.repository }}
outputs: type=image,push-by-digest=true,name-canonical=true,push=${{ github.event_name != 'pull_request' && github.ref == 'refs/heads/main' }}
outputs: type=image,push-by-digest=true,name-canonical=true,push=${{ steps.meta.outputs.publish == 'true' }}
cache-from: type=gha,scope=${{ inputs.cache_scope }}-${{ steps.plat.outputs.suffix }}
cache-to: type=gha,mode=max,scope=${{ inputs.cache_scope }}-${{ steps.plat.outputs.suffix }},ignore-error=true
provenance: false

- name: Record digest
if: inputs.platform != '' && github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
if: inputs.platform != '' && steps.meta.outputs.publish == 'true'
shell: bash
run: |
mkdir -p "$RUNNER_TEMP/digests"
Expand All @@ -130,7 +147,7 @@ runs:
DIGEST: ${{ steps.digest-build.outputs.digest }}

- uses: actions/upload-artifact@v4
if: inputs.platform != '' && github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
if: inputs.platform != '' && steps.meta.outputs.publish == 'true'
with:
name: digests-${{ inputs.image_name }}-${{ steps.plat.outputs.suffix }}
path: ${{ runner.temp }}/digests/*
Expand Down
13 changes: 10 additions & 3 deletions .github/actions/merge-image/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,25 @@ runs:
owner=${OWNER,,}
echo "owner=$owner" >> "$GITHUB_OUTPUT"
repo="ghcr.io/$owner/$IMAGE"
tags=(-t "$repo:latest" -t "$repo:sha-$SHA")
if [ -n "$EXTRA_TAG" ]; then tags+=(-t "$repo:$EXTRA_TAG"); fi
tags=(-t "$repo:sha-$SHA")
# Moving tags only from main; a branch publish is reachable by commit.
if [ "$REF" = refs/heads/main ]; then
tags+=(-t "$repo:latest")
if [ -n "$EXTRA_TAG" ]; then tags+=(-t "$repo:$EXTRA_TAG"); fi
fi
sources=()
for d in *; do sources+=("$repo@sha256:$d"); done
[ "${#sources[@]}" -ge 2 ] || { echo "expected a digest per platform, got: ${sources[*]}" >&2; exit 1; }
docker buildx imagetools create "${tags[@]}" "${sources[@]}"
docker buildx imagetools inspect "$repo:latest"
docker buildx imagetools inspect "$repo:sha-$SHA"
echo "### $IMAGE" >> "$GITHUB_STEP_SUMMARY"
docker buildx imagetools inspect "$repo:sha-$SHA" --format '`{{.Manifest.Digest}}`' >> "$GITHUB_STEP_SUMMARY"
env:
OWNER: ${{ github.repository_owner }}
IMAGE: ${{ inputs.image_name }}
SHA: ${{ github.sha }}
EXTRA_TAG: ${{ inputs.extra_tag }}
REF: ${{ github.ref }}

- uses: ./.github/actions/verify-public-image
with:
Expand Down
14 changes: 10 additions & 4 deletions .github/workflows/build-governance-interceptor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ on:
- tests/charts/test_governance_interceptor_image.py
- image-builder-charts/helm/governance-interceptor-image/**
workflow_dispatch:
inputs:
publish:
description: Publish this branch's build as ghcr.io/<owner>/governance-interceptor:sha-<commit>
type: boolean
default: false

permissions:
contents: read
Expand All @@ -31,7 +36,7 @@ jobs:
# One native build per architecture (no QEMU), each pushed by digest; the
# merge job joins them into one multi-arch :latest / :sha-<commit> tag.
build:
if: github.event_name == 'pull_request' || github.ref != 'refs/heads/main'
if: github.event_name == 'pull_request' || (github.ref != 'refs/heads/main' && !inputs.publish)
strategy: &platforms
# Each architecture reports its own result; merge still needs both.
fail-fast: false
Expand Down Expand Up @@ -78,7 +83,8 @@ jobs:
# the interceptor must match the SAW gateways' OpenShell release.
extra_tag: ${{ steps.params.outputs.openshell_ref }}
platform: ${{ matrix.platform }}
registry_token: ${{ github.event_name != 'pull_request' && github.ref == 'refs/heads/main' && secrets.GITHUB_TOKEN || '' }}
publish: ${{ inputs.publish && 'true' || '' }}
registry_token: ${{ ((github.event_name != 'pull_request' && github.ref == 'refs/heads/main') || inputs.publish) && secrets.GITHUB_TOKEN || '' }}

# Compile the OpenShift build source too, including its behavioral
# tests, on each architecture. This targets the builder stage; no
Expand Down Expand Up @@ -121,7 +127,7 @@ jobs:
provenance: false

publish:
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
if: (github.event_name != 'pull_request' && github.ref == 'refs/heads/main') || inputs.publish
permissions: {contents: read, packages: write}
strategy: *platforms
runs-on: ${{ matrix.runner }}
Expand All @@ -130,7 +136,7 @@ jobs:
merge:
needs: publish
permissions: {contents: read, packages: write}
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
if: (github.event_name != 'pull_request' && github.ref == 'refs/heads/main') || inputs.publish
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand Down
14 changes: 10 additions & 4 deletions .github/workflows/build-kubernetes-runtime.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ on:
- .github/actions/merge-image/**
- .github/actions/verify-public-image/**
workflow_dispatch:
inputs:
publish:
description: Publish this branch's build as ghcr.io/<owner>/saw-kubernetes-runtime:sha-<commit>
type: boolean
default: false

permissions:
contents: read
Expand All @@ -39,7 +44,7 @@ concurrency:

jobs:
build:
if: github.event_name == 'pull_request' || github.ref != 'refs/heads/main'
if: github.event_name == 'pull_request' || (github.ref != 'refs/heads/main' && !inputs.publish)
strategy: &platforms
fail-fast: false
matrix:
Expand All @@ -58,9 +63,10 @@ jobs:
dockerfile: kubernetes-runtime/Containerfile
cache_scope: saw-kubernetes-runtime
platform: ${{ matrix.platform }}
registry_token: ${{ github.event_name != 'pull_request' && github.ref == 'refs/heads/main' && secrets.GITHUB_TOKEN || '' }}
publish: ${{ inputs.publish && 'true' || '' }}
registry_token: ${{ ((github.event_name != 'pull_request' && github.ref == 'refs/heads/main') || inputs.publish) && secrets.GITHUB_TOKEN || '' }}
publish:
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
if: (github.event_name != 'pull_request' && github.ref == 'refs/heads/main') || inputs.publish
permissions: {contents: read, packages: write}
strategy: *platforms
runs-on: ${{ matrix.runner }}
Expand All @@ -69,7 +75,7 @@ jobs:
merge:
needs: publish
permissions: {contents: read, packages: write}
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
if: (github.event_name != 'pull_request' && github.ref == 'refs/heads/main') || inputs.publish
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand Down
106 changes: 106 additions & 0 deletions .github/workflows/build-openclaw-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
name: Build the OpenShift-ready OpenClaw image

# Publishes ghcr.io/<repository owner>/saw-openclaw (linux/amd64 and
# linux/arm64): the notebook BOM's stock OpenClaw image with /sandbox
# searchable by OpenShift namespace UIDs (images/saw-openclaw/Containerfile).
# Pin the published digest in containerDefaults.profileImageOverrides.

on:
push:
branches: [main]
paths:
- images/saw-openclaw/**
- charts/saw-bom/profiles/data-science/default/sandbox.yaml
- .github/workflows/build-openclaw-image.yml
- .github/actions/build-push-image/**
- .github/actions/merge-image/**
pull_request:
paths:
- images/saw-openclaw/**
- charts/saw-bom/profiles/data-science/default/sandbox.yaml
- .github/workflows/build-openclaw-image.yml
- .github/actions/build-push-image/**
- .github/actions/merge-image/**
workflow_dispatch:
inputs:
publish:
description: Publish this branch's build as ghcr.io/<owner>/saw-openclaw:sha-<commit>
type: boolean
default: false

permissions:
contents: read

concurrency:
group: build-openclaw-image-${{ github.ref }}
cancel-in-progress: true

jobs:
build:
if: github.event_name == 'pull_request' || (github.ref != 'refs/heads/main' && !inputs.publish)
strategy: &platforms
fail-fast: false
matrix:
include:
- platform: linux/amd64
runner: ubuntu-latest
- platform: linux/arm64
runner: ubuntu-24.04-arm
runs-on: ${{ matrix.runner }}
steps: &build_steps
- uses: actions/checkout@v4
- name: Resolve the stock image and its user
id: source
env:
PLATFORM: ${{ matrix.platform }}
run: |
set -euo pipefail
image=$(yq -r '.spec.sandboxes[] | select(.name == "notebook") | .image' charts/saw-bom/profiles/data-science/default/sandbox.yaml)
[[ "$image" =~ ^[a-z0-9][a-z0-9./:_-]+@sha256:([0-9a-f]{64})$ ]] || { echo "notebook image must be pinned by digest: $image" >&2; exit 1; }
digest="${BASH_REMATCH[1]}"
user=$(docker buildx imagetools inspect "$image" --format '{{json .Image}}' |
jq -er --arg p "$PLATFORM" 'if has("config") then .config.User else .[$p].config.User end | select(type == "string" and length > 0)')
[[ "$user" =~ ^[A-Za-z0-9_-]+(:[A-Za-z0-9_-]+)?$ && "${user%%:*}" != root && "${user%%:*}" != 0 ]] || { echo "stock image must declare a non-root USER: $user" >&2; exit 1; }
{
echo "image=$image"
echo "user=$user"
echo "tag=src-${digest:0:12}"
} >> "$GITHUB_OUTPUT"
- uses: ./.github/actions/build-push-image
with:
image_name: saw-openclaw
context: images/saw-openclaw
dockerfile: images/saw-openclaw/Containerfile
cache_scope: saw-openclaw
platform: ${{ matrix.platform }}
publish: ${{ inputs.publish && 'true' || '' }}
build_args: |
SOURCE_IMAGE=${{ steps.source.outputs.image }}
IMAGE_USER=${{ steps.source.outputs.user }}
registry_token: ${{ ((github.event_name != 'pull_request' && github.ref == 'refs/heads/main') || inputs.publish) && secrets.GITHUB_TOKEN || '' }}

publish:
if: (github.event_name != 'pull_request' && github.ref == 'refs/heads/main') || inputs.publish
permissions: {contents: read, packages: write}
strategy: *platforms
runs-on: ${{ matrix.runner }}
steps: *build_steps

merge:
needs: publish
permissions: {contents: read, packages: write}
if: (github.event_name != 'pull_request' && github.ref == 'refs/heads/main') || inputs.publish
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Source tag
id: source
run: |
image=$(yq -r '.spec.sandboxes[] | select(.name == "notebook") | .image' charts/saw-bom/profiles/data-science/default/sandbox.yaml)
digest="${image##*@sha256:}"
echo "tag=src-${digest:0:12}" >> "$GITHUB_OUTPUT"
- uses: ./.github/actions/merge-image
with:
image_name: saw-openclaw
extra_tag: ${{ steps.source.outputs.tag }}
registry_token: ${{ secrets.GITHUB_TOKEN }}
Loading
Loading