From e1f47694c1b5c0320b9b6146b8512a385bc3ad52 Mon Sep 17 00:00:00 2001 From: Anand Pant Date: Sat, 14 Feb 2026 20:49:22 -0600 Subject: [PATCH 1/2] Prewarm tiktoken cache for Foundry runtime Avoid runtime DNS/egress failures by caching cl100k_base during image build and setting TIKTOKEN_CACHE_DIR in the container. --- Dockerfile | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index b42983c..e9d4447 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,6 +16,11 @@ RUN uv sync --frozen --no-dev COPY src ./src COPY artifacts ./artifacts +# Pre-warm tiktoken encoding cache during build so the runtime does not +# need outbound access to openaipublic.blob.core.windows.net. +RUN mkdir -p /app/.tiktoken_cache \ + && TIKTOKEN_CACHE_DIR=/app/.tiktoken_cache python -c 'import tiktoken; tiktoken.get_encoding("cl100k_base")' + FROM python:3.13-slim AS runtime @@ -23,7 +28,8 @@ ARG SERVER_OPENAPI="{}" ENV PYTHONUNBUFFERED=1 \ PATH="/app/.venv/bin:${PATH}" \ - PYTHONPATH="/app" + PYTHONPATH="/app" \ + TIKTOKEN_CACHE_DIR="/app/.tiktoken_cache" WORKDIR /app @@ -33,9 +39,10 @@ RUN groupadd --gid 5000 app \ COPY --from=builder --chown=5000:5000 /app/.venv /app/.venv COPY --from=builder --chown=5000:5000 /app/src ./src COPY --from=builder --chown=5000:5000 /app/artifacts ./artifacts +COPY --from=builder --chown=5000:5000 /app/.tiktoken_cache /app/.tiktoken_cache COPY --chown=5000:5000 pyproject.toml uv.lock README.md ./ -RUN mkdir -p /app/data/.dspy_cache && chown -R 5000:5000 /app +RUN mkdir -p /app/data/.dspy_cache /app/.tiktoken_cache && chown -R 5000:5000 /app LABEL server.openapi="${SERVER_OPENAPI}" From 11572d3d5247df85603dba272304b6933740aa94 Mon Sep 17 00:00:00 2001 From: Anand Pant Date: Sat, 14 Feb 2026 20:55:01 -0600 Subject: [PATCH 2/2] Fix tiktoken prewarm to use venv python Use /app/.venv/bin/python so the build step can import tiktoken after uv sync. --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index e9d4447..9f0397d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -19,7 +19,7 @@ COPY artifacts ./artifacts # Pre-warm tiktoken encoding cache during build so the runtime does not # need outbound access to openaipublic.blob.core.windows.net. RUN mkdir -p /app/.tiktoken_cache \ - && TIKTOKEN_CACHE_DIR=/app/.tiktoken_cache python -c 'import tiktoken; tiktoken.get_encoding("cl100k_base")' + && TIKTOKEN_CACHE_DIR=/app/.tiktoken_cache /app/.venv/bin/python -c 'import tiktoken; tiktoken.get_encoding("cl100k_base")' FROM python:3.13-slim AS runtime