Skip to content

perf(docker): tune release profile and switch to musl/Alpine#84

Merged
nanotaboada merged 5 commits into
masterfrom
perf/docker-build
Apr 8, 2026
Merged

perf(docker): tune release profile and switch to musl/Alpine#84
nanotaboada merged 5 commits into
masterfrom
perf/docker-build

Conversation

@nanotaboada

@nanotaboada nanotaboada commented Apr 8, 2026

Copy link
Copy Markdown
Owner

Summary

Results

Before After
Binary ~7 MB ~6.5 MB
Base image debian:bookworm-slim ~74 MB alpine ~7 MB
Total image ~140 MB 9.1 MB

Test plan

  • cargo fmt passes
  • cargo clippy --all-targets --all-features -- -D warnings passes clean
  • cargo build succeeds
  • cargo test — all 38 tests pass, no regressions
  • docker compose build succeeds — image size confirmed at 9.1 MB
  • docker compose up starts the API and responds on port 9000

Closes #60
Closes #57

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Chores
    • Optimized release builds for smaller, faster startup artifacts via stricter release settings.
    • Container runtime switched to a lighter Alpine base for a smaller image footprint.
    • Builds now produce fully static Linux binaries for a leaner, more portable amd64 container deployment.

nanotaboada and others added 2 commits April 8, 2026 11:54
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Apr 8, 2026

Copy link
Copy Markdown

Walkthrough

Added Cargo release profile settings (LTO, single codegen unit, strip, panic = "abort") and updated the Docker build to produce a fully static x86_64-unknown-linux-musl binary and switch the runtime image from Debian to Alpine.

Changes

Cohort / File(s) Summary
Build Configuration
Cargo.toml
Added [profile.release] with lto = true, codegen-units = 1, strip = true, panic = "abort".
Docker Build System
Dockerfile
Builder: install musl-tools, add x86_64-unknown-linux-musl target, set CC_x86_64_unknown_linux_musl=musl-gcc, build with --target x86_64-unknown-linux-musl and --platform=linux/amd64; Runtime: switched base image to alpine:3.23, replaced Debian user/group commands with Alpine equivalents, copy path updated to target/x86_64-unknown-linux-musl/release/....
Changelog
CHANGELOG.md
Added release notes describing release-profile tuning and musl/Alpine container build changes.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Assessment against linked issues

