fix: Use TARGETARCH for multi-platform builds#3
Conversation
Replace hardcoded GOARCH=amd64 with TARGETARCH which is automatically set by Docker buildx during multi-platform builds. This enables building kilo images for arm64 and other architectures. The GOARCH variable now defaults to TARGETARCH when set, falling back to amd64 for backward compatibility with non-buildx builds. Co-Authored-By: Claude <[email protected]> Signed-off-by: Aleksei Sviridkin <[email protected]>
Summary of ChangesHello @lexfrei, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the Docker image build process by introducing dynamic architecture detection. It resolves the limitation of hardcoded Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
📝 WalkthroughWalkthroughThe Dockerfile now accepts a TARGETARCH build argument and sets GOARCH dynamically to ${TARGETARCH:-amd64} in both stages, replacing the prior hardcoded GOARCH=amd64. The CNI plugins download URL is updated to use the derived GOARCH value. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
No actionable comments were generated in the recent review. 🎉 Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Code Review
This pull request aims to enable multi-platform builds by using Docker's TARGETARCH variable. The change correctly updates the first stage of the Dockerfile to use TARGETARCH for downloading CNI plugins. However, the change is incomplete as the second stage of the Dockerfile is not updated, which will cause buildx builds to fail. I've left a specific comment with details on how to fix this.
| ARG GOARCH=amd64 | ||
| # TARGETARCH is automatically set by Docker buildx for multi-platform builds | ||
| ARG TARGETARCH | ||
| ARG GOARCH=${TARGETARCH:-amd64} |
There was a problem hiding this comment.
This is a good change for supporting multi-platform builds in the cni stage. However, the second stage of this Dockerfile also depends on the architecture but has not been updated. The ARG GOARCH on line 12 is declared without a value, so when using buildx it will be empty. This will cause the COPY commands on lines 20-21 to fail.
To fully enable multi-platform builds as intended, you should apply the same pattern to the second build stage by adding ARG TARGETARCH and setting ARG GOARCH=${TARGETARCH:-amd64}.
There was a problem hiding this comment.
Good catch, fixed in 71eea82 — applied the same TARGETARCH pattern to the runtime stage.
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
Dockerfile (1)
12-12:⚠️ Potential issue | 🔴 CriticalBug:
GOARCHwill be empty in stage 2 during multi-platform builds.Docker
ARGvalues don't carry across stage boundaries. SinceGOARCHis only derived fromTARGETARCHin stage 1, the second stage'sARG GOARCH(line 12) will resolve to an empty string duringbuildxbuilds—causing lines 20–21 to expand tobin/linux//kgandbin/linux//kgctl.You need to re-declare
TARGETARCHand deriveGOARCHin stage 2 as well:Proposed fix
FROM $FROM -ARG GOARCH +ARG TARGETARCH +ARG GOARCH=${TARGETARCH:-amd64} ARG ALPINE_VERSION=v3.20
The runtime stage also references GOARCH for copying pre-built binaries (bin/linux/$GOARCH/kg). Without TARGETARCH, buildx leaves GOARCH empty, breaking the COPY paths. Co-Authored-By: Claude <[email protected]> Signed-off-by: Aleksei Sviridkin <[email protected]>
|
Fixed the runtime stage issue flagged by @coderabbitai in 71eea82 — |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain🏁 Script executed: Length of output: 1194
If you found this review helpful, would you consider giving us a shout-out on X? Thank you for using CodeRabbit! |
Summary
Enable ARM64 and other architecture support by using Docker's automatic
TARGETARCHvariable instead of hardcodedGOARCH=amd64.Problem
The current Dockerfile hardcodes
ARG GOARCH=amd64, which prevents building images for other architectures likearm64usingdocker buildx build --platform linux/arm64.Solution
TARGETARCHwhich is automatically set by Docker buildx during multi-platform buildsamd64for backward compatibility with non-buildx buildsChanges
Testing
Build for multiple platforms:
docker buildx build --platform linux/amd64,linux/arm64 -t kilo:test .Related
Summary by CodeRabbit