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

feat: use alpine as base image #1106

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

feat: use alpine as base image #1106

wants to merge 8 commits into from

Conversation

de-sh
Copy link
Contributor

@de-sh de-sh commented Jan 16, 2025

Fixes #XXXX.

Description

This is just a proposal, the alpine image is only ~40MB smaller on disk


This PR has:

  • been tested to ensure log ingestion and log query works.
  • added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.
  • added documentation for new or modified features or behaviors.

Summary by CodeRabbit

  • Chores
    • Streamlined the container environment to reduce image size and improve build efficiency by transitioning to Alpine-based images.
    • Adjusted the installation of build dependencies to further optimize the deployment process.

@coveralls
Copy link

coveralls commented Jan 16, 2025

Pull Request Test Coverage Report for Build 12852443457

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 12.714%

Totals Coverage Status
Change from base Build 12850824320: 0.0%
Covered Lines: 2459
Relevant Lines: 19341

💛 - Coveralls

@de-sh
Copy link
Contributor Author

de-sh commented Jan 17, 2025

As can be noticed from the ci runs, alpine is equally suitable base image for parseable

@de-sh de-sh closed this Feb 16, 2025
@de-sh de-sh deleted the alpine branch February 16, 2025 16:48
@de-sh de-sh restored the alpine branch February 16, 2025 16:48
@de-sh de-sh reopened this Feb 16, 2025
Signed-off-by: Devdutt Shenoi <[email protected]>
Copy link

coderabbitai bot commented Feb 16, 2025

Walkthrough

This pull request updates the Dockerfile by switching both the build and final stage base images to Alpine-based images. The builder stage now uses rust:1.84.0-alpine instead of rust:1.84.0-bookworm, and installs additional build dependencies (build-base, git, and bash) via apk. In the final stage, the previous distroless Debian image has been replaced with scratch, and the command to run the application has been updated to ENTRYPOINT ["/parseable"].

Changes

File Change Summary
Dockerfile Updated builder base image to rust:1.84.0-alpine (from rust:1.84.0-bookworm), added apk commands to install build dependencies. Changed final stage base to scratch (from gcr.io/distroless/cc-debian12:latest). Updated command to run application.
Dockerfile.debug Updated builder base image to rust:1.84.0-alpine (from rust:1.84.0-bookworm), added apk commands to install build dependencies. Changed final stage base to alpine:latest (from docker.io/debian:bookworm-slim). Updated command for installing curl.

Sequence Diagram(s)

sequenceDiagram
    participant Dev as Developer
    participant BS as Builder Stage (Alpine Rust)
    participant FS as Final Stage (Scratch)

    Dev->>BS: Initiate Docker build
    BS->>BS: Install dependencies (apk add build-base, git, bash)
    BS->>FS: Copy static binary to final image
    FS->>FS: Execute application (ENTRYPOINT)
Loading

Poem

Hi there, I'm a bunny with a twist,
Hopping through changes that can't be missed.
From heavy builds to Alpine light,
My Docker playground feels just right.
With a twitch of my nose and a joyful leap,
I celebrate this update—hop, skip, and peep!


