1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-11-11 12:46:49 +00:00

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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kk4h2TcUiaWmU5MUszYSea
This commit is contained in:
catborise 2026-11-08 15:57:33 +03:00
parent 1764240cff
commit b03828c684

View file

@ -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 && \