FROM python:3.9 as builder # enchant dependency for sphinx RUN apt-get update && apt-get install -y python-enchant # copy source files WORKDIR /access_controller/ COPY ./ /access_controller # dev requirements for building sphinx docs RUN pip install -r requirements/dev.txt -r requirements/prod.txt # build static and documentation files into build/webserver RUN ./manage.py collectstatic --no-input && ./documentation.sh # create production venv to copy to final image # production venv is built here because `cryptography` requires rust which doesn't ship on alpine RUN python -m venv venv && venv/bin/pip install -r requirements/prod.txt # move files necessary to run the app to the build folder (including production venv) RUN mv venv access_controller main manage.py build FROM python:3.9-alpine WORKDIR /access_controller/ COPY --from=builder ["/access_controller/build", "./"] RUN apk update && apk add postgresql-libs && adduser -D -H -u 5579 actrl && chmod -R -w ./ USER actrl EXPOSE 8000 CMD . venv/bin/activate && \ python manage.py migrate && \ cp -rT webserver srv && \ daphne -b 0.0.0.0 access_controller.asgi:application