-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
71 lines (53 loc) · 1.79 KB
/
Dockerfile
File metadata and controls
71 lines (53 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# Multi-stage build for testmcpserver MCP server using uv
FROM python:3.12-slim AS builder
# Install uv
COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv
# Set working directory
WORKDIR /app
# Copy dependency files first for layer caching
COPY pyproject.toml .python-version* uv.lock* ./
COPY README.md ./
RUN if [ -f uv.lock ]; then \
echo "Using existing lockfile"; \
uv sync --frozen --no-dev --no-cache --no-install-project; \
else \
echo "Generating lockfile and installing dependencies"; \
uv sync --no-dev --no-cache --no-install-project; \
fi
# Copy source code
COPY src/ ./src/
COPY mcp.yaml ./
# Production stage
FROM python:3.12-slim
# Install uv in production
COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv
# Create non-root user
RUN groupadd -r mcpuser && useradd -r -g mcpuser mcpuser
# Set working directory
WORKDIR /app
# Copy virtual environment and application from builder
COPY --from=builder /app/.venv /app/.venv
COPY --from=builder /app/src /app/src
COPY --from=builder /app/mcp.yaml /app/mcp.yaml
COPY --from=builder /app/pyproject.toml /app/pyproject.toml
# Make sure scripts in .venv are usable
ENV PATH="/app/.venv/bin:$PATH"
# Install runtime dependencies only
RUN apt-get update && apt-get install -y \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*
# Change ownership to non-root user
RUN chown -R mcpuser:mcpuser /app
# Switch to non-root user
USER mcpuser
# Expose port (if needed for HTTP transport)
EXPOSE 8080
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD python -c "import src.main; print('healthy')"
# Set environment variables
ENV PYTHONPATH=/app
ENV PYTHONUNBUFFERED=1
ENV OTEL_SERVICE_NAME=testmcpserver
# Default command
CMD ["python", "src/main.py"]