Skip to content

Commit 740d7e3

Browse files
committed
perf(ci): cross-compile validator images to skip QEMU on arm64
The GB200 UAT path builds validator images multi-arch (linux/amd64, linux/arm64) on an amd64 runner. Running go build inside the target-arch builder stage emulated the arm64 compile under QEMU (~15 min/image, ~53 min total). Pin the builder to $BUILDPLATFORM and cross-compile via $TARGETARCH so the compile stays native; the distroless stage is COPY-only and needs no emulation. Verified ~8x faster (1061s -> 126s) on a fork build probe. Signed-off-by: Nathan Hensley <nhensley@nvidia.com>
1 parent 6f9050b commit 740d7e3

3 files changed

Lines changed: 30 additions & 6 deletions

File tree

validators/conformance/Dockerfile

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,15 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
# Pin the builder stage to the build host's native arch ($BUILDPLATFORM) and
16+
# cross-compile to the requested $TARGETARCH with Go's own toolchain, rather
17+
# than running an emulated (QEMU) builder for foreign platforms. Multi-arch
18+
# GB200 UAT builds (linux/amd64,linux/arm64 on an amd64 runner) previously
19+
# executed the arm64 `go build` under emulation (~15 min); cross-compiling on
20+
# the native builder brings it back to native speed. The final distroless stage
21+
# is a COPY-only layer, so it needs no emulation for the target arch.
1522
ARG GO_VERSION=1.26.3
16-
FROM golang:${GO_VERSION}-bookworm AS builder
23+
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-bookworm AS builder
1724

1825
WORKDIR /src
1926
COPY go.mod go.sum ./
@@ -22,7 +29,8 @@ COPY pkg/ pkg/
2229
COPY validators/ validators/
2330
COPY recipes/ recipes/
2431

25-
RUN CGO_ENABLED=0 go build -o /out/conformance ./validators/conformance
32+
ARG TARGETOS TARGETARCH
33+
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -o /out/conformance ./validators/conformance
2634

2735
FROM nvcr.io/nvidia/distroless/static:v4.0.0@sha256:d90158b69e250d2018f32622b5c622925202ee97224a990a54b63811cb1e3d69
2836

validators/deployment/Dockerfile

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,15 @@
2020
# v1alpha1.Test AST and dispatches assert/error to kyverno-json's
2121
# checks.Check engine, so the external binary is no longer needed.
2222

23+
# Pin the builder stage to the build host's native arch ($BUILDPLATFORM) and
24+
# cross-compile to the requested $TARGETARCH with Go's own toolchain, rather
25+
# than running an emulated (QEMU) builder for foreign platforms. Multi-arch
26+
# GB200 UAT builds (linux/amd64,linux/arm64 on an amd64 runner) previously
27+
# executed the arm64 `go build` under emulation (~15 min); cross-compiling on
28+
# the native builder brings it back to native speed. The final distroless stage
29+
# is a COPY-only layer, so it needs no emulation for the target arch.
2330
ARG GO_VERSION=1.26.3
24-
FROM golang:${GO_VERSION}-bookworm AS builder
31+
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-bookworm AS builder
2532

2633
WORKDIR /src
2734
COPY go.mod go.sum ./
@@ -30,7 +37,8 @@ COPY pkg/ pkg/
3037
COPY recipes/ recipes/
3138
COPY validators/ validators/
3239

33-
RUN CGO_ENABLED=0 go build -o /out/deployment ./validators/deployment
40+
ARG TARGETOS TARGETARCH
41+
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -o /out/deployment ./validators/deployment
3442

3543
FROM nvcr.io/nvidia/distroless/static:v4.0.0@sha256:d90158b69e250d2018f32622b5c622925202ee97224a990a54b63811cb1e3d69
3644

validators/performance/Dockerfile

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,15 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
# Pin the builder stage to the build host's native arch ($BUILDPLATFORM) and
16+
# cross-compile to the requested $TARGETARCH with Go's own toolchain, rather
17+
# than running an emulated (QEMU) builder for foreign platforms. Multi-arch
18+
# GB200 UAT builds (linux/amd64,linux/arm64 on an amd64 runner) previously
19+
# executed the arm64 `go build` under emulation (~15 min); cross-compiling on
20+
# the native builder brings it back to native speed. The final distroless stage
21+
# is a COPY-only layer, so it needs no emulation for the target arch.
1522
ARG GO_VERSION=1.26.3
16-
FROM golang:${GO_VERSION}-bookworm AS builder
23+
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-bookworm AS builder
1724

1825
WORKDIR /src
1926
COPY go.mod go.sum ./
@@ -22,7 +29,8 @@ COPY pkg/ pkg/
2229
COPY validators/ validators/
2330
COPY recipes/ recipes/
2431

25-
RUN CGO_ENABLED=0 go build -o /out/performance ./validators/performance
32+
ARG TARGETOS TARGETARCH
33+
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -o /out/performance ./validators/performance
2634

2735
FROM nvcr.io/nvidia/distroless/static:v4.0.0@sha256:d90158b69e250d2018f32622b5c622925202ee97224a990a54b63811cb1e3d69
2836

0 commit comments

Comments
 (0)