FROM python:3.8.10-slim-buster


LABEL authors="Patrick Jentsch <p.jentsch@uni-bielefeld.de>"


ARG DOCKER_GID
ARG UID
ARG GID


ENV LANG="C.UTF-8"
ENV PYTHONDONTWRITEBYTECODE="1"
ENV PYTHONUNBUFFERED="1"


RUN apt-get update \
 && apt-get install --no-install-recommends --yes \
      build-essential \
      libpq-dev \
 && rm --recursive /var/lib/apt/lists/*


RUN groupadd --gid "${DOCKER_GID}" docker \
 && groupadd --gid "${GID}" nopaque \
 && useradd --create-home --gid nopaque --groups "${DOCKER_GID}" --no-log-init --uid "${UID}" nopaque
USER nopaque
WORKDIR /home/nopaque


ENV PYTHON3_VENV_PATH="/home/nopaque/venv"
RUN python3 -m venv "${PYTHON3_VENV_PATH}"
ENV PATH="${PYTHON3_VENV_PATH}/bin:${PATH}"


COPY --chown=nopaque:nopaque requirements.txt .
RUN python3 -m pip install --requirement requirements.txt \
 && rm requirements.txt


COPY --chown=nopaque:nopaque app app
COPY --chown=nopaque:nopaque migrations migrations
COPY --chown=nopaque:nopaque tests tests
COPY --chown=nopaque:nopaque .flaskenv boot.sh config.py nopaque.py ./


EXPOSE 5000


ENTRYPOINT ["./boot.sh"]
