Skip to content

Commit 486af12

Browse files
Merge pull request #385 from geowa4/update-containerfile-for-openshift-deployment
perf(mcp): optimize container for OpenShift deployment
2 parents fecdd5c + de8b630 commit 486af12

File tree

4 files changed

+22
-39
lines changed

4 files changed

+22
-39
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ build-container:
3838
@mkdir -p mcp/managed-notifications
3939
@cp -r cluster hcp ocm osd rosa scripts mcp/managed-notifications/
4040
@echo "Building container with podman..."
41-
cd mcp && podman build --no-cache -t managed-notifications-search .
41+
cd mcp && podman build --no-cache $(shell [ "$$(uname)" = "Darwin" ] && echo "--platform linux/amd64") -t managed-notifications-search:latest -f Containerfile .

mcp/Containerfile

Lines changed: 17 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
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
67
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /usr/local/bin/
78

89
# Set working directory
910
WORKDIR /app
11+
ENV UV_NO_CACHE=1
1012

1113
# Copy all source files
1214
COPY pyproject.toml ./
@@ -15,50 +17,30 @@ COPY uv.lock ./
1517
# Install dependencies and project
1618
RUN 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)
2221
COPY scripts/ ./scripts/
2322
COPY 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
4925
ENV HOST=0.0.0.0
5026
ENV 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
5332
COPY 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
6143
EXPOSE 8000
6244

6345
# Default command
64-
CMD ["uv", "run", "main.py"]
46+
CMD ["/app/start.sh"]

mcp/main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""MCP server for searching managed service notification logs."""
22

33
import json
4+
import os
45
from pathlib import Path
56
from typing import Any, Dict, List
67

@@ -113,7 +114,7 @@ def search_notifications(
113114

114115
# Initialize the search server
115116
project_root = Path(__file__).parent
116-
db_path = project_root / "chroma_db"
117+
db_path = Path(os.getenv("CHROMA_DB_PATH", str(project_root / "chroma_db")))
117118
search_server = NotificationSearchServer(db_path)
118119

119120

mcp/scripts/build_embeddings.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,9 @@ def main() -> None:
182182
"""Main function to build embeddings database."""
183183
script_dir = Path(__file__).parent
184184
project_root = script_dir.parent
185-
185+
186186
notifications_dir = project_root / "managed-notifications"
187-
db_path = project_root / "chroma_db"
187+
db_path = Path(os.getenv("CHROMA_DB_PATH", str(project_root / "chroma_db")))
188188

189189
if not notifications_dir.exists():
190190
print(f"Error: Managed notifications directory not found at {notifications_dir}")

0 commit comments

Comments
 (0)