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]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
fix(docker): copy only runtime artifacts into the final image (#30243)
yuneng-jiang1fd8ab4c5f72
diff --git a/Dockerfile b/Dockerfileindex 9ad9ab31b65..4d55148ff89 100644--- a/Dockerfile+++ b/Dockerfile@@ -68,22 +68,24 @@ FROM $LITELLM_RUNTIME_IMAGE AS runtimeUSER root-RUN apk add --no-cache bash openssl tzdata nodejs npm python3 libsndfile && \- npm install -g [email protected] [email protected] [email protected] @isaacs/[email protected] [email protected] [email protected] [email protected] [email protected] && \- GLOBAL="$(npm root -g)" && \- for pkg in tar glob @isaacs/brace-expansion brace-expansion minimatch diff picomatch; do \- name="${pkg##*/}"; \- find "$GLOBAL/npm" -type d -name "$name" -path "*/node_modules/$pkg" | while read d; do \- rm -rf "$d" && cp -rL "$GLOBAL/$pkg" "$d"; \- done; \- done && \- npm cache clean --force && \- { apk del --no-cache npm 2>/dev/null || true; }+# node (without npm) is required by the prisma CLI at runtime+RUN apk add --no-cache bash openssl tzdata nodejs python3 libsndfileWORKDIR /appENV PATH="/app/.venv/bin:${PATH}"-COPY --from=builder /app /app+# Copy only what runtime needs. The application is installed inside the venv;+# the rest of the builder's /app is source and build metadata that must not+# ship (manifest-scanning tools attribute everything in it to this image).+# entrypoint.sh invokes litellm/proxy/prisma_migration.py by source path.+COPY --from=builder /app/.venv /app/.venv+COPY --from=builder /app/docker /app/docker+COPY --from=builder /app/schema.prisma /app/schema.prisma+COPY --from=builder /app/litellm/proxy/prisma_migration.py /app/litellm/proxy/prisma_migration.py+# enterprise/ is imported by source path at runtime (proxy_cli puts the+# working directory on sys.path; litellm/proxy/hooks resolves+# enterprise.enterprise_hooks from it)+COPY --from=builder /app/enterprise /app/enterprise# Prisma binaries live in $HOME/.cache (default prisma-python location),# which is /root/.cache here. Copy only the Prisma subdirs — copying the# whole /root/.cache drags in the uv build cache (~660 MB, includes adiff --git a/docker/Dockerfile.database b/docker/Dockerfile.databaseindex c84003a065f..e591a4a2adb 100644--- a/docker/Dockerfile.database+++ b/docker/Dockerfile.database@@ -66,36 +66,31 @@ FROM $LITELLM_RUNTIME_IMAGE AS runtimeUSER root-RUN apk add --no-cache bash openssl tzdata nodejs npm python3 libsndfile && \- npm install -g [email protected] [email protected] [email protected] @isaacs/[email protected] [email protected] [email protected] && \- GLOBAL="$(npm root -g)" && \- find "$GLOBAL/npm" -type d -name "tar" -path "*/node_modules/tar" | while read d; do \- rm -rf "$d" && cp -rL "$GLOBAL/tar" "$d"; \- done && \- find "$GLOBAL/npm" -type d -name "glob" -path "*/node_modules/glob" | while read d; do \- rm -rf "$d" && cp -rL "$GLOBAL/glob" "$d"; \- done && \- find "$GLOBAL/npm" -type d -name "brace-expansion" -path "*/node_modules/@isaacs/brace-expansion" | while read d; do \- rm -rf "$d" && cp -rL "$GLOBAL/@isaacs/brace-expansion" "$d"; \- done && \- find "$GLOBAL/npm" -type d -name "minimatch" -path "*/node_modules/minimatch" | while read d; do \- rm -rf "$d" && cp -rL "$GLOBAL/minimatch" "$d"; \- done && \- find "$GLOBAL/npm" -type d -name "diff" -path "*/node_modules/diff" | while read d; do \- rm -rf "$d" && cp -rL "$GLOBAL/diff" "$d"; \- done && \- npm cache clean --force && \- { apk del --no-cache npm 2>/dev/null || true; }+# node (without npm) is required by the prisma CLI at runtime+RUN apk add --no-cache bash openssl tzdata nodejs python3 libsndfileWORKDIR /appENV PATH="/app/.venv/bin:${PATH}"-COPY --from=builder /app /app+# Copy only what runtime needs. The application is installed inside the venv;+# the rest of the builder's /app is source and build metadata that must not+# ship (manifest-scanning tools attribute everything in it to this image).+# entrypoint.sh invokes litellm/proxy/prisma_migration.py by source path.+COPY --from=builder /app/.venv /app/.venv+COPY --from=builder /app/docker /app/docker+COPY --from=builder /app/schema.prisma /app/schema.prisma+COPY --from=builder /app/litellm/proxy/prisma_migration.py /app/litellm/proxy/prisma_migration.py+# enterprise/ is imported by source path at runtime (proxy_cli puts the+# working directory on sys.path; litellm/proxy/hooks resolves+# enterprise.enterprise_hooks from it)+COPY --from=builder /app/enterprise /app/enterprise# Prisma binaries live in $HOME/.cache (default prisma-python location),# which is /root/.cache here. Copy them from the builder so they survive# deployments that volume-mount /app/.cache (e.g. readOnlyRootFilesystem# + emptyDir) — otherwise the mount would shadow the baked-in query engine.-COPY --from=builder /root/.cache /root/.cache+# Only the Prisma subdirs: the whole /root/.cache drags in the uv build cache.+COPY --from=builder /root/.cache/prisma /root/.cache/prisma+COPY --from=builder /root/.cache/prisma-python /root/.cache/prisma-pythonRUN find /app/.venv -type f -path "*/tornado/test/*" -delete && \find /app/.venv -type d -path "*/tornado/test" -deletediff --git a/docker/Dockerfile.non_root b/docker/Dockerfile.non_rootindex 8717e5b3fcd..eafbd23fd90 100644--- a/docker/Dockerfile.non_root+++ b/docker/Dockerfile.non_root@@ -95,7 +95,21 @@ RUN for i in 1 2 3; do \apk add --no-cache python3 bash openssl tzdata libsndfile nodejs && break || sleep 5; \done-COPY --from=builder /app /app+# Copy only what runtime needs. The application is installed inside the venv;+# the rest of the builder's /app is source and build metadata that must not+# ship (manifest-scanning tools attribute everything in it to this image).+# entrypoint.sh invokes litellm/proxy/prisma_migration.py by source path.+# Prisma caches live under /app/.cache here (XDG_CACHE_HOME /+# PRISMA_BINARY_CACHE_DIR) so the runtime prisma generate finds them.+COPY --from=builder /app/.venv /app/.venv+COPY --from=builder /app/docker /app/docker+COPY --from=builder /app/schema.prisma /app/schema.prisma+COPY --from=builder /app/litellm/proxy/prisma_migration.py /app/litellm/proxy/prisma_migration.py+# enterprise/ is imported by source path at runtime (proxy_cli puts the+# working directory on sys.path; litellm/proxy/hooks resolves+# enterprise.enterprise_hooks from it)+COPY --from=builder /app/enterprise /app/enterprise+COPY --from=builder /app/.cache /app/.cacheCOPY --from=builder /var/lib/litellm/ui /var/lib/litellm/uiCOPY --from=builder /var/lib/litellm/assets /var/lib/litellm/assets