Skip to content

Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.

ci: build docker images natively per arch (#1100)

Jiahui Zhou59334dcb5273
diff --git a/.github/workflows/build-docker-image.yml b/.github/workflows/build-docker-image.yml
index c36802d74..4845ddce7 100644
--- a/.github/workflows/build-docker-image.yml
+++ b/.github/workflows/build-docker-image.yml
@@ -12,11 +12,20 @@ on:
env:
REGISTRY: ghcr.io
- IMAGE_NAME: ${{ github.repository }}
jobs:
build-and-push-image:
- runs-on: ubuntu-24.04
+ strategy:
+ fail-fast: false
+ matrix:
+ include:
+ - arch: amd64
+ platform: linux/amd64
+ runner: ubuntu-24.04
+ - arch: arm64
+ platform: linux/arm64
+ runner: ubuntu-24.04-arm
+ runs-on: ${{ matrix.runner }}
permissions:
contents: read
packages: write
@@ -29,6 +38,13 @@ jobs:
with:
submodules: recursive
+ - name: Normalize image name
+ id: image-name
+ env:
+ RAW_IMAGE_NAME: ${{ github.repository }}
+ run: |
+ echo "image=$(echo "$RAW_IMAGE_NAME" | tr '[:upper:]' '[:lower:]')" >> "$GITHUB_OUTPUT"
+
- name: Log in to the Container registry
uses: docker/login-action@v4
with:
@@ -40,10 +56,10 @@ jobs:
id: meta
uses: docker/metadata-action@v6
with:
- images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
-
- - name: Set up QEMU
- uses: docker/setup-qemu-action@v4
+ images: ${{ env.REGISTRY }}/${{ steps.image-name.outputs.image }}
+ tags: |
+ type=raw,value=${{ github.event.inputs.version }},enable=${{ github.event_name == 'workflow_dispatch' }}
+ type=ref,event=tag,enable=${{ github.ref_type == 'tag' }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
@@ -53,10 +69,91 @@ jobs:
uses: docker/build-push-action@v7
with:
context: .
- platforms: linux/amd64,linux/arm64
- push: ${{ github.ref_type == 'tag' || github.event_name == 'workflow_dispatch' }}
- tags: ${{ steps.meta.outputs.tags }}
+ platforms: ${{ matrix.platform }}
+ outputs: type=image,name=${{ env.REGISTRY }}/${{ steps.image-name.outputs.image }},push-by-digest=true,name-canonical=true,push=true
labels: ${{ steps.meta.outputs.labels }}
build-args: |
# fallback to 0.0.0 if no version is provided
OPENVIKING_VERSION=${{ (github.event_name == 'workflow_dispatch' && github.event.inputs.version) || (github.ref_type == 'tag' && github.ref_name) || '0.0.0' }}
+
+ - name: Export image digest
+ run: |
+ mkdir -p /tmp/digests
+ digest="${{ steps.push.outputs.digest }}"
+ touch "/tmp/digests/${digest#sha256:}"
+
+ - name: Upload image digest
+ uses: actions/upload-artifact@v7
+ with:
+ name: docker-digests-${{ matrix.arch }}
+ path: /tmp/digests/*
+ if-no-files-found: error
+ retention-days: 1
+
+ create-manifest:
+ runs-on: ubuntu-24.04
+ needs: build-and-push-image
+ permissions:
+ contents: read
+ packages: write
+
+ steps:
+ - name: Checkout repository
+ uses: actions/checkout@v6
+ with:
+ submodules: recursive
+
+ - name: Normalize image name
+ id: image-name
+ env:
+ RAW_IMAGE_NAME: ${{ github.repository }}
+ run: |
+ echo "image=$(echo "$RAW_IMAGE_NAME" | tr '[:upper:]' '[:lower:]')" >> "$GITHUB_OUTPUT"
+
+ - name: Log in to the Container registry
+ uses: docker/login-action@v4
+ with:
+ registry: ${{ env.REGISTRY }}
+ username: ${{ github.actor }}
+ password: ${{ secrets.GITHUB_TOKEN }}
+
+ - name: Extract metadata (tags, labels) for Docker
+ id: meta
+ uses: docker/metadata-action@v6
+ with:
+ images: ${{ env.REGISTRY }}/${{ steps.image-name.outputs.image }}
+ tags: |
+ type=raw,value=${{ github.event.inputs.version }},enable=${{ github.event_name == 'workflow_dispatch' }}
+ type=ref,event=tag,enable=${{ github.ref_type == 'tag' }}
+
+ - name: Set up Docker Buildx
+ uses: docker/setup-buildx-action@v4
+
+ - name: Download image digests
+ uses: actions/download-artifact@v8
+ with:
+ pattern: docker-digests-*
+ path: /tmp/digests
+ merge-multiple: true
+
+ - name: Create multi-arch manifests
+ env:
+ SOURCE_TAGS: ${{ steps.meta.outputs.tags }}
+ run: |
+ image_refs=()
+ for digest_file in /tmp/digests/*; do
+ [ -e "$digest_file" ] || continue
+ image_refs+=("${{ env.REGISTRY }}/${{ steps.image-name.outputs.image }}@sha256:$(basename "$digest_file")")
+ done
+
+ [ ${#image_refs[@]} -gt 0 ] || {
+ echo "No image digests found" >&2
+ exit 1
+ }
+
+ while IFS= read -r tag; do
+ [ -n "$tag" ] || continue
+ docker buildx imagetools create \
+ --tag "$tag" \
+ "${image_refs[@]}"
+ done <<< "$SOURCE_TAGS"
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 2f8fad30e..ec9c51d12 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -156,12 +156,22 @@ jobs:
echo "::notice::Published to PyPI (or already existed) with version: $VERSION"
docker:
- name: Build and Push Docker Image
+ name: Build and Push Docker Image (${{ matrix.arch }})
needs: [build, permission-check]
if: >-
needs.permission-check.outputs.allowed == 'true' &&
github.event_name == 'release'
- runs-on: ubuntu-24.04
+ strategy:
+ fail-fast: false
+ matrix:
+ include:
+ - arch: amd64
+ platform: linux/amd64
+ runner: ubuntu-24.04
+ - arch: arm64
+ platform: linux/arm64
+ runner: ubuntu-24.04-arm
+ runs-on: ${{ matrix.runner }}
permissions:
contents: read
packages: write
@@ -173,6 +183,13 @@ jobs:
with:
submodules: recursive
+ - name: Normalize image name
+ id: image-name
+ env:
+ RAW_IMAGE_NAME: ${{ github.repository }}
+ run: |
+ echo "image=$(echo "$RAW_IMAGE_NAME" | tr '[:upper:]' '[:lower:]')" >> "$GITHUB_OUTPUT"
+
- name: Log in to the Container registry
uses: docker/login-action@v4
with:
@@ -184,21 +201,104 @@ jobs:
id: meta
uses: docker/metadata-action@v6
with:
- images: ghcr.io/${{ github.repository }}
-
- - name: Set up QEMU
- uses: docker/setup-qemu-action@v4
+ images: ghcr.io/${{ steps.image-name.outputs.image }}
+ tags: |
+ type=raw,value=${{ github.event.release.tag_name }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Build and push Docker image
+ id: push
uses: docker/build-push-action@v7
with:
context: .
- platforms: linux/amd64,linux/arm64
- push: true
- tags: ${{ steps.meta.outputs.tags }}
+ platforms: ${{ matrix.platform }}
+ outputs: type=image,name=ghcr.io/${{ steps.image-name.outputs.image }},push-by-digest=true,name-canonical=true,push=true
labels: ${{ steps.meta.outputs.labels }}
build-args: |
OPENVIKING_VERSION=${{ github.event.release.tag_name }}
+
+ - name: Export image digest
+ run: |
+ mkdir -p /tmp/digests
+ digest="${{ steps.push.outputs.digest }}"
+ touch "/tmp/digests/${digest#sha256:}"
+
+ - name: Upload image digest
+ uses: actions/upload-artifact@v7
+ with:
+ name: docker-digests-${{ matrix.arch }}
+ path: /tmp/digests/*
+ if-no-files-found: error
+ retention-days: 1
+
+ docker-manifest:
+ name: Publish Docker Manifest
+ needs: [docker, permission-check]
+ if: >-
+ needs.permission-check.outputs.allowed == 'true' &&
+ github.event_name == 'release'
+ runs-on: ubuntu-24.04
+ permissions:
+ contents: read
+ packages: write
+ steps:
+ - name: Checkout repository
+ uses: actions/checkout@v6
+ with:
+ submodules: recursive
+
+ - name: Normalize image name
+ id: image-name
+ env:
+ RAW_IMAGE_NAME: ${{ github.repository }}
+ run: |
+ echo "image=$(echo "$RAW_IMAGE_NAME" | tr '[:upper:]' '[:lower:]')" >> "$GITHUB_OUTPUT"
+
+ - name: Log in to the Container registry
+ uses: docker/login-action@v4
+ with:
+ registry: ghcr.io
+ username: ${{ github.actor }}
+ password: ${{ secrets.GITHUB_TOKEN }}
+
+ - name: Extract metadata (tags, labels) for Docker
+ id: meta
+ uses: docker/metadata-action@v6
+ with:
+ images: ghcr.io/${{ steps.image-name.outputs.image }}
+ tags: |
+ type=raw,value=${{ github.event.release.tag_name }}
+
+ - name: Set up Docker Buildx
+ uses: docker/setup-buildx-action@v4
+
+ - name: Download image digests
+ uses: actions/download-artifact@v8
+ with:
+ pattern: docker-digests-*
+ path: /tmp/digests
+ merge-multiple: true
+
+ - name: Create multi-arch manifests
+ env:
+ SOURCE_TAGS: ${{ steps.meta.outputs.tags }}
+ run: |
+ image_refs=()
+ for digest_file in /tmp/digests/*; do
+ [ -e "$digest_file" ] || continue
+ image_refs+=("ghcr.io/${{ steps.image-name.outputs.image }}@sha256:$(basename "$digest_file")")
+ done
+
+ [ ${#image_refs[@]} -gt 0 ] || {
+ echo "No image digests found" >&2
+ exit 1
+ }
+
+ while IFS= read -r tag; do
+ [ -n "$tag" ] || continue
+ docker buildx imagetools create \
+ --tag "$tag" \
+ "${image_refs[@]}"
+ done <<< "$SOURCE_TAGS"
diff --git a/tests/misc/test_docker_workflow_native_multiarch.py b/tests/misc/test_docker_workflow_native_multiarch.py
new file mode 100644
index 000000000..e5b390e36
--- /dev/null
+++ b/tests/misc/test_docker_workflow_native_multiarch.py
@@ -0,0 +1,50 @@
+from pathlib import Path
+
+REPO_ROOT = Path(__file__).resolve().parents[2]
+
+
+def _read_text(relative_path: str) -> str:
+ return (REPO_ROOT / relative_path).read_text(encoding="utf-8")
+
+
+def test_build_docker_workflow_uses_native_parallel_multiarch_jobs():
+ workflow = _read_text(".github/workflows/build-docker-image.yml")
+
+ assert "docker/setup-qemu-action" not in workflow
+ assert "ubuntu-24.04-arm" in workflow
+ assert "docker buildx imagetools create" in workflow
+ assert "push-by-digest=true" in workflow
+ assert "name-canonical=true" in workflow
+ assert '"${tag}-amd64"' not in workflow
+ assert '"${tag}-arm64"' not in workflow
+ assert "platforms: linux/amd64,linux/arm64" not in workflow
+
+
+def test_release_docker_workflow_uses_native_parallel_multiarch_jobs():
+ workflow = _read_text(".github/workflows/release.yml")
+
+ assert "docker/setup-qemu-action" not in workflow
+ assert "ubuntu-24.04-arm" in workflow
+ assert "docker buildx imagetools create" in workflow
+ assert "push-by-digest=true" in workflow
+ assert "name-canonical=true" in workflow
+ assert '"${tag}-amd64"' not in workflow
+ assert '"${tag}-arm64"' not in workflow
+ assert "platforms: linux/amd64,linux/arm64" not in workflow
+
+
+def test_build_docker_workflow_uses_manual_input_version_for_dispatch_tags():
+ workflow = _read_text(".github/workflows/build-docker-image.yml")
+
+ assert "type=raw,value=${{ github.event.inputs.version }}" in workflow
+ assert "type=ref,event=tag" in workflow
+
+
+def test_docker_workflows_normalize_image_names_to_lowercase():
+ build_workflow = _read_text(".github/workflows/build-docker-image.yml")
+ release_workflow = _read_text(".github/workflows/release.yml")
+
+ assert "tr '[:upper:]' '[:lower:]'" in build_workflow
+ assert "steps.image-name.outputs.image" in build_workflow
+ assert "tr '[:upper:]' '[:lower:]'" in release_workflow
+ assert "steps.image-name.outputs.image" in release_workflow