From 99868e4e805db11085f6a0cc7030b616b501bbe3 Mon Sep 17 00:00:00 2001 From: tooboredtocode Date: Mon, 8 Apr 2024 23:56:49 +0200 Subject: [PATCH 1/2] Reapply "Merge pull request #3055 from tooboredtocode/develop" This reverts commit f14acc371d7cf7ac7bcd6c1bd102f7d3c6a6b2b8. --- Dockerfile | 8 ++++++++ boot.sh | 17 +++++++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 3f17d0f11..c5856bcfa 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,6 +6,8 @@ RUN apk add --no-cache postgresql-libs postgresql-client gettext zlib libjpeg li #Print all logs without buffering it. ENV PYTHONUNBUFFERED 1 +ENV DOCKER true + #This port will be used by gunicorn. EXPOSE 8080 @@ -33,6 +35,12 @@ RUN apk add --no-cache --virtual .build-deps gcc musl-dev postgresql-dev zlib-de #Copy project and execute it. COPY . ./ +# collect the static files +RUN /opt/recipes/venv/bin/python manage.py collectstatic_js_reverse +RUN /opt/recipes/venv/bin/python manage.py collectstatic --noinput +# copy the collected static files to a different location, so they can be moved into a potentially mounted volume +RUN mv /opt/recipes/staticfiles /opt/recipes/staticfiles-collect + # collect information from git repositories RUN /opt/recipes/venv/bin/python version.py # delete git repositories to reduce image size diff --git a/boot.sh b/boot.sh index ae3dbb51d..ab5d7fddd 100644 --- a/boot.sh +++ b/boot.sh @@ -67,12 +67,21 @@ echo "Migrating database" python manage.py migrate -echo "Generating static files" +if [[ "${DOCKER}" == "true" ]]; then + echo "Copying cached static files from docker build" -python manage.py collectstatic_js_reverse -python manage.py collectstatic --noinput + mkdir -p /opt/recipes/staticfiles + rm -rf /opt/recipes/staticfiles/* + mv /opt/recipes/staticfiles-collect/* /opt/recipes/staticfiles + rm -rf /opt/recipes/staticfiles-collect +else + echo "Collecting static files, this may take a while..." -echo "Done" + python manage.py collectstatic_js_reverse + python manage.py collectstatic --noinput + + echo "Done" +fi chmod -R 755 /opt/recipes/mediafiles From 42b7d1afcb880e65338370ffce9737302456e08e Mon Sep 17 00:00:00 2001 From: tooboredtocode Date: Mon, 8 Apr 2024 23:58:10 +0200 Subject: [PATCH 2/2] fix: image not working in docker compose environments --- boot.sh | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/boot.sh b/boot.sh index ab5d7fddd..c14d66aab 100644 --- a/boot.sh +++ b/boot.sh @@ -68,12 +68,16 @@ echo "Migrating database" python manage.py migrate if [[ "${DOCKER}" == "true" ]]; then - echo "Copying cached static files from docker build" + if [[ -d "/opt/recipes/staticfiles-collect" ]]; then + echo "Copying cached static files from docker build" - mkdir -p /opt/recipes/staticfiles - rm -rf /opt/recipes/staticfiles/* - mv /opt/recipes/staticfiles-collect/* /opt/recipes/staticfiles - rm -rf /opt/recipes/staticfiles-collect + mkdir -p /opt/recipes/staticfiles + rm -rf /opt/recipes/staticfiles/* + mv /opt/recipes/staticfiles-collect/* /opt/recipes/staticfiles + rm -rf /opt/recipes/staticfiles-collect + else + echo "Static files are already up to date" + fi else echo "Collecting static files, this may take a while..."