FROM debian:bullseye

ARG KEYPME_SERVER_HOST

# 'psmsic' for killall support
RUN apt-get -o Acquire::Check-Valid-Until=false update && apt install -y psmisc \
				   python3 python3-pip \
				   libffi-dev \
				   git \
				   postgresql-common postgresql-server-dev-13 \
				   libldap2-dev libsasl2-dev

ENV PYTHONUNBUFFERED 1

# Copy current code requirements to prepare the docker image
RUN mkdir /code
COPY . /code/

RUN pip3 install -r /code/requirements.txt
# Note: 'python_kadmin-0.1.2+twtr-cp39-cp39-linux_x86_64.whl ' has been copied by 'ci/gitlab-ci.yml'
#RUN pip3 install /code/python_kadmin-0.1.2+twtr-cp39-cp39-linux_x86_64.whl

# PYTHONPATH for the server
ENV PYTHONPATH "/code/:${PYTHONPATH}"

# Create directory for Django's static, logs, media
RUN mkdir -p /static
RUN mkdir -p /logs
RUN mkdir -p /media

#
# Collect static into the shared folder /staticfiles
#

ENV KEYPME_SERVER_HOST   ${KEYPME_SERVER_HOST}
# KEYPME_REALM,KEYPME_LDAP_BASE_DN does not need to be set to its real value at this stage
ENV KEYPME_REALM         SAMDOM
ENV KEYPME_LDAP_BASE_DN  "dc=samdom,dc=vm-keypme-server"
#ENV BIOSENCY_CREDENTIALS_ROOT /credentials
ENV DJANGO_SETTINGS_MODULE keypme_server.settings.docker
#RUN mkdir /credentials
# We need credentials to start Django
#COPY ./credentials/ /credentials
RUN python3 code/manage.py collectstatic --noinput
#RUN rm -Rf /credentials
