Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add ARM64 support for Docker builds #4164

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

DeVikingMark
Copy link

Fixes #4128

Changes:

  • Modified Dockerfile to use $TARGETPLATFORM instead of $BUILDPLATFORM
  • Updated base image to support multi-platform builds
  • Added support for ARM64 architecture

This PR enables Docker builds for ARM64 architecture while maintaining compatibility with AMD64.

@DeVikingMark DeVikingMark requested a review from a team as a code owner December 27, 2024 01:01
@DeVikingMark DeVikingMark requested review from rootulp and rach-id and removed request for a team December 27, 2024 01:01
Copy link
Contributor

coderabbitai bot commented Dec 27, 2024

📝 Walkthrough

Walkthrough

The pull request introduces a comprehensive modification to the Docker build process, focusing on multi-platform image support. The changes involve updating the GitHub Actions workflow and Dockerfile to enable building and pushing Docker images for both linux/amd64 and linux/arm64 architectures. The workflow now uses the docker/build-push-action@v5 to streamline the multi-platform build process, while the Dockerfile adjusts the base image and platform specifications to support cross-architecture builds.

Changes

File Change Summary
.github/workflows/reusable_dockerfile_pipeline.yml Added multi-platform build step using docker/build-push-action@v5
docker/Dockerfile Updated base builder image from golang:1.23.1-alpine3.20 to golang:1.21-alpine
Changed platform specification from $BUILDPLATFORM to $TARGETPLATFORM

Sequence Diagram

sequenceDiagram
    participant GHA as GitHub Actions
    participant Docker as Docker Build System
    participant Registry as Container Registry
    
    GHA->>Docker: Initiate multi-platform build
    Docker->>Docker: Build for amd64
    Docker->>Docker: Build for arm64
    Docker->>Registry: Push images
Loading

Assessment against linked issues

Objective Addressed Explanation
Publish Docker images for arm64 [#4128]
Investigate multi-architecture image support
Enable cross-platform compatibility

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
docker/Dockerfile (1)

Line range hint 6-8: Consider documenting platform support.

Since we're adding ARM64 support, it would be helpful to document the supported platforms in the Dockerfile comments.

Add this documentation:

 # Separating the builder and runtime image allows the runtime image to be
 # considerably smaller because it doesn't need to have Golang installed.
+# Supported platforms:
+# - linux/amd64
+# - linux/arm64
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 05d1acd and 90e199b.

📒 Files selected for processing (2)
  • .github/workflows/reusable_dockerfile_pipeline.yml (1 hunks)
  • docker/Dockerfile (1 hunks)
🧰 Additional context used
🪛 actionlint (1.7.4)
.github/workflows/reusable_dockerfile_pipeline.yml

5-5: workflow is sequence node but mapping node is expected

(syntax-check)


5-5: "on" section is missing in workflow

(syntax-check)


5-5: "jobs" section is missing in workflow

(syntax-check)

🔇 Additional comments (4)
.github/workflows/reusable_dockerfile_pipeline.yml (2)

5-13: LGTM! Multi-platform build configuration looks correct.

The build step is properly configured for multi-architecture support:

  • Uses the latest stable version of docker/build-push-action
  • Correctly specifies both linux/amd64 and linux/arm64 platforms
  • Properly inherits tags and labels from previous steps
🧰 Tools
🪛 actionlint (1.7.4)

5-5: workflow is sequence node but mapping node is expected

(syntax-check)


5-5: "on" section is missing in workflow

(syntax-check)


5-5: "jobs" section is missing in workflow

(syntax-check)


1-3: Verify the removed AMD64-specific build steps.

Please ensure that any platform-specific environment variables or build arguments from the removed AMD64 build steps are now properly handled in the new multi-platform configuration.

✅ Verification successful

Multi-platform build configuration is properly set up

The verification shows that:

  1. The old AMD64-specific build steps have been successfully replaced with a proper multi-platform configuration using docker/build-push-action@v5
  2. The platforms are correctly configured to build for both linux/amd64 and linux/arm64
  3. No platform-specific build arguments or environment variables are present in the workflow, suggesting a unified build configuration
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any remaining platform-specific configurations
rg -i "amd64|x86_64" .github/workflows/

Length of output: 232


Script:

#!/bin/bash
# Let's check the complete context of the platform configuration
rg -B5 -A5 "platforms:" .github/workflows/reusable_dockerfile_pipeline.yml

# Also check for any build arguments or environment variables that might be platform-specific
rg -i "build-arg|env" .github/workflows/reusable_dockerfile_pipeline.yml

Length of output: 427

docker/Dockerfile (2)

Line range hint 41-77: LGTM! Runtime stage configuration is solid.

The runtime stage is well-configured for multi-arch support:

  • Uses Alpine 3.19 which supports both AMD64 and ARM64
  • Follows security best practices
  • Properly configured for all required ports

Line range hint 22-40: Verify ARM64 build compatibility.

The build configuration looks correct for multi-arch support, but let's verify:

  1. The use of $TARGETPLATFORM is appropriate for cross-compilation
  2. CGO_ENABLED=0 is correct for cross-platform builds
  3. The build dependencies should work on ARM64
✅ Verification successful

ARM64 build configuration is correctly set up

The Dockerfile is properly configured for multi-architecture builds:

  1. Uses --platform=$TARGETPLATFORM with golang base image
  2. Correctly sets CGO_ENABLED=0 which is required for cross-compilation
  3. Properly uses TARGETOS and TARGETARCH build arguments for Go compilation
  4. All build dependencies (gcc, git, linux-headers, make, musl-dev) are architecture-agnostic and available on Alpine Linux for ARM64
  5. Uses multi-stage build with Alpine Linux base images that support ARM64

The build configuration follows best practices for multi-architecture Docker builds and will work correctly on ARM64 platforms.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if there are any architecture-specific build dependencies or configurations
rg -i "amd64|arm64|x86_64|aarch64" docker/

Length of output: 44


Script:

#!/bin/bash
# Let's check the Dockerfile and related files more thoroughly
cat docker/Dockerfile

# Check if there are any architecture-specific make targets or build flags
fd Makefile --exec cat {}

# Check for any platform-specific build configurations
rg -i "platform|arch|target" docker/

Length of output: 17099

@@ -19,7 +19,7 @@ ARG UPGRADE_HEIGHT_DELAY
# Ignore hadolint rule because hadolint can't parse the variable.
# See https://github.com/hadolint/hadolint/issues/339
# hadolint ignore=DL3006
FROM --platform=$BUILDPLATFORM ${BUILDER_IMAGE} AS builder
FROM --platform=$TARGETPLATFORM golang:1.21-alpine AS builder
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Critical: Review base image configuration.

Several issues need attention in the base image configuration:

  1. The previous version 1.23.1 doesn't exist (Go 1.21 is current stable)
  2. Using non-specific patch version (1.21 vs 1.21.x) could lead to build inconsistency
  3. Removed explicit registry reference (docker.io/) might affect availability

Apply this fix:

-FROM --platform=$TARGETPLATFORM golang:1.21-alpine AS builder
+FROM --platform=$TARGETPLATFORM docker.io/golang:1.21.5-alpine AS builder
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
FROM --platform=$TARGETPLATFORM golang:1.21-alpine AS builder
FROM --platform=$TARGETPLATFORM docker.io/golang:1.21.5-alpine AS builder

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Publish docker images for arm64
1 participant