From fc9869c1a92d3c440428008ffec850790f47a877 Mon Sep 17 00:00:00 2001 From: Thomas Kolar Date: Fri, 28 Feb 2025 16:06:25 +0100 Subject: [PATCH 1/6] fix docker complaining about casing in dockerfile --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index da4f7ba4..f17cf7f3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.11 as production +FROM python:3.11 AS production # Update the package listing, so we know what packages exist RUN apt-get update From 84f0d1fe4057cde485ade5be811fb8fcd9477370 Mon Sep 17 00:00:00 2001 From: Thomas Kolar Date: Fri, 28 Feb 2025 16:07:16 +0100 Subject: [PATCH 2/6] don't pin UV to an ancient version --- Dockerfile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index f17cf7f3..9f6b66c2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -40,8 +40,7 @@ USER deploy RUN python -m venv $VIRTUAL_ENV # Add our python libraries for managing dependencies -uv 0.1.43 is triggering bad certificate errors, so we pin to 0.1.39 -RUN python -m pip install uv==0.1.39 wheel --upgrade +RUN python -m pip install uv wheel --upgrade # Copy application code, with dockerignore filtering out the stuff we don't want # from our final build artefact From eab80cf351885ecfbf86c3e6cccd164763df7274 Mon Sep 17 00:00:00 2001 From: Thomas Kolar Date: Fri, 28 Feb 2025 16:07:55 +0100 Subject: [PATCH 3/6] use uv sync instead of pip to install requirements --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 9f6b66c2..b4e4773c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -47,7 +47,7 @@ RUN python -m pip install uv wheel --upgrade COPY --chown=deploy . . # Install dependencies via uv -RUN uv pip install -r requirements/requirements.linux.generated.txt +RUN uv sync # Set up front end pipeline RUN python ./manage.py tailwind install From 8fd911caa3aa6e8a198766d42c0ae724a357fa88 Mon Sep 17 00:00:00 2001 From: Thomas Kolar Date: Fri, 28 Feb 2025 16:27:52 +0100 Subject: [PATCH 4/6] before copying the whole tree into the image, copy only the pyproject.toml and run uv sync to prevent any change in the tree from causing this step to run again --- Dockerfile | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index b4e4773c..8bf5215a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -42,12 +42,17 @@ RUN python -m venv $VIRTUAL_ENV # Add our python libraries for managing dependencies RUN python -m pip install uv wheel --upgrade +# Copy just the pyproject.toml for uv sync. +# That way, the next step can be cached until pyproject.toml changes. +COPY --chown=deploy ./pyproject.toml ./pyproject.toml + +# Install dependencies via uv +RUN uv sync + # Copy application code, with dockerignore filtering out the stuff we don't want # from our final build artefact COPY --chown=deploy . . -# Install dependencies via uv -RUN uv sync # Set up front end pipeline RUN python ./manage.py tailwind install From 03524cf5bc00bd8906a09d333c31bc5001abc1c7 Mon Sep 17 00:00:00 2001 From: Thomas Kolar Date: Fri, 28 Feb 2025 16:28:56 +0100 Subject: [PATCH 5/6] copy the envfile to the correct location so that future commands can use dotenv to load it --- .dockerignore | 1 + Dockerfile | 2 ++ 2 files changed, 3 insertions(+) diff --git a/.dockerignore b/.dockerignore index 65c2d395..30238f63 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,6 +1,7 @@ # ignore everything beginning with dot by default .* +!.env.docker ansible* diff --git a/Dockerfile b/Dockerfile index 8bf5215a..e8b01990 100644 --- a/Dockerfile +++ b/Dockerfile @@ -53,6 +53,8 @@ RUN uv sync # from our final build artefact COPY --chown=deploy . . +# Copy envfile to the correct location. +COPY --chown=deploy .env.docker .env # Set up front end pipeline RUN python ./manage.py tailwind install From 6a08ffc7e273f47d41d0a9705c2f078016fab67c Mon Sep 17 00:00:00 2001 From: Thomas Kolar Date: Fri, 28 Feb 2025 16:29:43 +0100 Subject: [PATCH 6/6] make commands that need it make use of dotenv --- Dockerfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index e8b01990..16f15389 100644 --- a/Dockerfile +++ b/Dockerfile @@ -57,8 +57,8 @@ COPY --chown=deploy . . COPY --chown=deploy .env.docker .env # Set up front end pipeline -RUN python ./manage.py tailwind install -RUN python ./manage.py tailwind build +RUN dotenv run -- python ./manage.py tailwind install +RUN dotenv run -- python ./manage.py tailwind build # Install the other node dependencies # TODO: we might not need node in production *at all* if we can generate @@ -69,7 +69,7 @@ RUN cd ./apps/theme/static_src/ && \ npx rollup --config # Collect static files -RUN python ./manage.py collectstatic --noinput --clear +RUN dotenv run -- python ./manage.py collectstatic --noinput --clear # Use the shell form of CMD, so we have access to our environment variables # $GUNICORN_CMD_ARGS allows us to add additional arguments to the gunicorn command