Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

fix(docker): bake prisma offline in the componentized migrations image (#35485)

Yassin Kortam72c888856312
diff --git a/.github/workflows/image-scan.yml b/.github/workflows/image-scan.yml
index 4d4a3242399..23aa6114f08 100644
--- a/.github/workflows/image-scan.yml
+++ b/.github/workflows/image-scan.yml
@@ -9,6 +9,8 @@ on:
- "litellm_**"
paths:
- docker/Dockerfile.non_root
+ - migrations/Dockerfile
+ - migrations/run.py
- tests/proxy_migration_tests/test_offline_image_migration.py
- uv.lock
- ui/litellm-dashboard/package-lock.json
@@ -83,3 +85,34 @@ jobs:
--only-fixed \
--fail-on high \
--output table
+
+ migrations-image:
+ name: migrations-image
+ runs-on: ubuntu-latest
+ if: >-
+ github.event_name != 'pull_request' ||
+ github.event.pull_request.head.repo.full_name == github.repository
+ timeout-minutes: 30
+ permissions:
+ contents: read
+ steps:
+ - uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4.3.0
+ with:
+ persist-credentials: false
+
+ - name: Build migrations image
+ run: docker build -f migrations/Dockerfile -t litellm-migrations-scan:${{ github.sha }} .
+
+ - name: Set up Python
+ uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
+ with:
+ python-version: "3.12"
+
+ - name: Verify offline migration as a non-root uid
+ env:
+ LITELLM_IMAGE: litellm-migrations-scan:${{ github.sha }}
+ LITELLM_MIGRATION_INTERPRETER: python3
+ LITELLM_MIGRATION_SCRIPT: /app/run.py
+ run: |
+ python -m pip install "pytest==9.0.3"
+ python -m pytest tests/proxy_migration_tests/test_offline_image_migration.py -v
diff --git a/migrations/Dockerfile b/migrations/Dockerfile
index b20284df000..52795d426ec 100644
--- a/migrations/Dockerfile
+++ b/migrations/Dockerfile
@@ -77,9 +77,9 @@ COPY migrations/run.py /app/run.py
# client at runtime — the migration job invokes `prisma migrate deploy`
# via subprocess — but having it cached is harmless and the alternative
# (`prisma py fetch`) doesn't reliably trigger engine downloads.
-RUN mkdir -p /home/nonroot && \
- HOME=/home/nonroot prisma generate --schema=./schema.prisma && \
- chown -R nonroot:nonroot /home/nonroot/.cache
+RUN HOME=/opt/prisma XDG_CACHE_HOME=/opt/prisma/.cache PRISMA_BINARY_CACHE_DIR=/opt/prisma/binaries \
+ npm_config_cache=/root/.npm \
+ prisma generate --schema=./schema.prisma
# ---------- Runtime ----------
FROM $LITELLM_RUNTIME_IMAGE AS runtime
@@ -87,7 +87,7 @@ FROM $LITELLM_RUNTIME_IMAGE AS runtime
USER root
RUN for i in 1 2 3; do \
- apk add --no-cache bash openssl tzdata python3 libsndfile libatomic && break; \
+ apk add --no-cache bash openssl tzdata python3 nodejs libsndfile libatomic && break; \
[ $i = 3 ] && { echo "apk add failed after 3 retries" >&2; exit 1; }; \
sleep 5; \
done
@@ -100,10 +100,18 @@ ENV HOME=/home/nonroot \
PATH="/app/.venv/bin:${PATH}" \
PYTHONPATH="/app" \
PYTHONDONTWRITEBYTECODE=1 \
- PYTHONUNBUFFERED=1
+ PYTHONUNBUFFERED=1 \
+ PRISMA_BINARY_CACHE_DIR=/opt/prisma/binaries \
+ PRISMA_CLI_PATH=/opt/prisma/binaries/node_modules/.bin/prisma \
+ PRISMA_CLI_QUERY_ENGINE_TYPE=binary \
+ PRISMA_OFFLINE_MODE=true
COPY --from=builder --chown=nonroot:nonroot /app /app
-COPY --from=builder --chown=nonroot:nonroot /home/nonroot/.cache /home/nonroot/.cache
+COPY --from=builder /opt/prisma /opt/prisma
+
+RUN chmod -R a+rX /opt/prisma && \
+ test -x /opt/prisma/binaries/node_modules/.bin/prisma && \
+ test -f /opt/prisma/binaries/node_modules/prisma/build/index.js
USER nonroot
diff --git a/tests/proxy_migration_tests/test_offline_image_migration.py b/tests/proxy_migration_tests/test_offline_image_migration.py
index 8ed88278e69..ae2ba703420 100644
--- a/tests/proxy_migration_tests/test_offline_image_migration.py
+++ b/tests/proxy_migration_tests/test_offline_image_migration.py
@@ -26,6 +26,11 @@ POSTGRES_IMAGE = os.getenv("LITELLM_TEST_POSTGRES_IMAGE", "postgres:16-alpine")
MIN_TABLES = int(os.getenv("LITELLM_TEST_MIN_TABLES", "20"))
NON_ROOT_UID = "12345:0" # arbitrary uid in GID 0, as OpenShift restricted-v2 assigns
+MIGRATION_INTERPRETER = os.getenv("LITELLM_MIGRATION_INTERPRETER", "python")
+MIGRATION_SCRIPT = os.getenv(
+ "LITELLM_MIGRATION_SCRIPT", "litellm/proxy/prisma_migration.py"
+)
+
pytestmark = [
pytest.mark.skipif(IMAGE is None, reason="requires a built image (set LITELLM_IMAGE)"),
pytest.mark.skipif(shutil.which("docker") is None, reason="requires the docker CLI"),
@@ -108,8 +113,8 @@ def test_migration_offline_as_non_root_uid(offline_postgres):
"-e", f"DATABASE_URL=postgresql://postgres:pw@{pg}:5432/litellm",
"-e", "LITELLM_MASTER_KEY=sk-offline-migration-test",
"-e", "DISABLE_SCHEMA_UPDATE=false",
- "-w", "/app", "--entrypoint", "python",
- IMAGE, "litellm/proxy/prisma_migration.py",
+ "-w", "/app", "--entrypoint", MIGRATION_INTERPRETER,
+ IMAGE, MIGRATION_SCRIPT,
check=False,
)
tables = _table_count(pg)