mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-28 00:00:38 +00:00
The standalone migration entrypoint re-runs `prisma generate` after the migration completes. That refresh writes into the installed prisma package in site-packages, which an arbitrary non-root uid cannot do, and which no uid can do under a read-only root filesystem. Both are supported configurations of the migrations Job: helm/litellm-helm/tests/migrations-job_tests.yaml asserts runAsNonRoot, runAsUser and readOnlyRootFilesystem all render. The write has always failed there, but the failure used to be swallowed. Making migration failures fatal turned it into a hard exit 1, so a Job that applied every migration correctly now reports Failed and blocks the rollout it was supposed to gate. The refresh is redundant in the shipped images: every Dockerfile generates the client at build time from the same baked schema, copies it into the runtime stage, and asserts it resolves there. It stays load-bearing only for a source checkout, where CircleCI runs the entrypoint under `set +e` and ignores the exit code anyway. So the call stays and only its exit code stops propagating; migration failures are still fatal. image-scan never ran on the change that introduced this, because its path filter did not list the entrypoint it exercises. Add prisma_migration.py and entrypoint.sh so the non-root offline migration test gates them from now on.
45 lines
1.6 KiB
Python
45 lines
1.6 KiB
Python
"""Standalone entrypoint for applying database migrations and generating the Prisma client.
|
|
|
|
Migration failures fail the entrypoint by default; set ENFORCE_PRISMA_MIGRATION_CHECK=false
|
|
for log-only behavior. A failed 'prisma generate' is always log-only: every shipped image
|
|
bakes the client at build time, and refreshing it writes into site-packages, which an
|
|
arbitrary non-root uid or a read-only root filesystem cannot do.
|
|
"""
|
|
|
|
import os
|
|
import subprocess
|
|
import sys
|
|
|
|
sys.path.insert(0, os.path.abspath("./"))
|
|
|
|
from typing import Final
|
|
|
|
from litellm._logging import verbose_proxy_logger
|
|
from litellm.proxy.proxy_cli import run_server
|
|
from litellm.secret_managers.main import str_to_bool
|
|
|
|
|
|
def main() -> int:
|
|
enforce_prisma_migration_check: Final = str_to_bool(os.getenv("ENFORCE_PRISMA_MIGRATION_CHECK")) is not False
|
|
run_server_args: Final = (
|
|
("--skip_server_startup", "--enforce_prisma_migration_check")
|
|
if enforce_prisma_migration_check
|
|
else ("--skip_server_startup",)
|
|
)
|
|
run_server(run_server_args, standalone_mode=False)
|
|
|
|
verbose_proxy_logger.info("Running 'prisma generate'...")
|
|
result: Final = subprocess.run(("prisma", "generate"), capture_output=True, text=True)
|
|
verbose_proxy_logger.info("'prisma generate' stdout: %s", result.stdout)
|
|
|
|
if result.returncode != 0:
|
|
verbose_proxy_logger.warning(
|
|
"'prisma generate' exited %s; continuing with the client baked at image build time. stderr: %s",
|
|
result.returncode,
|
|
result.stderr,
|
|
)
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|