🪧 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. (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.

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.

@de-sh de-sh marked this pull request as ready for review February 16, 2025 16:51
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 (1)
Dockerfile (1)

37-38: Switch Final Stage to Alpine Minimal Runtime
Changing the final stage base image to alpine:latest effectively minimizes the runtime image. However, ensure that the binary copied from the builder stage is either statically linked or fully compatible with Alpine’s musl libc, as incompatibilities may lead to runtime issues.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 523ecc7 and 65db3a8.

📒 Files selected for processing (1)
  • Dockerfile (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (10)
  • GitHub Check: Build Default x86_64-pc-windows-msvc
  • GitHub Check: Build Default aarch64-apple-darwin
  • GitHub Check: Build Kafka aarch64-apple-darwin
  • GitHub Check: Build Default x86_64-apple-darwin
  • GitHub Check: Build Kafka x86_64-unknown-linux-gnu
  • GitHub Check: Quest Smoke and Load Tests for Standalone deployments
  • GitHub Check: Build Default aarch64-unknown-linux-gnu
  • GitHub Check: Quest Smoke and Load Tests for Distributed deployments
  • GitHub Check: Build Default x86_64-unknown-linux-gnu
  • GitHub Check: coverage
🔇 Additional comments (2)
Dockerfile (2)

17-17: Adopt Alpine-based Rust Builder Image
Switching the builder stage to use rust:1.84.0-alpine helps significantly reduce image size. Please verify that all Rust crates and native dependencies compile correctly in the Alpine environment, as Alpine’s musl libc can sometimes have subtle differences compared to Debian-based images.


24-25: Install Build Dependencies with apk
The addition of the command RUN apk add --no-cache build-base git bash ensures that necessary build tools are available in the Alpine image. This is a correct approach for Alpine-based builds; just double-check that these packages cover all your build requirements.

coderabbitai[bot]
coderabbitai bot previously approved these changes Feb 16, 2025
@de-sh
Copy link
Contributor Author

de-sh commented Feb 16, 2025

Should consider using APKO

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 (1)
Dockerfile (1)

17-17: Ensure Static Linking for scratch Final Stage

The builder stage now uses the Alpine-based image (rust:1.84.0-alpine), which is excellent for reducing image size. However, since the final stage uses scratch, please confirm that the Rust release build produces a fully statically linked binary. If not already ensured, consider using appropriate linker flags or setting the target to x86_64-unknown-linux-musl to guarantee compatibility with a scratch base image.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 65db3a8 and a4d8fe0.

📒 Files selected for processing (2)
  • Dockerfile (2 hunks)
  • Dockerfile.debug (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (10)
  • GitHub Check: Build Default x86_64-pc-windows-msvc
  • GitHub Check: Build Default aarch64-apple-darwin
  • GitHub Check: Build Default x86_64-apple-darwin
  • GitHub Check: Build Default aarch64-unknown-linux-gnu
  • GitHub Check: Build Kafka aarch64-apple-darwin
  • GitHub Check: Quest Smoke and Load Tests for Standalone deployments
  • GitHub Check: Build Default x86_64-unknown-linux-gnu
  • GitHub Check: Quest Smoke and Load Tests for Distributed deployments
  • GitHub Check: Build Kafka x86_64-unknown-linux-gnu
  • GitHub Check: coverage
🔇 Additional comments (13)
Dockerfile (4)

24-26: Dependency Installation via apk

Installing the build dependencies (build-base, git, and bash) with apk add --no-cache is clear and concise. Ensure these packages cover all requirements needed during the build stage.


38-38: Adopting a Minimal Final Stage

Switching the final stage base image to scratch significantly minimizes the runtime image size. This is a great move for production deployments. Just be sure that the static linking concern (as mentioned above) is verified so the binary runs correctly.


43-43: Binary Copy and Path Consistency

The binary is copied from the builder’s release output using the command:

COPY --from=builder /parseable/target/release/parseable /parseable

and the ENTRYPOINT is set to ["/parseable"]. Please verify that this location is intentional and that the file has appropriate permissions to execute in the scratch environment.


45-45: ENTRYPOINT Configuration

Using ENTRYPOINT to run the application ensures that the container starts with your binary directly. Additionally, confirm that your binary handles signals appropriately (e.g., SIGTERM) for graceful shutdowns.

Dockerfile.debug (9)

17-17: Using Alpine for the Debug Build

Switching the builder stage to rust:1.84.0-alpine provides consistency with the production build. In the debug context, this change is acceptable since static linking is less of a concern for debug binaries.


24-26: Consistent Dependency Installation

The debug Dockerfile also installs build-base, git, and bash with apk. This consistency helps maintain the same build environment across all builds.


31-31: Efficient Dependency Caching

Using a temporary src/main.rs with a dummy main function to cache dependencies is an efficient approach. Just ensure that there’s no leftover artifact from this caching step that might interfere with the subsequent debug build.


34-35: Debug Binary Build Process

Copying the actual src directory and running cargo build builds the debug version of the binary. This approach is standard for non-optimized (debug) builds.


38-38: Final Stage: Alpine Base for Debugging

Using FROM alpine:latest in the final stage for the debug build is a smart choice. It provides a lightweight environment with essential utilities, which aids in troubleshooting compared to the scratch image used in production.


40-40: Installation of Debug Utilities

Installing curl using apk add --no-cache curl is useful for debugging and potential log ingestion tests. This helps ensure you have a minimal toolset for runtime investigations.


42-42: Working Directory Configuration

Setting the working directory to /parseable aligns the context for running the application and matches the subsequent file copy location.


45-45: Verify Debug Binary Placement and Permissions

The command:

COPY --from=builder /parseable/target/debug/parseable /usr/bin/parseable

places the debug binary in /usr/bin/parseable. Ensure this location is intentional and that the binary has the right execution permissions within the Alpine environment.


47-47: CMD for Debug Execution

Using CMD ["/usr/bin/parseable"] is appropriate for launching the debug binary in the final image. This configuration supports straightforward container execution for debugging purposes.

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