# Use an official Python runtime as a parent image
FROM python:3.12-slim
# Set the working directory in the container
WORKDIR /app
# Copy requirements first for better caching
COPY requirements.txt .
# Install any needed packages specified in requirements.txt
RUN pip install --no-cache-dir -r requirements.txt
# Copy the current directory contents into the container at /app
COPY . /app
# Create a non-root user for security
RUN groupadd -r appuser && useradd -r -g appuser appuser
RUN chown -R appuser:appuser /app
USER appuser
# Make ports available to the world outside this container
EXPOSE 8001 8002
# Define environment variables
ENV PYTHONUNBUFFERED=1
ENV PYTHONPATH=/app/src
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD python -c "import httpx; httpx.get('http://localhost:${MCP_HTTP_PORT:-8001}/health', timeout=5)" || exit 1
# Run FastMCP server when the container launches
CMD ["python", "src/fastmcp_server.py"]