Dockerfile•1.77 kB
# Multi-stage Dockerfile for Hostaway MCP Server
# Stage 1: Builder - Install dependencies
# Stage 2: Runtime - Minimal production image
#
# Stage 1: Builder
#
FROM python:3.12-slim AS builder
# Set working directory
WORKDIR /app
# Install system dependencies for building Python packages
RUN apt-get update && apt-get install -y \
--no-install-recommends \
build-essential \
curl \
&& rm -rf /var/lib/apt/lists/*
# Install uv for fast dependency management
RUN curl -LsSf https://astral.sh/uv/install.sh | sh
ENV PATH="/root/.local/bin:$PATH"
# Copy dependency files and README (required by hatchling)
COPY pyproject.toml uv.lock README.md ./
# Install dependencies using uv (creates .venv)
RUN uv sync --frozen --no-dev
#
# Stage 2: Runtime
#
FROM python:3.12-slim
# Set working directory
WORKDIR /app
# Install only runtime system dependencies
RUN apt-get update && apt-get install -y \
--no-install-recommends \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*
# Copy virtual environment from builder
COPY --from=builder /app/.venv /app/.venv
# Copy application code
COPY src/ ./src/
COPY pyproject.toml ./
# Create non-root user for security
RUN useradd -m -u 1000 mcpuser && \
chown -R mcpuser:mcpuser /app
# Switch to non-root user
USER mcpuser
# Set Python path to use virtual environment
ENV PATH="/app/.venv/bin:$PATH" \
PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD python -c "import httpx; httpx.get('http://localhost:8000/health', timeout=5.0).raise_for_status()" || exit 1
# Expose port
EXPOSE 8000
# Run FastAPI app with uvicorn
CMD ["uvicorn", "src.api.main:app", "--host", "0.0.0.0", "--port", "8000"]