# Use Python 3.11 slim image
FROM python:3.11-slim

# Set working directory
WORKDIR /app

# Copy shared directory from parent context (required by pyproject.toml force-include)
COPY shared /shared

# Copy project files
COPY data-migration-orchestrator/pyproject.toml data-migration-orchestrator/README.md ./
COPY data-migration-orchestrator/src/ ./src/

# Install the package and dependencies
RUN pip install --no-cache-dir -e .
# TODO(SNOW-2860314): move dependency installation before the part in which we copy the source code to leverage Docker layer caching

# Set the Python path
ENV PYTHONPATH=/app/src

# Disable Python output buffering to see logs in real-time
ENV PYTHONUNBUFFERED=1

# Create non-root user and pre-create writable dirs
RUN groupadd --system appgroup && useradd --system --gid appgroup appuser \
    && mkdir -p /app/logs && chown appuser:appgroup /app/logs
USER appuser

# Run the main module
CMD ["python", "-u", "-m", "data_migration_orchestrator"]
