openapi-mcp-server/Dockerfile
Tom Foster 6db4ea8e96
All checks were successful
CI / Build and push Docker image (push) Successful in 1m29s
Initial commit
2025-06-16 19:17:09 +01:00

47 lines
1.5 KiB
Docker

# Build stage using uv with a frozen lockfile and dependency caching
FROM ghcr.io/astral-sh/uv:python3.13-bookworm-slim AS uv
WORKDIR /app
# Enable bytecode compilation and copy mode
ENV UV_COMPILE_BYTECODE=1 \
UV_LINK_MODE=copy
# Install dependencies using the lockfile
COPY pyproject.toml uv.lock ./
RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --frozen --no-dev --no-editable --no-install-project
# Install the project in a second layer
COPY . .
RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --frozen --no-dev --no-editable
# Prepare runtime image
FROM python:3.13-slim-bookworm AS runtime
WORKDIR /app
# Install minimal system dependencies and create runtime user
RUN apt-get update && apt-get install -y curl \
&& rm -rf /var/lib/apt/lists/* \
&& groupadd -g 1000 omcps \
&& useradd -u 1000 -g 1000 -m omcps \
&& mkdir -p /data \
&& touch /data/memory.json \
&& chown -R 1000:1000 /data
# Copy only the virtual environment from the build stage
COPY --from=uv /app/.venv /app/.venv
# Switch to non-root user
USER omcps
# Set environment variables for runtime
ENV PATH="/app/.venv/bin:$PATH" \
PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
MEMORY_FILE_PATH="/data/memory.json"
# Use wrapper script to handle startup
ENTRYPOINT ["uvicorn", "openapi_mcp_server.server:create_app", "--factory", "--host", "0.0.0.0", "--port", "80"]
HEALTHCHECK --interval=30s --timeout=10s --retries=3 CMD curl -f http://localhost/health || exit 1