# syntax=docker/dockerfile:1
FROM python:3.11
ARG OPERATION

RUN useradd -d /code xf
RUN mkdir -p /code
RUN chown -R xf:xf /code

RUN mkdir -p /conf/static
RUN chown -R xf:xf /conf

RUN mkdir /venv
RUN chown xf:xf /venv

RUN apt-get update && apt-get install -y cargo rustc

ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
WORKDIR /code
COPY requirements.txt /code/
RUN python -m venv /venv
RUN . /venv/bin/activate && pip install -r requirements.txt
RUN chown -R xf:xf /code /venv /conf

USER xf
CMD if [ "$OPERATION" = "uwsgi" ] ; then . /venv/bin/activate && uwsgi --ini /conf/uwsgi.ini ; else . /venv/bin/activate && exec python manage.py runserver 0.0.0.0:8000; fi
