Skip to content

fix: Use TARGETARCH for multi-platform builds#3

Merged
lexfrei merged 2 commits intocozystack:mainfrom
lexfrei:fix/arm64-support
Feb 12, 2026
Merged

fix: Use TARGETARCH for multi-platform builds#3
lexfrei merged 2 commits intocozystack:mainfrom
lexfrei:fix/arm64-support

Conversation

@lexfrei
Copy link

@lexfrei lexfrei commented Feb 10, 2026

Summary

Enable ARM64 and other architecture support by using Docker's automatic TARGETARCH variable instead of hardcoded GOARCH=amd64.

Problem

The current Dockerfile hardcodes ARG GOARCH=amd64, which prevents building images for other architectures like arm64 using docker buildx build --platform linux/arm64.

Solution

  • Use TARGETARCH which is automatically set by Docker buildx during multi-platform builds
  • Fall back to amd64 for backward compatibility with non-buildx builds

Changes

# Before
ARG GOARCH=amd64

# After
ARG TARGETARCH
ARG GOARCH=${TARGETARCH:-amd64}

Testing

Build for multiple platforms:

docker buildx build --platform linux/amd64,linux/arm64 -t kilo:test .

Related

Summary by CodeRabbit

  • Chores
    • Docker build updated to detect and use the target CPU architecture across build stages, including downloads of platform-specific components. This improves multi‑architecture build support and broadens platform compatibility without changing runtime behavior.

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]>
@gemini-code-assist
Copy link

Summary of Changes

Hello @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 amd64 builds, allowing for seamless multi-platform image creation, particularly for ARM64, while maintaining compatibility with existing build workflows.

Highlights

  • Multi-platform build support: Enabled support for building Docker images across various architectures, including ARM64, by dynamically determining the target architecture.
  • Flexible architecture detection: Replaced the static GOARCH=amd64 argument with TARGETARCH, which is automatically provided by Docker buildx during multi-platform builds.
  • Backward compatibility: Ensured that builds not using buildx or TARGETARCH will gracefully fall back to amd64 as the default architecture.

🧠 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
  • Dockerfile
    • Replaced ARG GOARCH=amd64 with ARG TARGETARCH and ARG GOARCH=${TARGETARCH:-amd64}.
    • Added a comment explaining the purpose of TARGETARCH.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@coderabbitai
Copy link

coderabbitai bot commented Feb 10, 2026

📝 Walkthrough

Walkthrough

The 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

Cohort / File(s) Summary
Multi-architecture Build
Dockerfile
Adds ARG TARGETARCH and replaces hardcoded GOARCH=amd64 with GOARCH=${TARGETARCH:-amd64} in both build stages; CNI plugins URL now references the dynamic GOARCH variable.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐇 I hopped into the Docker tree,
TARGETARCH whispered back to me,
GOARCH dances, no more static tune,
Builds for ARM, amd64 — a happy rune,
One Dockerfile, under the moon. 🌙

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: introducing TARGETARCH for multi-platform Docker builds instead of hardcoded GOARCH.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

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

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 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}

Choose a reason for hiding this comment

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

high

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}.

Copy link
Author

Choose a reason for hiding this comment

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

Good catch, fixed in 71eea82 — applied the same TARGETARCH pattern to the runtime stage.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

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 | 🔴 Critical

Bug: GOARCH will be empty in stage 2 during multi-platform builds.

Docker ARG values don't carry across stage boundaries. Since GOARCH is only derived from TARGETARCH in stage 1, the second stage's ARG GOARCH (line 12) will resolve to an empty string during buildx builds—causing lines 20–21 to expand to bin/linux//kg and bin/linux//kgctl.

You need to re-declare TARGETARCH and derive GOARCH in 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]>
@lexfrei
Copy link
Author

lexfrei commented Feb 10, 2026

Fixed the runtime stage issue flagged by @coderabbitai in 71eea82ARG GOARCH now uses ${TARGETARCH:-amd64} in both stages.

@coderabbitai
Copy link

coderabbitai bot commented Feb 10, 2026

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Read the Dockerfile to verify the fix in both stages
cat Dockerfile

Length of output: 1194


@lexfrei Thank you for the fix! I can confirm that the Dockerfile now correctly declares both ARG TARGETARCH and ARG GOARCH=${TARGETARCH:-amd64} in both the builder stage (lines 3-4) and the runtime stage (lines 11-12). This ensures that multi-platform builds will work correctly across both stages, with the proper fallback to amd64 for backward compatibility. Great work! 🎉


If you found this review helpful, would you consider giving us a shout-out on X?

Thank you for using CodeRabbit!

@lexfrei lexfrei self-assigned this Feb 11, 2026
Copy link
Member

@kvaps kvaps left a comment

Choose a reason for hiding this comment

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

Lgtm

@lexfrei lexfrei merged commit 062f897 into cozystack:main Feb 12, 2026
13 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.

2 participants