Shamelessly ripped from https://containers.dev/guide/prebuild because I couldn't have put it better myself.
We start at the .devcontainer/devcontainer.json designed for end use in the Kubernetes repo and other forks of it
- It sets a few properties, such as hostRequirements, onCreateCommand, and otherPortsAttributes
- We see it references a prebuilt image, which will include dependencies that don’t need to be explicitly mentioned in this end user dev container. Let’s next go explore the dev container defining this prebuilt image
- We next open the config that defines the prebuilt image. This is contained in the .github/.devcontainer folder
- We see there’s a devcontainer.json. It’s much more detailed than the end user dev container we explored above and includes a variety of Features
- Each Feature defines additional functionality
- We can explore what each of them installs in their associated repo. Most appear to be defined in the devcontainers/features repo as part of the dev container spec
- If I’d like to add more content to my dev container, I can either modify my end user dev container (i.e. the one designed for the main Kubernetes repo), or modify the config defining the prebuilt image (i.e. the content in Craig’s dev container)
- For universal changes that anyone using the prebuilt image should get, update the prebuilt image
- For more project or user specific changes (i.e. a language I need in my project but other forks won’t necessarily need, or user settings I prefer for my editor environment), update the end user dev container
- Features are a great way to add dependencies in a clear, easily packaged way
Start at the beginning. Don't even start at the beginning -- start at a scratchpad (AS builder) that comes several layers before the beginning. You built the scratchpad for one thing. Get a release of ripgrep, like so:
FROM registry.access.redhat.com/ubi10:latest AS builder
ADD --unpack=true https://github.com/BurntSushi/ripgrep/releases/download/15.2.0/ripgrep-15.2.0-x86_64-unknown-linux-musl.tar.gz /tmp
FROM something
COPY --from=builder /tmp/ripgrep-*/rg /usr/local/bin/Whenever possible: FROM early, COPY late. It's your sentinel. Everything before the COPY line: ground truth. Never altered. Or as my grandfather used to say, SLOPPY BEFORE COPY, CACHE GETS DROPPIED
RUN --mount=type=cache,target=/root/.local/share/pnpm/store pnpm install --frozen-lockfileI'm going to guess pnpm is "portable npm." I don't know much about env beyond subshell, and I only use TypeScript when I need EcmaScript but can't tolerate that lazy duck typing. Still, words like "portable" and "frozen lockfile" are the sort of contracts you look for early and often in a Docker build.
So, I looked up pnpm
"When using npm, if you have 100 projects using lodash, you will have 100 copies of lodash on disk. With pnpm, lodash will be stored in a content-addressable storage"
I hope it all burns before I learn what lodash is.