Skip to content

ci: build multi-arch images with native Go builder#420

Open
ranxi2001 wants to merge 1 commit into
volcano-sh:mainfrom
ranxi2001:ci/native-build-platform-images
Open

ci: build multi-arch images with native Go builder#420
ranxi2001 wants to merge 1 commit into
volcano-sh:mainfrom
ranxi2001:ci/native-build-platform-images

Conversation

@ranxi2001

Copy link
Copy Markdown
Contributor

What type of PR is this?

/kind enhancement

What this PR does / why we need it:

This PR optimizes the multi-arch image build path by running the Go builder stages on $BUILDPLATFORM while keeping TARGETOS / TARGETARCH for cross-compilation.

On x64 GitHub-hosted runners, the previous Dockerfiles ran the linux/arm64 Go builder stage under QEMU. In the release-image benchmark recorded in #419, the workloadmanager linux/arm64 Go build was the dominant cost. This change keeps the produced images multi-arch, but avoids running the Go compiler through arm64 emulation.

Scope of this first PR:

  • Change only the Go builder stage platform in docker/Dockerfile, docker/Dockerfile.router, and docker/Dockerfile.picod.
  • Do not change release triggers, image tags, Helm chart metadata, matrix builds, or buildx cache behavior.
  • Leave the Karmada-style prebuild pipeline, PicoD runtime-layer optimization, and matrix/cache improvements as follow-ups tracked by Optimize multi-arch image build time in the release workflow #419.

This PR does not conflict with #416 because #416 changes the release workflow metadata and Helm chart version handling, while this PR only changes Dockerfile builder stages. It is also separate from #264, which adjusts workloadmanager build entrypoints and Makefile flow.

Which issue(s) this PR fixes:
Refs #419

Special notes for your reviewer:

  • Scope: Dockerfile-only build performance optimization for multi-arch image builds.
  • Changed files: docker/Dockerfile, docker/Dockerfile.router, docker/Dockerfile.picod.
  • Validation:
    • git diff --check upstream/main...HEAD
    • make build-all
    • docker buildx build --builder agentcube-day39 --platform linux/amd64,linux/arm64 -f docker/Dockerfile --target builder --progress=plain .
    • docker buildx build --builder agentcube-day39 --platform linux/amd64,linux/arm64 -f docker/Dockerfile.router --target builder --progress=plain .
    • docker buildx build --builder agentcube-day39 --platform linux/amd64,linux/arm64 -f docker/Dockerfile.picod --target builder --progress=plain .
    • Fork push validation on ranxi2001:ci/native-build-platform-images: 9/9 workflows passed.
  • AI assistance: Used Codex to inspect the build path, compare benchmark logs, and prepare this PR. I reviewed and validated the changes.

Does this PR introduce a user-facing change?:

NONE

Signed-off-by: ranxi2001 <ranxi169@163.com>
Copilot AI review requested due to automatic review settings July 3, 2026 07:32
@volcano-sh-bot volcano-sh-bot added the kind/enhancement New feature or request label Jul 3, 2026
@volcano-sh-bot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign yaozengzeng for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the builder stages in docker/Dockerfile, docker/Dockerfile.picod, and docker/Dockerfile.router to use --platform=$BUILDPLATFORM for multi-architecture support. The feedback recommends optimizing the Docker build cache by moving the platform-specific build arguments (ARG TARGETOS and ARG TARGETARCH) to after the go mod download step, which prevents dependency download cache invalidation during multi-platform builds.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread docker/Dockerfile
@@ -1,5 +1,5 @@
# Multi-stage build for workloadmanager
FROM golang:1.26.4-alpine AS builder
FROM --platform=$BUILDPLATFORM golang:1.26.4-alpine AS builder

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To fully optimize the multi-architecture build cache, declare the platform-specific build arguments ARG TARGETOS and ARG TARGETARCH after the go mod download step (just before the go build step).

Currently, because they are declared at the top of the Dockerfile (lines 5-6), any change in the target platform (e.g., building for amd64 and arm64 simultaneously) will invalidate the cache for all subsequent steps, including go mod download. This forces Go to download dependencies twice (once for each architecture).

Moving these ARG declarations to just before the go build step allows the go mod download layer to be cached and shared across all target platforms.

Comment thread docker/Dockerfile.picod
@@ -1,5 +1,5 @@
# Build stage
FROM golang:1.26.4 AS builder
FROM --platform=$BUILDPLATFORM golang:1.26.4 AS builder

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To fully optimize the multi-architecture build cache, declare the platform-specific build arguments ARG TARGETOS and ARG TARGETARCH after the go mod download step (just before the go build step).

Currently, because they are declared at the top of the Dockerfile (lines 5-6), any change in the target platform (e.g., building for amd64 and arm64 simultaneously) will invalidate the cache for all subsequent steps, including go mod download. This forces Go to download dependencies twice (once for each architecture).

Moving these ARG declarations to just before the go build step allows the go mod download layer to be cached and shared across all target platforms.

Comment thread docker/Dockerfile.router
@@ -1,5 +1,5 @@
# Multi-stage build for agentcube-router
FROM golang:1.26.4-alpine AS builder
FROM --platform=$BUILDPLATFORM golang:1.26.4-alpine AS builder

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To fully optimize the multi-architecture build cache, declare the platform-specific build arguments ARG TARGETOS and ARG TARGETARCH after the go mod download step (just before the go build step).

Currently, because they are declared at the top of the Dockerfile (lines 5-6), any change in the target platform (e.g., building for amd64 and arm64 simultaneously) will invalidate the cache for all subsequent steps, including go mod download. This forces Go to download dependencies twice (once for each architecture).

Moving these ARG declarations to just before the go build step allows the go mod download layer to be cached and shared across all target platforms.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR optimizes multi-arch image builds by running the Go builder stage on $BUILDPLATFORM (native to the runner) while still compiling binaries for TARGETOS/TARGETARCH, avoiding QEMU-emulated Go compilation during linux/arm64 builds.

Changes:

  • Set the builder stage in all three image Dockerfiles to FROM --platform=$BUILDPLATFORM ... AS builder.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
docker/Dockerfile Switches workloadmanager builder stage to run on $BUILDPLATFORM.
docker/Dockerfile.router Switches router builder stage to run on $BUILDPLATFORM.
docker/Dockerfile.picod Switches PicoD builder stage to run on $BUILDPLATFORM.

Comment thread docker/Dockerfile
Comment on lines 1 to +2
# Multi-stage build for workloadmanager
FROM golang:1.26.4-alpine AS builder
FROM --platform=$BUILDPLATFORM golang:1.26.4-alpine AS builder
Comment thread docker/Dockerfile.router
Comment on lines 1 to +2
# Multi-stage build for agentcube-router
FROM golang:1.26.4-alpine AS builder
FROM --platform=$BUILDPLATFORM golang:1.26.4-alpine AS builder
Comment thread docker/Dockerfile.picod
Comment on lines 1 to +2
# Build stage
FROM golang:1.26.4 AS builder
FROM --platform=$BUILDPLATFORM golang:1.26.4 AS builder
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 58.50%. Comparing base (524e55e) to head (0f58bdb).
⚠️ Report is 162 commits behind head on main.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@             Coverage Diff             @@
##             main     #420       +/-   ##
===========================================
+ Coverage   47.57%   58.50%   +10.93%     
===========================================
  Files          30       36        +6     
  Lines        2819     3463      +644     
===========================================
+ Hits         1341     2026      +685     
+ Misses       1338     1228      -110     
- Partials      140      209       +69     
Flag Coverage Δ
unittests 58.50% <ø> (+10.93%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/enhancement New feature or request size/XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants