Skip to content

Fix cross-compilation of native modules in Dockerfile#66

Merged
djannot merged 1 commit intokagent-dev:mainfrom
syn-zhu:fix/targetplatform-builder
Mar 9, 2026
Merged

Fix cross-compilation of native modules in Dockerfile#66
djannot merged 1 commit intokagent-dev:mainfrom
syn-zhu:fix/targetplatform-builder

Conversation

@syn-zhu
Copy link
Contributor

@syn-zhu syn-zhu commented Mar 4, 2026

Summary

  • Change builder stage from $BUILDPLATFORM to $TARGETPLATFORM so that native Node.js modules (better-sqlite3) are compiled for the target architecture

Problem

When building on arm64 (e.g., Apple Silicon) targeting amd64, $BUILDPLATFORM causes node-gyp to compile the better-sqlite3 C extension for arm64. The resulting binary fails at runtime on amd64 nodes with exec format error or shared object errors.

Fix

One-line change: FROM --platform=$TARGETPLATFORM instead of FROM --platform=$BUILDPLATFORM in the builder stage. This ensures native modules match the target architecture. The tradeoff is slower cross-arch builds (QEMU emulation) but correct binaries.

Fixes #65

🤖 Generated with Claude Code

Change builder stage from $BUILDPLATFORM to $TARGETPLATFORM so that
native Node.js modules (better-sqlite3) are compiled for the target
architecture rather than the build machine's architecture.

With $BUILDPLATFORM, cross-compilation scenarios (e.g., arm64 Mac
building for amd64 clusters) produce native binaries for the wrong
architecture, causing runtime failures.

Fixes kagent-dev#65

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Simon Zhu <simon.zhu@mongodb.com>
@syn-zhu syn-zhu force-pushed the fix/targetplatform-builder branch from b3b326f to 8c27ff1 Compare March 5, 2026 05:14
@djannot djannot merged commit 7618dc4 into kagent-dev:main Mar 9, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dockerfile builder stage uses $BUILDPLATFORM, breaking cross-compilation of native modules

2 participants