Rules Hub
Coding Rules Library
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Copy config files only into the Docker build stages that need them
In multi-stage Dockerfiles, COPY a file (e.g. a workspace manifest) only into the stages that actually consume it, not into every stage.
Bad example
| 1 | FROM node AS deps |
| 2 | COPY pnpm-workspace.yaml ./ |
| 3 | FROM node AS build |
| 4 | COPY pnpm-workspace.yaml ./ |
| 5 | FROM node AS final |
| 6 | COPY pnpm-workspace.yaml ./ |
Explanation (EN)
Copying the same file into every stage, including ones that never read it, adds noise and confuses which stage actually needs the dependency-resolution manifest.
Objašnjenje (HR)
Kopiranje iste datoteke u svaku fazu, ukljucujuci one koje je nikad ne citaju, dodaje sum i zbunjuje koja faza doista treba manifest za razrjesavanje ovisnosti.
Good example
| 1 | FROM node AS deps |
| 2 | COPY pnpm-workspace.yaml ./ |
| 3 | FROM node AS production-deps |
| 4 | COPY pnpm-workspace.yaml ./ |
| 5 | FROM node AS build |
| 6 | # implicitly available via COPY --from=deps /app |
| 7 | FROM node AS final |
| 8 | # not needed, final stage doesn't install packages |
Explanation (EN)
Only `deps` and `production-deps` install packages and need the workspace manifest; `build` inherits it from an earlier stage and the final runtime stage doesn't install anything.
Objašnjenje (HR)
Samo `deps` i `production-deps` instaliraju pakete i trebaju manifest radnog prostora; `build` ga nasljeduje iz ranije faze, a zavrsna runtime faza ne instalira nista.