Objective Addressed Explanation
Add [profile.release] with lto, codegen-units, strip, panic [#60]
Install musl-tools, add x86_64-unknown-linux-musl target, set musl linker, and build with --target [#57]
Switch runtime base image to alpine and update user/group creation to Alpine syntax [#57]
Verify native-dependent crates (e.g., rusqlite) build cleanly under musl [#57] No build logs, CI changes, or test artifacts provided to confirm native deps compile and run under musl.
🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title follows Conventional Commits format with 'perf:' prefix, is 60 characters (under 80), and clearly describes the main changes: tuning release profile and switching to musl/Alpine for performance optimization.
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
  • Commit unit tests in branch perf/docker-build
  • 🛠️ sync documentation: Commit on current branch
  • 🛠️ sync documentation: Create PR
  • 🛠️ enforce http error handling: Commit on current branch
  • 🛠️ enforce http error handling: Create PR
  • 🛠️ idiomatic review: Commit on current branch
  • 🛠️ idiomatic review: Create PR
  • 🛠️ verify api contract: Commit on current branch
  • 🛠️ verify api contract: Create PR

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
Dockerfile (1)

52-52: Pin the Alpine version for reproducible builds.

Using the bare alpine tag means builds may use different Alpine versions over time, potentially introducing unexpected behavior or security differences.

📦 Suggested fix to pin Alpine version
-FROM alpine AS runtime
+FROM alpine:3.23 AS runtime
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@Dockerfile` at line 52, Replace the non-pinned base image in the Dockerfile
so builds are reproducible: update the "FROM alpine AS runtime" reference to use
a specific Alpine tag (e.g., alpine:3.18) or introduce an ARG like
ALPINE_VERSION and use "FROM alpine:${ALPINE_VERSION} AS runtime" so the image
version is explicit and repeatable; ensure any CI/build configs set the same
ALPINE_VERSION value.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@Dockerfile`:
- Line 52: Replace the non-pinned base image in the Dockerfile so builds are
reproducible: update the "FROM alpine AS runtime" reference to use a specific
Alpine tag (e.g., alpine:3.18) or introduce an ARG like ALPINE_VERSION and use
"FROM alpine:${ALPINE_VERSION} AS runtime" so the image version is explicit and
repeatable; ensure any CI/build configs set the same ALPINE_VERSION value.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 7d027231-0547-4b81-a728-de9ce6368232

📥 Commits

Reviewing files that changed from the base of the PR and between e1602d6 and fec4570.

📒 Files selected for processing (3)
  • CHANGELOG.md
  • Cargo.toml
  • Dockerfile

@codecov

codecov Bot commented Apr 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.33%. Comparing base (e1602d6) to head (e8cb513).
⚠️ Report is 6 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master      #84   +/-   ##
=======================================
  Coverage   84.33%   84.33%           
=======================================
  Files           6        6           
  Lines         166      166           
=======================================
  Hits          140      140           
  Misses         26       26           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@Dockerfile`:
- Line 18: The Dockerfile hard-codes the Rust target with "RUN rustup target add
x86_64-unknown-linux-musl" while the two FROM statements lack platform
directives, causing cross-arch mismatches on arm64 builders; fix by either
adding --platform=linux/amd64 to both FROM statements to force amd64 build and
runtime, or update the Dockerfile to parameterize the target using build
args/variables (e.g., TARGETARCH/TARGETPLATFORM) and derive the rustup target
from those variables so the rustup invocation (the RUN rustup target add ...)
and the runtime FROM are consistent with the chosen architecture.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 6cec8ae6-5fa7-4de7-9d1d-a87fc60b9eaa

📥 Commits

Reviewing files that changed from the base of the PR and between fec4570 and 799dfb2.

📒 Files selected for processing (1)
  • Dockerfile

Comment thread Dockerfile
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
Dockerfile (1)

54-54: Pin the Alpine version for reproducible builds.

Using alpine without a version tag means the image can change unexpectedly when a new Alpine release becomes :latest. This affects build reproducibility and may introduce breaking changes silently. Pin to a stable version such as alpine:3.23.

📦 Proposed fix to pin Alpine version
-FROM --platform=linux/amd64 alpine AS runtime
+FROM --platform=linux/amd64 alpine:3.23 AS runtime
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@Dockerfile` at line 54, The Dockerfile's base image line "FROM
--platform=linux/amd64 alpine AS runtime" should pin the Alpine tag to ensure
reproducible builds; update that FROM instruction to use a specific, stable tag
(e.g., alpine:3.23) instead of the floating "alpine" to prevent unexpected
changes in downstream builds.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@Dockerfile`:
- Line 54: The Dockerfile's base image line "FROM --platform=linux/amd64 alpine
AS runtime" should pin the Alpine tag to ensure reproducible builds; update that
FROM instruction to use a specific, stable tag (e.g., alpine:3.23) instead of
the floating "alpine" to prevent unexpected changes in downstream builds.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: fb657dbf-1a50-46e3-befa-9bf4aff12f9c

📥 Commits

Reviewing files that changed from the base of the PR and between 799dfb2 and e09ec70.

📒 Files selected for processing (1)
  • Dockerfile

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
Dockerfile (1)

31-32: Use --locked in both Cargo build steps.

Cargo.lock is copied explicitly, but plain cargo build will still proceed if the lockfile is out of sync and resolve inside the image. --locked makes that drift fail fast and keeps the Docker build deterministic.

♻️ Proposed change
 RUN --mount=type=cache,target=/usr/local/cargo/registry \
     --mount=type=cache,target=/app/target \
     CC_x86_64_unknown_linux_musl=musl-gcc \
-    cargo build --release --target x86_64-unknown-linux-musl
+    cargo build --locked --release --target x86_64-unknown-linux-musl
@@
 RUN --mount=type=cache,target=/usr/local/cargo/registry \
     --mount=type=cache,target=/app/target \
     touch src/main.rs && \
     CC_x86_64_unknown_linux_musl=musl-gcc \
-    cargo build --release --target x86_64-unknown-linux-musl && \
+    cargo build --locked --release --target x86_64-unknown-linux-musl && \
     cp target/x86_64-unknown-linux-musl/release/rust-samples-rocket-restful /app/rust-samples-rocket-restful

Also applies to: 46-48

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@Dockerfile` around lines 31 - 32, Builds are using plain `cargo build` which
can resolve/update Cargo.lock inside the image; add `--locked` to both cargo
build invocations so the image fails if Cargo.lock is out of sync. Update the
two occurrences of the `cargo build --release --target
x86_64-unknown-linux-musl` commands (one following
`CC_x86_64_unknown_linux_musl=musl-gcc` and the other earlier in the Dockerfile)
to `cargo build --locked --release --target x86_64-unknown-linux-musl` so the
Docker build remains deterministic given the copied Cargo.lock.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@Dockerfile`:
- Around line 31-32: Builds are using plain `cargo build` which can
resolve/update Cargo.lock inside the image; add `--locked` to both cargo build
invocations so the image fails if Cargo.lock is out of sync. Update the two
occurrences of the `cargo build --release --target x86_64-unknown-linux-musl`
commands (one following `CC_x86_64_unknown_linux_musl=musl-gcc` and the other
earlier in the Dockerfile) to `cargo build --locked --release --target
x86_64-unknown-linux-musl` so the Docker build remains deterministic given the
copied Cargo.lock.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 701948b9-8413-480f-a89c-a9e077e65524

📥 Commits

Reviewing files that changed from the base of the PR and between e09ec70 and e8cb513.

📒 Files selected for processing (1)
  • Dockerfile

@nanotaboada
nanotaboada merged commit b4c1f0a into master Apr 8, 2026
10 checks passed
@nanotaboada
nanotaboada deleted the perf/docker-build branch April 8, 2026 16:33
@coderabbitai coderabbitai Bot mentioned this pull request Apr 11, 2026
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant