Skip to content

[Fix] Dockerfile.non_root: handle missing .npmrc gracefully - #25307

Merged
yuneng-berri merged 1 commit into
mainfrom
litellm_/fix_npmrc_dockerfile
Apr 7, 2026
Merged

[Fix] Dockerfile.non_root: handle missing .npmrc gracefully#25307
yuneng-berri merged 1 commit into
mainfrom
litellm_/fix_npmrc_dockerfile

Conversation

@yuneng-berri

Copy link
Copy Markdown
Contributor

Summary

Failure Path (Before Fix)

Dockerfile.non_root unconditionally runs mv /app/.npmrc /app/.npmrc.bak during the UI build step. When the build context doesn't include .npmrc (e.g. when LiteLLM is vendored in a subdirectory like containers/litellm/), the build fails with mv: can't rename '/app/.npmrc': No such file or directory.

Fix

Make all .npmrc rename operations conditional with [ -f file ] && mv ... || true. This is safe because npm ci installs from package-lock.json with pinned versions and integrity hashes — the .npmrc guardrails (ignore-scripts=true, min-release-age=3d) provide no additional protection during Docker builds and were already being temporarily removed anyway.

Testing

  • Verified the Dockerfile builds correctly when .npmrc is present (no behavior change)
  • The conditional guards ensure the build also succeeds when .npmrc is absent

Type

🐛 Bug Fix

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.
@vercel

vercel Bot commented Apr 7, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
litellm Ready Ready Preview, Comment Apr 7, 2026 7:45pm

Request Review

@codspeed-hq

codspeed-hq Bot commented Apr 7, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 16 untouched benchmarks


Comparing litellm_/fix_npmrc_dockerfile (537727f) with main (23e1a7d)

Open in CodSpeed

@greptile-apps

greptile-apps Bot commented Apr 7, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a Docker build failure in Dockerfile.non_root that occurs when .npmrc is absent from the build context (e.g. when LiteLLM is vendored in a subdirectory). The three unconditional mv commands are replaced with [ -f file ] && mv ... || true guards that no-op gracefully when the files don't exist.

  • mv /app/.npmrc /app/.npmrc.bak → guarded with [ -f /app/.npmrc ] (line 49)
  • mv .npmrc .npmrc.bak → guarded with [ -f .npmrc ] (line 58)
  • Both restore operations are individually guarded with [ -f *.bak ] checks (lines 60–61)
  • Backup/restore symmetry is maintained: if a file was backed up it will be restored; if it was never present, nothing happens in either direction

Confidence Score: 5/5

Safe 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

Important Files Changed

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
Loading

Reviews (1): Last reviewed commit: "[Fix] Dockerfile.non_root: handle missin..." | Re-trigger Greptile

@ryan-crabbe-berri
ryan-crabbe-berri self-requested a review April 7, 2026 19:52
@yuneng-berri
yuneng-berri merged commit f3bc200 into main Apr 7, 2026
88 of 97 checks passed
@yuneng-berri
yuneng-berri deleted the litellm_/fix_npmrc_dockerfile branch April 7, 2026 20:01
fzowl pushed a commit to fzowl/litellm that referenced this pull request Jun 24, 2026
…erfile

[Fix] Dockerfile.non_root: handle missing .npmrc gracefully
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants