# Design System Server (DSS) - Docker Image
# Version: 0.8.0

FROM python:3.11-slim

LABEL maintainer="DSS Team"
LABEL version="0.8.0"
LABEL description="Design System Server with MCP integration"

# Set environment variables
ENV PYTHONUNBUFFERED=1 \
    PYTHONDONTWRITEBYTECODE=1 \
    PIP_NO_CACHE_DIR=1 \
    PIP_DISABLE_PIP_VERSION_CHECK=1

# Install system dependencies
RUN apt-get update && apt-get install -y \
    sqlite3 \
    curl \
    && rm -rf /var/lib/apt/lists/*

# Create app user
RUN useradd -m -u 1000 dss && \
    mkdir -p /app && \
    chown -R dss:dss /app

# Set working directory
WORKDIR /app

# Copy requirements
COPY requirements.txt .

# Install Python dependencies
RUN pip install --no-cache-dir -r requirements.txt

# Copy application code
COPY --chown=dss:dss . .

# Create data directories
RUN mkdir -p /app/.dss/cache && \
    chown -R dss:dss /app/.dss

# Switch to app user
USER dss

# Expose port
EXPOSE 3456

# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
    CMD curl -f http://localhost:3456/health || exit 1

# Set working directory to tools/api
WORKDIR /app/tools/api

# Run server
CMD ["python3", "-m", "uvicorn", "server:app", "--host", "0.0.0.0", "--port", "3456"]
