chore(docker): shrink runtime image and stop building arm64 under QEMU - #3
Merged
Merged
Conversation
- Pin the toolchain used by the deps and build stages to --platform=$BUILDPLATFORM. The Nitro bundle is pure JavaScript and identical across target platforms, so those stages now run once, natively, instead of once per target (arm64 was running the full pnpm install and Vite build under QEMU). The flag is applied to the image reference because BuildKit ignores it on a stage reference. - Replace the full `pnpm install --prod` in the prod-deps stage with a minimal manifest listing only the packages imported outside Nitro's bundle (instrument.server.mjs and scripts/*.mjs): @sentry/tanstackstart-react, drizzle-orm, and pg. Nitro traces and inlines everything else, so the previous production install (~200 packages, ~210MB) was mostly dead weight. Final image goes from ~549MB to ~108MB. The manifest is generated in the build stage from the installed versions (docker/write-runtime-package.mjs) so the Sentry SDK loaded via --import can never drift from the one bundled into .output. - Add a pull_request trigger (build-only, no push) to docker-publish.yml so a broken Dockerfile is caught before merging to main. The existing `if: github.event_name != 'pull_request'` guards were already written for this but the trigger was missing. - Add a concurrency group so overlapping pushes to main don't run redundant builds. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
|
Warning Review limit reachedNext included review available in 43 minutes. View limit detailsLimit details: You’ve used the included review currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (3)
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. Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up to a review of the Dockerfile and the container publish workflow. Structure was already sound (multi-stage, non-root, frozen lockfile); this fixes the three things that made builds slow and images large.
depsandbuildstages now use a toolchain pinned to--platform=$BUILDPLATFORM. The Nitro output is pure JavaScript, so in thelinux/amd64,linux/arm64CI build the pnpm install and Vite build run a single time on the host instead of once natively and once under QEMU. Only the small runtimenode_modulesinstall is still done per target platform.node_modules. Nitro inlines the whole server dependency tree into.output/server. The only code that runs outside the bundle isinstrument.server.mjsandscripts/*.mjs, which need just@sentry/tanstackstart-react,drizzle-ormandpg. Theprod-depsstage now installs only those. Their versions are derived at build time from the installed (lockfile-resolved) tree bydocker/write-runtime-package.mjs, so the Sentry SDK loaded via--importcannot drift from the one bundled into.output.pull_requesttrigger (build only, no push) so Dockerfile breakage is caught before merge, and aconcurrencygroup so overlapping pushes tomaincancel superseded builds. The workflow's existingpull_requestguards were already in place; only the trigger was missing.node_modulesVerification
docker buildof the final Dockerfile succeeds; the container starts, loads Sentry instrumentation, and reaches the database migration step (fails only because no database is provided).docker buildx build --no-cache --platform linux/amd64,linux/arm64runspnpm run buildin exactly one vertex on the native architecture; theprod-depsstage runs once per platform as intended.--platform=$BUILDPLATFORMis a no-op when applied to a stage reference and only takes effect on an image reference, which is why the flag is on thebuild-baseimage line..nodenative binaries in the runtime tree.Not addressed (from the same review)
RUN --mount=type=cachepnpm store is not persisted by thetype=ghacache backend, so CI still relies on layer caching alone. Left as is;buildkit-cache-dancewould be the fix if it becomes a problem.corepackis deprecated upstream and works onnode:22but is gone fromnode:25images.tailwindcss,@faker-js/faker,dotenv-cliandnitrois listed underdependenciesinpackage.json. No longer affects the image, but could be moved todevDependenciesfor hygiene.🤖 Generated with Claude Code