@@ -3,31 +3,39 @@ FROM python:3.12-slim-bookworm AS base
33LABEL company="20tab" project="{{ cookiecutter.project_slug }}" service="backend" stage="base"
44ARG DEBIAN_FRONTEND=noninteractive
55ARG USER=appuser
6- ENV APPUSER=$USER LANG=C.UTF-8 LC_ALL=C.UTF-8 PYTHONUNBUFFERED=1 PYTHONDONTWRITEBYTECODE=1 WORKDIR=/app
6+ ENV APPUSER=$USER \
7+ LANG=C.UTF-8 \
8+ LC_ALL=C.UTF-8 \
9+ PYTHONUNBUFFERED=1 \
10+ PYTHONDONTWRITEBYTECODE=1 \
11+ VIRTUAL_ENV=/opt/venv \
12+ WORKDIR=/app
713WORKDIR $WORKDIR
814RUN useradd --skel /dev/null --create-home $APPUSER
915RUN chown $APPUSER:$APPUSER $WORKDIR
10- ENV PATH="/home/${APPUSER}/.local /bin:${PATH}"
11- ARG PACKAGES_PATH=/home/${APPUSER}/.local /lib/python3.12/site-packages
16+ ENV PATH="${VIRTUAL_ENV} /bin:${PATH}"
17+ ARG PACKAGES_PATH=${VIRTUAL_ENV} /lib/python3.12/site-packages
1218RUN apt-get update \
1319 && apt-get install --assume-yes --no-install-recommends \
1420 libpq5 \
1521 && rm -rf /var/lib/apt/lists/*
1622COPY --chown=$APPUSER ./requirements/base.txt requirements/base.txt
23+ RUN python3 -m venv $VIRTUAL_ENV \
24+ && chown -R $APPUSER:$APPUSER $VIRTUAL_ENV
1725RUN apt-get update \
1826 && apt-get install --assume-yes --no-install-recommends \
1927 gcc \
2028 libc6-dev \
2129 libpq-dev \
22- && su $APPUSER -c "python3 -m pip install --user -- no-cache-dir -r requirements/base.txt" \
30+ && su $APPUSER -c "python3 -m pip install --no-cache-dir -r requirements/base.txt" \
2331 && find ${PACKAGES_PATH} -regex '^.*/locale/.*/*.\( mo\| po\) $' -not -path '*/en*' -not -path '*/it*' -delete || true \
2432 && apt-get purge --assume-yes --auto-remove \
2533 gcc \
2634 libc6-dev \
2735 libpq-dev \
2836 && rm -rf /var/lib/apt/lists/*
2937COPY --chown=$APPUSER ./requirements/common.txt requirements/common.txt
30- RUN su $APPUSER -c "python3 -m pip install --user -- no-cache-dir -r requirements/common.txt" \
38+ RUN su $APPUSER -c "python3 -m pip install --no-cache-dir -r requirements/common.txt" \
3139 && find ${PACKAGES_PATH} -regex '^.*/locale/.*/*.\( mo\| po\) $' -not -path '*/en*' -not -path '*/it*' -delete || true
3240
3341FROM base AS test
@@ -36,7 +44,7 @@ LABEL company="20tab" project="{{ cookiecutter.project_slug }}" service="backend
3644ENV DJANGO_CONFIGURATION=Testing
3745USER $APPUSER
3846COPY --chown=$APPUSER ./requirements/test.txt requirements/test.txt
39- RUN python3 -m pip install --user -- no-cache-dir -r requirements/test.txt
47+ RUN python3 -m pip install --no-cache-dir -r requirements/test.txt
4048COPY --chown=$APPUSER . .
4149CMD ./scripts/test.sh
4250
@@ -45,9 +53,9 @@ FROM base AS remote
4553LABEL company="20tab" project="{{ cookiecutter.project_slug }}" service="backend" stage="remote"
4654ENV DJANGO_CONFIGURATION=Remote INTERNAL_SERVICE_PORT={{ cookiecutter.internal_service_port }}
4755USER $APPUSER
48- ARG PACKAGES_PATH=/home/${APPUSER}/.local /lib/python3.12/site-packages
56+ ARG PACKAGES_PATH=${VIRTUAL_ENV} /lib/python3.12/site-packages
4957COPY --chown=$APPUSER ./requirements/remote.txt requirements/remote.txt
50- RUN python3 -m pip install --user -- no-cache-dir -r requirements/remote.txt \
58+ RUN python3 -m pip install --no-cache-dir -r requirements/remote.txt \
5159 && find ${PACKAGES_PATH}/boto*/data/* -maxdepth 0 -type d -not -name s3* -exec rm -rf {} \; || true
5260COPY --chown=$APPUSER . .
5361RUN DJANGO_SECRET_KEY=build python3 -m manage collectstatic --clear --link --noinput
@@ -71,7 +79,8 @@ RUN apt-get update \
7179 postgresql-client
7280USER $APPUSER
7381COPY --chown=$APPUSER ./requirements/local.txt requirements/local.txt
74- RUN python3 -m pip install --user --no-cache-dir -r requirements/local.txt
82+ RUN python3 -m pip install --no-cache-dir -r requirements/local.txt \
83+ && find ${PACKAGES_PATH} -regex '^.*/locale/.*/*.\( mo\| po\) $' -not -path '*/en*' -not -path '*/it*' -delete || true
7584COPY --chown=$APPUSER . .
7685RUN DJANGO_SECRET_KEY=build python3 -m manage collectstatic --clear --link --noinput
7786ENTRYPOINT ["./scripts/entrypoint.sh" ]
0 commit comments