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

Update Dockerfile #351

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Update Dockerfile #351

wants to merge 1 commit into from

Conversation

Alphena-EK
Copy link

This PR improves the Dockerfile for Initia, ensuring better compatibility, security, and efficiency. Key changes:

Fixed architecture handling (GOARCH) for multi-arch builds.
Added library verification for downloaded dependencies.
Optimized build process with better linker flags.
Enhanced security by running as a non-root user.
Reduced image size by removing unnecessary packages.

@Alphena-EK Alphena-EK requested a review from a team as a code owner February 26, 2025 16:00
Copy link

coderabbitai bot commented Feb 26, 2025

📝 Walkthrough

Walkthrough

This pull request updates the Dockerfile for a Go project. The changes set the GOARCH argument based on TARGETARCH, improve the mimalloc installation command with clearer formatting and line continuations, adjust architecture-specific library handling (now using a dedicated ARCH variable), and add hash verification for downloaded libraries. The build command is updated with CGO_ENABLED=1 and -static-libgcc, while user/group creation and port exposure commands are refined. No modifications were made to exported or public entities.

Changes

File(s) Change Summary
Dockerfile - Set GOARCH from TARGETARCH.
- Reformatted mimalloc installation with line continuations.
- Adjusted architecture-specific library logic (using ARCH) and enabled hash verification.
- Updated build command to include CGO_ENABLED=1 and -static-libgcc.
- Refined user/group creation and consolidated port exposure.
- Clarified the application run command.

Sequence Diagram(s)

sequenceDiagram
    participant B as Builder
    participant D as Dockerfile
    participant G as Go Compiler

    B->>D: Start build with TARGETARCH
    D->>D: Set GOARCH based on TARGETARCH
    D->>D: Reformat mimalloc install & adjust lib handling with hash checks
    D->>G: Build Go project with CGO_ENABLED=1 and -static-libgcc
    G-->>D: Return build results
    D->>D: Create user/group and configure port exposure
    D->>B: Run application with updated command
Loading

Possibly related PRs

Suggested reviewers

  • beer-1

Poem

Oh, how I hop with joyful cheer,
A Docker tweak has made things clear.
Arch aligned and builds so fine,
Libraries checked with code divine.
A happy bunny sings: "Build and shine!" 🐇✨


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:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • 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.
  • @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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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

@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 (2)
Dockerfile (2)

18-21: Mimalloc Installation Process
The mimalloc installation command chains several operations (cloning, building, and installing) in one RUN instruction. While this is concise, consider pinning the repository to a specific commit or tag for deterministic builds.


61-63: Defined Start Command for the Application
The CMD instruction to run the application (displaying the version) is clear. As a future enhancement, consider an entrypoint script if additional runtime configuration becomes necessary.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f5cd97d and cd53717.

📒 Files selected for processing (1)
  • Dockerfile (2 hunks)
🔇 Additional comments (6)
Dockerfile (6)

6-6: Architecture Build Argument Mapping
Mapping the TARGETARCH argument to GOARCH is correctly implemented to support multi-architecture builds. This ensures that subsequent build steps use the appropriate architecture.


8-9: Pinned MoveVM Version
The MoveVM version is explicitly set to v0.6.1, which ensures reproducibility. Verify whether future updates might require an update here.


39-44: Enhanced Build Command with Additional Linker Flags
The updated build command now enables CGO, applies appropriate build tags, and includes additional linker flags (like -static-libgcc) to improve performance and binary consistency. Ensure that the quoted -extldflags value is correctly processed by the build system.


48-50: Security Enhancement via Non-Root User Creation
Switching to a non-root user (initia) by creating a dedicated group and user enhances security and aligns with container best practices.


53-55: Cross-Stage Binary Transfer
Copying the built binary from the Go builder stage to the final image is correctly performed using multi-stage builds, which helps reduce the final image size.


58-60: Consolidated Port Exposure
Exposing all necessary ports in a single EXPOSE command improves clarity and conciseness.

Comment on lines +24 to 38
# Determine architecture-specific libraries
RUN set -eux; \
case "${TARGETARCH}" in \
"amd64") export GOARCH="amd64"; ARCH="x86_64";; \
"arm64") export GOARCH="arm64"; ARCH="aarch64";; \
"amd64") ARCH="x86_64";; \
"arm64") ARCH="aarch64";; \
*) echo "Unsupported architecture: ${TARGETARCH}"; exit 1;; \
esac; \
echo "Using GOARCH=${GOARCH} and ARCH=${ARCH}"; \
wget -O /lib/libmovevm_muslc.${ARCH}.a https://github.com/initia-labs/movevm/releases/download/${LIBMOVEVM_VERSION}/libmovevm_muslc.${ARCH}.a; \
wget -O /lib/libcompiler_muslc.${ARCH}.a https://github.com/initia-labs/movevm/releases/download/${LIBMOVEVM_VERSION}/libcompiler_muslc.${ARCH}.a; \
cp /lib/libmovevm_muslc.${ARCH}.a /lib/libmovevm_muslc.a; \
cp /lib/libcompiler_muslc.${ARCH}.a /lib/libcompiler_muslc.a

# Verify the library hashes (optional, uncomment if needed)
# RUN sha256sum /lib/libmovevm_muslc.${ARCH}.a | grep ...
# RUN sha256sum /lib/libcompiler_muslc.${ARCH}.a | grep ...
cp /lib/libcompiler_muslc.${ARCH}.a /lib/libcompiler_muslc.a; \
sha256sum /lib/libmovevm_muslc.${ARCH}.a | grep EXPECTED_HASH; \
sha256sum /lib/libcompiler_muslc.${ARCH}.a | grep EXPECTED_HASH

Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Architecture-Specific Library Download & Verification
The script properly sets the ARCH variable based on TARGETARCH and downloads the corresponding libraries. It also performs hash verification via sha256sum ... | grep EXPECTED_HASH. Note that "EXPECTED_HASH" is currently a placeholder—ensure that it is replaced with a defined value (or set as an environment variable) for effective integrity checks.

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.

1 participant