Skip to content

fix(docker): install npm in runtime stage so fresh-DB prisma migrate deploy works - #33657

Closed
devin-ai-integration[bot] wants to merge 1 commit into
litellm_internal_stagingfrom
litellm_fix_docker_runtime_npm_prisma_migrate
Closed

devin-ai-integration[bot] wants to merge 1 commit into
litellm_internal_stagingfrom
litellm_fix_docker_runtime_npm_prisma_migrate

Conversation

@devin-ai-integration

Copy link
Copy Markdown
Contributor

Relevant issues

Fixes #33650, fixes #24554

Linear ticket

Pre-Submission checklist

  • I have added meaningful tests
  • My PR passes all CI/CD checks (e.g., lint, format, unit tests)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • I have received a Greptile Confidence Score of at least 4/5 before requesting a maintainer review

Screenshots / Proof of Fix

Both runs use a brand-new empty Postgres and HOME=/home/litellm (the released image runs as the litellm user, so its Prisma cache under /root is never found and the CLI is bootstrapped at startup, which is what triggers the bug)

Before, built from this branch with npm removed from the runtime apk add (reproduces #33650 exactly):

$ docker logs litellm-broken-run
Running prisma migrate deploy
subprocess.CalledProcessError: Command '['/home/litellm/.cache/prisma-python/nodeenv/bin/npm', 'install', 'prisma@5.4.2']' returned non-zero exit status 127.
An error ocurred while installing the Prisma CLI; npm install log: node: error while loading shared libraries: libatomic.so.1: cannot open shared object file: No such file or directory

$ curl -s -X POST http://localhost:4002/team/new -H "Authorization: Bearer sk-test-1234" -d '{"team_alias":"repro"}'
{"error":{"message":"The table `public.LiteLLM_TeamTable` does not exist in the current database.","type":"internal_server_error","code":"500"}}

$ psql -d brokendb -c "SELECT count(*) FROM information_schema.tables WHERE table_schema='public';"
 0

After, at commit 3154bb7:

$ docker logs litellm-fixed-run2
prisma migrate deploy stdout: Installing Prisma CLI
... 135 migrations found ... Applying migration `20250326162113_baseline` ...

$ curl -s -X POST http://localhost:4003/team/new -H "Authorization: Bearer sk-test-1234" -d '{"team_alias":"repro-fixed"}' -w "\nHTTP %{http_code}\n"
{"team_alias":"repro-fixed","team_id":"352218e1-ba2d-4527-9d8d-f09bdf15bbc6", ...}
HTTP 200

$ psql -d fixeddb -c "SELECT count(*) FROM information_schema.tables WHERE table_schema='public';"
 74

Type

🐛 Bug Fix

Changes

The runtime stage of Dockerfile and docker/Dockerfile.database installed nodejs but deliberately left out npm, on the assumption that runtime only ever runs prisma generate against binaries already cached from the builder stage. That assumption breaks for prisma migrate deploy at container startup against a fresh database: prisma-python has to bootstrap the Node-based Prisma CLI, and its resolver picks the global Node/npm toolchain only when both are on PATH (use_global_node defaults to True). With npm absent it falls back to nodeenv, which downloads a Node build (26.x) whose dynamic dependency libatomic.so.1 is not present in the Wolfi runtime image. node then exits 127, the migration silently fails, the proxy starts anyway with no schema, and every DB-backed endpoint 500s with The table 'public.LiteLLM_TeamTable' does not exist

The fix adds npm back to the runtime apk add in both Dockerfiles so prisma-python stays on the global-Node path and never invokes nodeenv at runtime. This mirrors what migrations/Dockerfile already does with PRISMA_USE_GLOBAL_NODE=true plus nodejs/npm, and completes the builder-stage fix from #28519/#28888 for the runtime half of the same bug class. docker/Dockerfile.non_root is unaffected: it runs with PRISMA_OFFLINE_MODE=true and executes the cached CLI directly via system Node, so it never reaches the nodeenv path

tests/test_litellm/test_dockerfile_runtime_prisma.py is a static guard that parses the runtime stage of both Dockerfiles and fails if nodejs or npm is dropped from apk add, so this regression cannot silently return

Final Attestation

  • The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR

Link to Devin session: https://app.devin.ai/sessions/be13d5ae0bac48d7ad1e309d69070686

@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@greptile-apps

greptile-apps Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a container-startup crash where prisma migrate deploy on a fresh database would silently fail because npm was absent from the runtime apk add, causing prisma-python to fall back to nodeenv, which downloads a Node build whose libatomic.so.1 dependency is missing from the Wolfi runtime image. The fix is a one-word addition — npm — to both Dockerfile and docker/Dockerfile.database.

  • Both Dockerfiles now install nodejs npm together in the runtime stage, matching what migrations/Dockerfile already does, so prisma-python always uses the global Node toolchain at runtime.
  • A new static test (test_dockerfile_runtime_prisma.py) parses both Dockerfiles and fails if either nodejs or npm is dropped from the runtime apk add, preventing a silent regression.

Confidence Score: 5/5

Safe to merge — the change is a single additional package in two identical apk add lines, backed by a reproducible before/after demonstration and a new static test that will catch any future regression.

The root-cause analysis is accurate, the fix is minimal and targeted, the regression test correctly isolates the runtime stage and validates both required packages, and the PR description includes concrete evidence of the crash and the fix. No logic changes, no new runtime code paths, no existing tests modified.

No files require special attention.

Important Files Changed

Filename Overview
Dockerfile Adds npm alongside existing nodejs in the runtime apk add call; well-commented explaining why the fallback nodeenv path breaks on Wolfi.
docker/Dockerfile.database Identical one-package addition (npm) in the runtime stage, mirroring the fix in the root Dockerfile.
tests/test_litellm/test_dockerfile_runtime_prisma.py New static regression guard that parses both Dockerfiles and asserts nodejs and npm are present in the runtime stage apk add; no network calls, no mocks.

Reviews (1): Last reviewed commit: "fix(docker): install npm in runtime stag..." | Re-trigger Greptile

@codecov

codecov Bot commented Jul 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@codspeed

codspeed Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing litellm_fix_docker_runtime_npm_prisma_migrate (3154bb7) with litellm_internal_staging (4d33964)

Open in CodSpeed

@github-actions

Copy link
Copy Markdown
Contributor

#24554 was fixed by #33853 and #33650 by #33853 on main, so this pull request is closed. Reopen it if something was missed.

@github-actions github-actions Bot closed this Sep 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants