From b03828c68446de9b447f2deba08e7ff93dd60486 Mon Sep 17 00:00:00 2001 From: catborise Date: Sun, 8 Nov 2026 15:57:33 +0300 Subject: [PATCH] build(docker): the image has one copy of the venv and no pip chown -R www-data on /srv/webvirtcloud after collectstatic copied the venv and the code into a layer of their own. The code now stays root's: the panel writes only to its data and backup directories, which the start script gives it. pip is removed from the runtime venv and its cache is a build cache mount, so a requirement change downloads only what changed. The image goes from 1.17 GB to 805 MB. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Kk4h2TcUiaWmU5MUszYSea --- Dockerfile | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index 300208ba..d8698970 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,10 +18,12 @@ RUN apt-get update -qqy \ WORKDIR /srv/webvirtcloud COPY conf/requirements.txt conf/requirements-ldap.txt conf/ -# hadolint ignore=DL3013,DL3042 -RUN python3 -m venv venv \ - && venv/bin/pip install --no-cache-dir -U pip wheel \ - && venv/bin/pip install --no-cache-dir -r conf/requirements.txt -r conf/requirements-ldap.txt +# pip's cache stays on the build host for the next build; pip itself is not +# shipped: a dependency change is a new image +RUN --mount=type=cache,target=/root/.cache/pip \ + python3 -m venv venv \ + && venv/bin/pip install -r conf/requirements.txt -r conf/requirements-ldap.txt \ + && venv/bin/pip uninstall -y pip FROM phusion/baseimage:resolute-1.0.23 @@ -49,11 +51,13 @@ WORKDIR /srv/webvirtcloud COPY --from=build /srv/webvirtcloud/venv venv COPY . /srv/webvirtcloud -# Run collectstatic with temporary dummy key, then remove temporary settings file +# The code stays root's: the panel writes only to its data and backup +# directories (made its own at start). A settings file and a key exist only +# for collectstatic. RUN cp webvirtcloud/settings.py.template webvirtcloud/settings.py && \ - SECRET_KEY="build-dummy-key-only-for-collectstatic" venv/bin/python3 manage.py collectstatic --noinput && \ - rm -f webvirtcloud/settings.py && \ - chown -R www-data:www-data /srv/webvirtcloud + SECRET_KEY="build-dummy-key-only-for-collectstatic" WEBVIRTCLOUD_LOG_FILE=/tmp/build.log \ + venv/bin/python3 manage.py collectstatic --noinput && \ + rm -f webvirtcloud/settings.py /tmp/build.log # Setup Nginx RUN printf "\n%s" "daemon off;" >> /etc/nginx/nginx.conf && \