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: Directly compile cli binary in dockerfile #14

Merged
merged 2 commits into from
Mar 31, 2025

Conversation

adityachoudhari26
Copy link
Contributor

@adityachoudhari26 adityachoudhari26 commented Mar 31, 2025

Summary by CodeRabbit

  • Chores
    • Streamlined the container build process to minimize external dependencies and simplify application production, ensuring a more efficient environment for deployments.
    • Introduced a new GitHub Actions workflow to automate Docker build testing, enhancing the reliability of the build process.

Copy link

coderabbitai bot commented Mar 31, 2025

Walkthrough

The Dockerfile has been updated to simplify the build process. The base image has changed from alpine:3.19 to golang:1.24-alpine. The multi-step process involving external dependency installation, architecture checks, and binary downloads has been replaced with a process that directly copies the source code into the container and builds it using Go (via the go build command). Additionally, the ARG CLI_VERSION has been removed, and a working directory has been set. A new GitHub Actions workflow has also been added to automate Docker build testing.

Changes

File Change Summary
docker/Dockerfile - Base image updated from alpine:3.19 to golang:1.24-alpine
- Removed ARG CLI_VERSION
- Set working directory with WORKDIR /app
- Replaced multi-step process with copying source and building using go build -o /usr/local/bin/ctrlc ./cmd/ctrlc
.github/workflows/test-docker-build.yaml - New workflow added: name: Test Docker Build
- Automates Docker build testing on pull requests and manual triggers
- Configures concurrency and job steps for building Docker images

Sequence Diagram(s)

sequenceDiagram
    participant Dev as Developer
    participant DF as Dockerfile (Builder Stage)
    participant GT as Go Toolchain
    participant FS as Final Stage
    participant CNT as Container

    Dev->>DF: Initiate Docker build
    DF->>DF: Set WORKDIR (/app) and copy source code
    DF->>GT: Execute go build (build binary)
    GT-->>DF: Return built binary
    DF->>FS: Copy binary to final stage
    FS->>CNT: Set entrypoint and command
    CNT-->>Dev: Run updated container
Loading

Poem

I’m a rabbit with a techy beat,
Hopping through changes oh so neat,
Go-build magic, clean and bright,
Our Docker world is set just right,
With every hop, I cheer in flight!
🐇✨


🪧 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 plan to trigger planning for file edits and PR creation.
  • @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: 0

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

3-3: Setting the Working Directory
Using WORKDIR /app helps organize the build context. Please ensure that a proper .dockerignore file is in place to prevent copying unnecessary files into the image.


5-5: Copying Source Files
The COPY . . statement effectively brings your source code into the container. Verify that your .dockerignore file is configured correctly to avoid including build caches or sensitive files.


7-8: Direct Binary Compilation Command
Compiling the binary with RUN go build -o /usr/local/bin/ctrlc ./cmd/ctrlc && \ chmod +x /usr/local/bin/ctrlc streamlines the build process. One note: Go-built binaries are typically executable by default, so the additional chmod +x may be redundant. Consider verifying if this extra step is needed.

Suggested Diff (if deemed unnecessary):

- RUN go build -o /usr/local/bin/ctrlc ./cmd/ctrlc && \
-   chmod +x /usr/local/bin/ctrlc
+ RUN go build -o /usr/local/bin/ctrlc ./cmd/ctrlc
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2ba84db and 7179e6d.

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

1-1: Builder Base Image Update
Changing the builder image to golang:1.24-alpine is a solid improvement. This base image ensures that the Go toolchain is available and tailored for building Go applications.


10-15: Final Stage and Container Execution
The final stage uses alpine:3.19 to provide a lean runtime environment, which is good for reducing image size. The binary is copied over correctly, and setting the ENTRYPOINT along with CMD ["--help"] clearly defines the container's behavior. Ensure that the final image meets all runtime dependency requirements for the binary.

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: 0

🧹 Nitpick comments (2)
.github/workflows/test-docker-build.yaml (2)

15-22: Jobs Block is Well-Structured with a Minor Formatting Issue.

The jobs configuration for the docker job is solid. However, note that line 18 appears to contain trailing spaces. Please remove them to comply with YAML linting rules.

🧰 Tools
🪛 YAMLlint (1.35.1)

[error] 18-18: trailing spaces

(trailing-spaces)


37-45: Build-Only Step is Configured Well with a Minor Formatting Suggestion.

The "Build Only" step correctly utilizes docker/build-push-action@v6 to build the image without pushing. Ensure that the file ends with a newline (line 45 is missing one) to meet YAML formatting standards.

🧰 Tools
🪛 YAMLlint (1.35.1)

[error] 45-45: no new line character at the end of file

(new-line-at-end-of-file)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7179e6d and 0f78ad4.

📒 Files selected for processing (1)
  • .github/workflows/test-docker-build.yaml (1 hunks)
🧰 Additional context used
🪛 YAMLlint (1.35.1)
.github/workflows/test-docker-build.yaml

[error] 18-18: trailing spaces

(trailing-spaces)


[error] 45-45: no new line character at the end of file

(new-line-at-end-of-file)

🔇 Additional comments (8)
.github/workflows/test-docker-build.yaml (8)

1-2: Workflow Name is Clear and Concise.

The title "Test Docker Build" effectively describes the purpose of this workflow.


3-6: Concurrency Configuration Looks Good.

The concurrency block is correctly set up to group workflow runs by branch and cancel in-progress jobs.


7-9: Global Permissions are Configured Appropriately.

The permissions (contents: read) are properly defined at the top level.


10-14: Trigger Events are Defined Correctly.

The workflow is triggered on pull requests to the main branch and supports manual dispatch; this configuration meets the PR objectives.


23-26: Matrix Strategy Setup is Clear and Correct.

The defined matrix (platform: [linux/amd64]) is straightforward and meets the build requirements.


27-30: Checkout Step is Configured Correctly.

The workflow correctly uses actions/checkout@v4 to fetch the repository code.


31-33: QEMU Setup is Implemented Properly.

The QEMU setup with docker/setup-qemu-action@v3 ensures cross-platform compatibility.


34-36: Docker Buildx Setup is Correctly Configured.

The step using docker/setup-buildx-action@v3 properly sets up Docker Buildx for the build process.

@adityachoudhari26 adityachoudhari26 merged commit 22a6300 into main Mar 31, 2025
2 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.

1 participant