FROM python:3.12-slim

# Prevent python from buffering stdout/stderr
ENV PYTHONUNBUFFERED=1
ENV PYTHONDONTWRITEBYTECODE=1

WORKDIR /app

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

# Copy dependency definition and install
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# Copy application script
COPY dms.py .

# Standard non-root user for security
RUN useradd -u 1000 -m appuser && chown -R appuser:appuser /app
USER appuser

# Defaults for Google Cloud Run
ENV PORT=8080
EXPOSE 8080

# Default entrypoint supports both Cloud Run Jobs (CLI) and Cloud Run Services (HTTP)
ENTRYPOINT ["python3", "dms.py"]
CMD ["--http"]
