aboutsummaryrefslogblamecommitdiffstats
path: root/Dockerfile
blob: 14951254155992be697c7de6ff54f4f322cbaccb (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12

                                                    

                                 
                                  
 





                                                                  
                         

                             
 



                                                














                                               









                                                                                   

                                                            


                                                                           








                                                     
FROM docker.io/python:3.12.3-slim-bookworm as python

FROM python as python-build-stage

ARG BUILD_ENVIRONMENT=requirements

RUN apt-get update && apt-get install --no-install-recommends -y \
  # dependencies for building Python packages
  build-essential \
  # psycopg dependencies
  libpq-dev

COPY ./requirements.txt .
COPY ./wait-for-it.sh .
RUN chmod +x ./wait-for-it.sh

RUN pip wheel --wheel-dir /usr/src/app/wheels  \
  -r ${BUILD_ENVIRONMENT}.txt


FROM python as python-run-stage

ARG BUILD_ENVIRONMENT=production
ARG APP_HOME=/app

ENV PYTHONUNBUFFERED 1
ENV PYTHONDONTWRITEBYTECODE 1
ENV BUILD_ENV ${BUILD_ENVIRONMENT}

WORKDIR ${APP_HOME}

RUN addgroup --system django \
    && adduser --system --ingroup django django


RUN apt-get update && apt-get install --no-install-recommends -y \
  libmagic1 \
  # psycopg dependencies
  libpq-dev \
  # Translations dependencies
  gettext \
  # cleaning up unused files
  && apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \
  && rm -rf /var/lib/apt/lists/*

COPY --from=python-build-stage /usr/src/app/wheels  /wheels/

RUN pip install --no-cache-dir --no-index --find-links=/wheels/ /wheels/* \
  && rm -rf /wheels/

COPY --chown=django:django . ${APP_HOME}

# make django owner of the WORKDIR directory as well.
RUN chown -R django:django ${APP_HOME}

USER django

RUN chmod +x docker-entrypoint.sh
ENTRYPOINT ["/app/docker-entrypoint.sh"]