app-docker-cache-fix

Installation
SKILL.md

App Docker Cache Fix

Target: $ARGUMENTS, or every Dockerfile and Containerfile in the current project minus vendored code when empty.

Adapted from @DanielLockyer: https://x.com/DanielLockyer/status/2127105345688359231

Review my Dockerfile and optimise it for layer caching. Minimise invalidation so small changes don't force full rebuilds

A layer is rebuilt when its instruction, its inputs or any layer above it changed. Invalidation is a rebuild the change did not need: a README edit that reinstalls dependencies because COPY . . sits above the install, a build-date ARG that busts every layer under it. The fix is ordering and narrowing, never a different image: the image after the change holds the same files, metadata and behavior as before.

Rules

  • The judge is which instructions re-ran, not seconds. Time is noisy; the rebuilt list is not. Name an instruction by what it does (RUN npm ci), since step numbers shift when you reorder. Work is what counts: RUN and ADD <url> re-runs; an extra COPY that splitting adds is cheap.
  • Baseline and result are the same measurement: same builder, same base image digest, same scenarios, same context copy.
  • Local only. Never push an image, write to a registry cache, or prune the user's build cache. Measure on a builder this skill creates (docker buildx create --name <unique> --driver docker-container) and remove it at the end (docker buildx rm <name>).
  • Scenario edits go in a copy of the build context made with cp -R, not a git checkout: untracked files enter the context today and change the build.
  • A secret that reaches the context or a layer (.env, keys, an ARG or ENV holding a token): report file and instruction, never the value, and flag it for rotation.
  • No Docker daemon or BuildKit: change nothing and list every candidate under For review.
Installs
2
Repository
lancetw/skills
GitHub Stars
6
First Seen
4 days ago