-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathDockerfile
More file actions
66 lines (51 loc) · 1.86 KB
/
Dockerfile
File metadata and controls
66 lines (51 loc) · 1.86 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
# Efficient multi-stage build using official uv image
# Stage 1: Build dependencies with uv
FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim AS builder
# Set working directory
WORKDIR /app
# Enable bytecode compilation for faster startup
ENV UV_COMPILE_BYTECODE=1 \
UV_LINK_MODE=copy \
UV_PYTHON_DOWNLOADS=never
# Install system build dependencies (only for psycopg2)
RUN apt-get update && apt-get install -y --no-install-recommends \
gcc \
python3-dev \
libpq-dev \
&& rm -rf /var/lib/apt/lists/*
# Copy dependency files first (better caching)
COPY pyproject.toml uv.lock ./
# Install dependencies using uv sync (creates .venv automatically)
RUN uv sync --frozen --no-dev
# Copy source code
COPY src/ ./src/
COPY README.md ./
# The package is already installed via uv sync
# Fix shebangs to point to correct location after copy
RUN sed -i 's|#!/app/.venv/bin/python|#!/opt/venv/bin/python|' /app/.venv/bin/*
# Stage 2: Minimal runtime image
FROM python:3.12-slim
# Install only PostgreSQL runtime library
RUN apt-get update && \
apt-get install -y --no-install-recommends libpq5 && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# Create non-root user
RUN useradd -m -u 1000 mcpuser
# Copy virtual environment from builder (uv creates .venv by default)
COPY --from=builder --chown=mcpuser:mcpuser /app/.venv /opt/venv
# Also copy the source code since it's referenced
COPY --from=builder --chown=mcpuser:mcpuser /app/src /opt/venv/lib/python3.12/site-packages/src
# Set environment
ENV PATH="/opt/venv/bin:$PATH" \
PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1
# Switch to non-root user
USER mcpuser
WORKDIR /home/mcpuser
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD python -c "import psycopg2; print('healthy')" || exit 1
# Entry point
ENTRYPOINT ["mcp-server-aact"]
CMD []