From 55604939ede7f5639b3ad7c5786b4f63aeb83f86 Mon Sep 17 00:00:00 2001 From: Patryk Bratkowski <151854505+pbratkowski@users.noreply.github.com> Date: Sat, 14 Dec 2024 18:11:34 +0200 Subject: [PATCH] Added 'KEEP_DEPENDENCIES' Docker argument As per #1817, tox is missing build dependencies and cannot run tests in containers. This commit added an argument to make purging packages optional, allowing to optimize image for deployment, while also keeping the required packages in dev environments. --- Dockerfile | 9 +++++++-- docker-compose.yml | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 19a42f83e..f61f3f834 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,9 @@ # pull official base image FROM python:3.12-slim-bookworm +# Overridden in docker-compose.yml to fix tox in Docker +ARG KEEP_DEPENDENCIES=False + # set work directory WORKDIR /usr/src/app @@ -34,11 +37,13 @@ RUN apt-get update \ libpq-dev \ zlib1g-dev \ && python3 -m pip install --no-cache-dir -r ${REQ_FILE} \ - && apt-get purge --assume-yes --auto-remove \ + && if [ "${KEEP_DEPENDENCIES}" != "True" ]; then \ + apt-get purge --assume-yes --auto-remove \ gcc \ libc6-dev \ libpq-dev \ - zlib1g-dev \ + zlib1g-dev; \ + fi \ && rm -rf /var/lib/apt/lists/* # install node dependencies diff --git a/docker-compose.yml b/docker-compose.yml index 8f875e2b5..0730523cb 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,6 +5,7 @@ services: dockerfile: Dockerfile args: - REQ_FILE=requirements/tests.txt + - KEEP_DEPENDENCIES=True entrypoint: ./docker-entrypoint.dev.sh command: python manage.py runserver 0.0.0.0:8000 volumes: