FROM python@sha256:c66cf219ac0083a9af2ff90e16530f16cd503c59eb7909feb3b8f3524dc1a87e
# python:3.12.2-slim-bullseye (amd64)
RUN useradd costhive

WORKDIR /home/costhive

RUN apt update && apt -y upgrade; \
    apt install -y libpq-dev gcc g++ swig make cmake m4; \
    rm -rf /var/lib/apt/lists

COPY boot.sh backend/requirements.txt ./
RUN python -m venv venv; \
    venv/bin/pip install --upgrade pip; \
    venv/bin/pip install wheel gunicorn; \
    venv/bin/pip install -r requirements.txt

COPY backend backend

ENV FLASK_APP=run.py

RUN chmod +x boot.sh; \
    chown -R costhive:costhive .

USER costhive

EXPOSE 5000
ENTRYPOINT ["./boot.sh"]