Repository navigation
docker: redeclare ARG PnpmVersion inside the build stages that use it (fixes #8210) - #8320
Merged
Merged
Conversation
The default `ARG PnpmVersion=12.4.2` is declared before the first `FROM`, so
it only exists in the global scope that precedes the stages. Inside
`adminbuild` and `build` it expands to an empty string, which turns
`npm install -g pnpm@${PnpmVersion}` into `npm install -g pnpm@` and installs
the latest pnpm rather than the pinned one. A version passed with
`--build-arg PnpmVersion=...` is therefore ignored.
Redeclare the ARG in each stage that installs pnpm, and extend the existing
dockerfilePnpmPin test to assert that every stage running
`npm install -g pnpm@${PnpmVersion}` redeclares `ARG PnpmVersion`, so the pin
cannot silently regress.
Fixes ether#8210
|
ⓘ Qodo reviews are paused because the subscription is no longer active. Ask your workspace admin to reactivate the subscription to resume reviews. Manage billing |
PR Summary by QodoFix pnpm build-arg scope in Docker build stages
AI Description
Diagram
High-Level Assessment
Files changed (2)
|
Code Review by Qodo🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)
Great, no issues found!Qodo reviewed your code and found no material issues that require reviewTip of the day💡 Did you know, you can keep summaries lean with Findings visible per group, which tucks the rest behind a View link |
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.
Fixes #8210
What this changes
The
ARG PnpmVersiondefault is declared before the firstFROM, so Docker only resolves it in the global scope that precedes the stages. Insideadminbuildandbuildit expands to an empty string, which turnsinto
npm install -g pnpm@— i.e. "install the latest pnpm" — so a version passed with--build-arg PnpmVersion=11.0.6is ignored and the image still ships the newest release.This redeclares
ARG PnpmVersioninside each stage that installs pnpm, which restores the build-arg:The default value before the first
FROMis unchanged, so builds without a build-arg keep using thepackageManagerpin exactly as before.What this does not change
The other half of #8210 — the
pnpm ls ... --no-productionspelling under pnpm 12 — was already fixed ondevelopand is not touched here.I deliberately did not change the default pnpm version or the
enginesfloor. Which pnpm the image pins is a separate decision (see the note in the issue about the minimum-release-age policy), and pinning an older build-arg now works but still has to satisfy"pnpm": ">=12.0.0"inpackage.json.Testing
Dockerfileis parsed the same way the existing #7911 test already does, so no Docker daemon is needed to regress this:src/tests/backend/specs/dockerfilePnpmPin.tswith a check that every stage runningnpm install -g pnpm@${PnpmVersion}also redeclaresARG PnpmVersion;adminbuildandbuildas offenders) and passes with the fix;NODE_ENV=production npx mocha --import=tsx --extension ts tests/backend/specs/dockerfilePnpmPin.ts→ 3 passing.