1- # Multi-stage build for Managed Notifications Search MCP Server
2- # Stage 1: Build embeddings (only rebuilds when notifications or script changes)
3- FROM python:3.13-slim as embeddings-builder
1+ # Alternative Containerfile that downloads model and builds embeddings at runtime
2+ # This reduces image size significantly but adds 2-5 minutes to startup time
3+
4+ FROM python:3.13-slim
45
56# Install uv
67COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /usr/local/bin/
78
89# Set working directory
910WORKDIR /app
11+ ENV UV_NO_CACHE=1
1012
1113# Copy all source files
1214COPY pyproject.toml ./
@@ -15,50 +17,30 @@ COPY uv.lock ./
1517# Install dependencies and project
1618RUN uv sync --frozen --no-dev
1719
18- # Pre-download the sentence transformer model
19- RUN uv run python -c "from sentence_transformers import SentenceTransformer; SentenceTransformer('all-MiniLM-L6-v2')"
20-
21- # Build embeddings database
20+ # Copy notification templates and scripts (embeddings built at runtime)
2221COPY scripts/ ./scripts/
2322COPY managed-notifications/ ./managed-notifications/
24- RUN uv run scripts/build_embeddings.py
25-
26- # Stage 2: Runtime image with MCP server
27- FROM python:3.13-slim as runtime
28-
29- # Install uv
30- COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /usr/local/bin/
31-
32- # Set working directory
33- WORKDIR /app
34-
35- # Copy all source files
36- COPY pyproject.toml ./
37- COPY uv.lock ./
38-
39- # Install dependencies and project
40- RUN uv sync --frozen --no-dev
41-
42- # Pre-download the sentence transformer model
43- RUN uv run python -c "from sentence_transformers import SentenceTransformer; SentenceTransformer('all-MiniLM-L6-v2')"
44-
45- # Copy pre-built embeddings database from builder stage
46- COPY --from=embeddings-builder /app/chroma_db/ ./chroma_db/
4723
4824# Set environment variables for MCP server
4925ENV HOST=0.0.0.0
5026ENV PORT=8000
27+ ENV HF_HOME=/tmp/huggingface
28+ ENV TRANSFORMERS_CACHE=/tmp/huggingface
29+ ENV CHROMA_DB_PATH=/tmp/chroma_db
5130
5231# Copy mcp server code
5332COPY main.py ./
5433
55- # Create non-root user for security
56- RUN useradd --create-home --shell /bin/bash mcp
57- RUN chown -R mcp:mcp /app
58- USER mcp
34+ # Create startup script that builds embeddings and starts server
35+ RUN echo '#!/bin/sh\n \
36+ echo "Building embeddings database (this may take 2-5 minutes)..."\n \
37+ uv run --no-sync scripts/build_embeddings.py\n \
38+ echo "Embeddings built, starting MCP server..."\n \
39+ exec uv run --no-sync main.py' > /app/start.sh && \
40+ chmod 755 /app/start.sh
5941
6042# Expose port for MCP server
6143EXPOSE 8000
6244
6345# Default command
64- CMD ["uv" , "run" , "main.py " ]
46+ CMD ["/app/start.sh " ]
0 commit comments