content: FROM python:3.11-slim as builder
  
  # Install system dependencies for building
  RUN apt-get update && apt-get install -y \
      gcc \
      g++ \
      libpq-dev \
      libssl-dev \
      libffi-dev \
      curl \
      && rm -rf /var/lib/apt/lists/*
  
  # Create virtual environment
  RUN python -m venv /opt/venv
  ENV PATH="/opt/venv/bin:$PATH"
  
  # Copy requirements files
  COPY pyproject.toml uv.lock ./
  
  # Install Python dependencies using uv
  RUN pip install --no-cache-dir uv && \
      uv pip install --no-cache-dir -r uv.lock
  
  # Production stage
  FROM python:3.11-slim
  
  # Install runtime dependencies
  RUN apt-get update && apt-get install -y \
      libpq5 \
      libssl3 \
      curl \
      && rm -rf /var/lib/apt/lists/*
  
  # Copy virtual environment from builder stage
  COPY --from=builder /opt/venv /opt/venv
  ENV PATH="/opt/venv/bin:$PATH"
  
  # Create non-root user
  RUN groupadd -r trustsvc && useradd -r -g trustsvc -d /app -s /bin/bash trustsvc
  
  # Set working directory
  WORKDIR /app
  
  # Copy application code
  COPY services/trust-svc/ ./
  COPY src/marty_common/ ./marty_common/
  
  # Create necessary directories
  RUN mkdir -p logs data && \
      chown -R trustsvc:trustsvc /app
  
  # Switch to non-root user
  USER trustsvc
  
  # Health check
  HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
      CMD curl -f http://localhost:8080/health || exit 1
  
  # Expose ports
  EXPOSE 8080 9090 8081
  
  # Set environment variables
  ENV PYTHONPATH=/app
  ENV PYTHONUNBUFFERED=1
  ENV LOG_LEVEL=INFO
  
  # Run the application
  CMD ["python", "-m", "uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8080"]