Fast Docker build: cache mounts, layer ordering, multi-stage nvim - #15
Open
IlyaasK wants to merge 2 commits into
Open
Fast Docker build: cache mounts, layer ordering, multi-stage nvim#15IlyaasK wants to merge 2 commits into
IlyaasK wants to merge 2 commits into
Conversation
Line 65 ends with backslash + trailing space. The backslash escapes the space, so the shell sees an unescaped newline: every command from 'alias vim' onward (vim/diff/pip aliases, venv activation, cd pufferlib, mesa env) was a syntax error and never made it into the image.
Apply the fastdocker principles (eblog.fly.dev/fastdocker.html): - Cache mounts for apt lists/debs, the uv wheel cache (~3GB torch wheels download once), ccache, and the experiments.zip baseline download. - Layer ordering least-to-most-frequently-changed; the init.vim and entrypoint.sh COPYs move to the end so config edits no longer invalidate the nsight/torch/pufferlib layers. - ARG NEOVIM_REF/PUFFERLIB_REF/PUFFERAI_REF so clone layers can be refreshed via --build-arg without editing the file (defaults unchanged: master/4.0/4.0). - Neovim builds in a separate stage with CMAKE_INSTALL_PREFIX=/opt/nvim; the final image keeps only the installed runtime, dropping the source tree, build artifacts, and cmake/ninja/gettext/unzip. Adds -j(nproc). - Merge scattered apt installs into one update+install layer; nsight stays on its own layer; COPY --chmod=755 replaces COPY+chmod; drop the no-op trailing 'apt-get clean' layer. - .dockerignore whitelists the two COPY'd files: context drops from the whole repo to 274 bytes.
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.
Fast Docker build: cache mounts, layer ordering, multi-stage Neovim (+1 bug fix)
Applies the principles from eblog's FastDocker to
puffertank.dockerfile.Changes
Cache mounts (BuildKit) —
--mount=type=cacheso rebuilds reuse state across builds:/root/.cache/uv→ the ~3GB of cu130 torch wheels download once, not on every layer invalidation/root/.cache/puffer→experiments.zipbaseline download survives rebuilds/var/cache/apt+/var/lib/apt→ package lists/debs shared across builds/root/.ccache(was already present)Layer ordering: least → most frequently changed
COPY init.vim(was line 29) andCOPY entrypoint.sh(was line 59) moved to the end. Previously, editing your vimrc invalidated the nsight, torch, and pufferlib layers — a multi-GB re-download per config tweak. Now a vimrc edit rebuilds only the final ~0s COPY layer.ARG NEOVIM_REF/PUFFERLIB_REF/PUFFERAI_REFlet you refresh git-clone layers with--build-arginstead of editing the file (Docker cachesgit clonelayers forever since it never re-checks the remote). Defaults unchanged:master/4.0/4.0.Multi-stage build (ship the pizza, not the oven)
nvim-builderstage withCMAKE_INSTALL_PREFIX=/opt/nvim; the final image copies only the installed runtime. Drops the nvim source tree + build artifacts (~1GB) and cmake/ninja/gettext/unzip from the final image.make -j$(nproc)parallelizes the compile.Smaller, granular layers
apt-get installRUNs merged into oneupdate && installlayer (same package list); nsight stays on its own layer since it's large and version-bumped independently.COPY --chmod=755replaces the COPY+chmod pair.RUN apt-get clean— a cleanup in a new layer never shrinks the layers below it..dockerignore — rewritten as a whitelist: build context drops from the whole repo to 2 files (274 bytes measured with
buildx --check), and the brokenpuffertank -> /puffertanksymlink can no longer break context transfer.Bug fix (separate commit)
Line 65 ends with
\␣(backslash + trailing space). The backslash escapes the space, so the shell sees an unescaped newline: a syntax error at&& echo …. Every bashrc line fromalias vimonward — the vim/diff/pip aliases, venv activation,cd pufferlib, the mesa env var — silently never applied in any image built from this revision. Continuations normalized; all 7 payloads byte-identical.Validation
docker buildx build --check -f puffertank.dockerfile .→ passes, no warnings (full frontend parse; base image not pulled).alias diffline both execute cleanly undersh(the original fails withsh: syntax error near unexpected token '&&').Not yet measured
Wall-clock build/rebuild timings are intentionally left out: this was prepared on an arm64 box without a GPU (no cu130 aarch64 torch wheels exist), so a fair measurement must happen on an amd64 + GPU machine. Expected effects once measured there:
-j), everything else roughly unchanged