FROM python:3.12-slim

ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
ENV PYTHONPATH=/app

RUN apt-get update && apt-get install -y --no-install-recommends \
    gcc \
    libpq-dev \
    curl \
    && rm -rf /var/lib/apt/lists/*

WORKDIR /app

COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

COPY services/ /app/services/

RUN useradd -m -u 1000 stonks && \
    chown -R stonks:stonks /app

USER stonks

ARG SERVICE_CMD="python -m services.scheduler.app"
ENV SERVICE_CMD=${SERVICE_CMD}

CMD ["sh", "-c", "${SERVICE_CMD}"]
