[Fix] Dockerfile.non_root: handle missing .npmrc gracefully - #25307
Conversation
The .npmrc file (ignore-scripts=true, min-release-age=3d) is temporarily removed during the Docker build since lifecycle scripts are needed by npm ci. However, the unconditional `mv` fails when the build context doesn't include .npmrc (e.g. when LiteLLM is vendored in a subdirectory). Make all .npmrc mv operations conditional. This is safe because npm ci already installs from package-lock.json with pinned versions and integrity hashes.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Greptile SummaryThis PR fixes a Docker build failure in
Confidence Score: 5/5Safe to merge — minimal, targeted fix with correct conditional logic and no behavioral change when .npmrc is present Single-file Dockerfile change with no logic regressions. All three mv operations are guarded symmetrically using the idiomatic [ -f file ] && mv ... || true shell pattern. Backup/restore symmetry is fully preserved — a file is only restored if it was backed up, and no spurious no-ops fire when files are present. No files require special attention
|
| Filename | Overview |
|---|---|
| docker/Dockerfile.non_root | Conditional guards added around all three .npmrc mv operations to handle missing files gracefully; backup/restore symmetry is preserved |
Sequence Diagram
sequenceDiagram
participant FS as Filesystem
participant Docker as Docker RUN layer
Note over Docker,FS: Step 1 — check /app/.npmrc
Docker->>FS: [ -f /app/.npmrc ]?
alt /app/.npmrc exists
FS-->>Docker: true
Docker->>FS: mv /app/.npmrc /app/.npmrc.bak
else /app/.npmrc missing
FS-->>Docker: false
Docker->>Docker: no-op
end
Note over Docker,FS: Step 2 — cd ui/litellm-dashboard, check .npmrc
Docker->>FS: [ -f .npmrc ]?
alt .npmrc exists
FS-->>Docker: true
Docker->>FS: mv .npmrc .npmrc.bak
else .npmrc missing
FS-->>Docker: false
Docker->>Docker: no-op
end
Note over Docker,FS: Step 3 — install dependencies
Docker->>Docker: npm ci
Note over Docker,FS: Step 4 — restore .npmrc
Docker->>FS: [ -f .npmrc.bak ]?
alt .npmrc.bak exists
FS-->>Docker: true
Docker->>FS: mv .npmrc.bak .npmrc
else missing
FS-->>Docker: false
Docker->>Docker: no-op
end
Note over Docker,FS: Step 5 — restore /app/.npmrc
Docker->>FS: [ -f /app/.npmrc.bak ]?
alt /app/.npmrc.bak exists
FS-->>Docker: true
Docker->>FS: mv /app/.npmrc.bak /app/.npmrc
else missing
FS-->>Docker: false
Docker->>Docker: no-op
end
Note over Docker,FS: Step 6 — build UI
Docker->>Docker: npm run build
Reviews (1): Last reviewed commit: "[Fix] Dockerfile.non_root: handle missin..." | Re-trigger Greptile
…erfile [Fix] Dockerfile.non_root: handle missing .npmrc gracefully
Summary
Failure Path (Before Fix)
Dockerfile.non_rootunconditionally runsmv /app/.npmrc /app/.npmrc.bakduring the UI build step. When the build context doesn't include.npmrc(e.g. when LiteLLM is vendored in a subdirectory likecontainers/litellm/), the build fails withmv: can't rename '/app/.npmrc': No such file or directory.Fix
Make all
.npmrcrename operations conditional with[ -f file ] && mv ... || true. This is safe becausenpm ciinstalls frompackage-lock.jsonwith pinned versions and integrity hashes — the.npmrcguardrails (ignore-scripts=true,min-release-age=3d) provide no additional protection during Docker builds and were already being temporarily removed anyway.Testing
.npmrcis present (no behavior change).npmrcis absentType
🐛 Bug Fix