Skip to content

perf(docker): optimize builds with cache mounts and parallel stages - #47

Merged
gatezh merged 2 commits into
masterfrom
optimize-claude-code
Mar 25, 2026
Merged

gatezh merged 2 commits into
masterfrom
optimize-claude-code

Conversation

@gatezh

@gatezh gatezh commented Mar 25, 2026

Copy link
Copy Markdown
Owner

What

Optimizes Docker build performance for claude-code and devcontainer-claude-bun images using BuildKit cache mounts and parallel download stages.

Why

Daily image rebuilds benefit from faster build times. Cache mounts avoid re-downloading apt packages and npm modules on each build, while parallel stages allow rtk and ralphex downloads to run concurrently with the main build.

Changes

  • Parallel multi-stage builds (claude-code): Split rtk and ralphex downloads into separate FROM alpine stages that BuildKit runs concurrently, then COPY --from the binaries into the final image
  • BuildKit cache mounts: Added --mount=type=cache for apt (/var/cache/apt, /var/lib/apt/lists) and npm (/root/.npm) across all RUN apt-get and npm install steps in both images
  • Removed manual cleanup: Dropped apt-get clean && rm -rf /var/lib/apt/lists/* since cache mounts handle layer efficiency
  • SHELL pipefail: Added explicit SHELL ["/bin/bash", "-o", "pipefail", "-c"] around piped curl | sh commands for safety
  • OCI labels: Consolidated multi-line LABEL instructions into single layer; added labels to both default and sandbox targets in claude-code

🤖 Generated with Claude Code

gatezh and others added 2 commits March 24, 2026 19:03
- Use BuildKit cache mounts for apt, npm, and apt/lists across all
  apt-get and npm install steps (eliminates manual cleanup)
- Extract rtk and ralphex downloads into parallel multi-stage builds
  with COPY --from for faster image builds
- Add SHELL pipefail directive for safer curl|sh piping
- Consolidate OCI LABEL instructions into single layer
- Add OCI labels to both default and sandbox targets

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@gatezh
gatezh merged commit a8d3f6e into master Mar 25, 2026
8 checks passed
@gatezh
gatezh deleted the optimize-claude-code branch March 26, 2026 01:00
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