🛡️ Warracker is an open source, self-hostable warranty tracker to monitor expirations, store receipts, files. You own the data, your rules!
Docker: smaller image, venv-only Python layer, pip supervisor
Omega (QA)91ed0d31f4ae
diff --git a/.dockerignore b/.dockerignoreindex 274ea4d..afc9a16 100644--- a/.dockerignore+++ b/.dockerignore@@ -11,3 +11,9 @@ scripts/*.pyc__pycache__/.env++# Ignore CI and test files (never copied into the image, keep the build+# context small)+.github/+tests/+.pytest_cache/diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 371a930..ffd488c 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -2,6 +2,8 @@## 1.0.5 - Unreleased+- **Smaller Docker image:** the Python dependencies now install into a virtualenv in the builder, and the runtime copies only that venv instead of the builder's whole /usr/local, so the image no longer carries a duplicate Python interpreter and standard library. Supervisor is the pip package (4.3.0) rather than the Debian package, which also removes the system Python that package pulled in. The entrypoint waits for the database with a short Python probe instead of pg_isready, so postgresql-client is gone, and the copied packages are stripped of bytecode caches, bundled test suites, and pip itself. Behaviour is unchanged: same base image, same startup flow, same supervisor-managed nginx, gunicorn, and cron. Setuptools is no longer a direct requirement (it was build tooling), and pip builds now use a BuildKit cache mount, so rebuilds on a maintainer's machine reuse previously downloaded packages.+ - _Files: `Dockerfile`, `Docker/entrypoint.sh`, `Docker/supervisord.conf`, `docker-compose.yml`, `backend/requirements.txt`, `.dockerignore`_- **Security dependency updates:** Authlib 1.9.1 to 1.9.2, which carries the upstream security fix GHSA-f3fg-34g9-v7jx (ID-JAG access tokens are now limited to the scopes granted in the ID-JAG claim). The Python 3.15 slim base image digest was refreshed in both Dockerfile stages, and actions/checkout in the test workflow moves to v7, which by default blocks checking out fork pull requests under pull_request_target and workflow_run triggers.- _Files: `backend/requirements.txt`, `Dockerfile`, `.github/workflows/tests.yml`_- **Product photo by URL (#207):** the add and edit forms now accept a photo URL next to the upload and camera options. The server downloads the image once, checks that it really is an image (PNG, JPG, WebP or GIF), and stores it like an uploaded photo, so cards and thumbnails work exactly as with an upload. Fetches are guarded: public http(s) addresses only, a size cap, a timeout, and a redirect limit. An uploaded file still wins when both are given.diff --git a/Docker/entrypoint.sh b/Docker/entrypoint.shindex c689505..ad4e265 100644--- a/Docker/entrypoint.sh+++ b/Docker/entrypoint.sh@@ -8,10 +8,18 @@ log() {echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1"}-# Database connection check (with retry)+# Database connection check (with retry). A plain TCP probe from Python+# replaces pg_isready, so the image no longer needs postgresql-client.log "Waiting for database connection..."for i in {1..30}; do- if pg_isready -h "${DB_HOST:-localhost}" -p "${DB_PORT:-5432}" -U "${DB_USER:-postgres}" > /dev/null 2>&1; then+ if python -c "+import os, socket, sys+try:+ with socket.create_connection((os.environ.get('DB_HOST', 'localhost'), int(os.environ.get('DB_PORT', '5432'))), timeout=2):+ sys.exit(0)+except OSError:+ sys.exit(1)+" > /dev/null 2>&1; thenlog "Database is ready!"breakfidiff --git a/Docker/supervisord.conf b/Docker/supervisord.confindex 24f3961..e314d13 100644--- a/Docker/supervisord.conf+++ b/Docker/supervisord.conf@@ -20,7 +20,7 @@ stderr_logfile=/dev/stderrstderr_logfile_maxbytes=0[program:gunicorn]-command=/usr/local/bin/gunicorn --config /app/gunicorn_config.py 'backend:create_app()'+command=/opt/venv/bin/gunicorn --config /app/gunicorn_config.py 'backend:create_app()'directory=/appuser=warrackerautostart=truediff --git a/Dockerfile b/Dockerfileindex 4b4de04..97e72e9 100644--- a/Dockerfile+++ b/Dockerfile@@ -13,12 +13,24 @@ RUN apt-get update && \apt-get clean && \rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*-# Upgrade pip-RUN pip install --no-cache-dir --upgrade pip+# Install Python dependencies into a virtualenv. The runtime stage copies+# only the venv, so the image does not carry a second copy of the Python+# interpreter and standard library from the builder's /usr/local.+RUN python -m venv /opt/venv+ENV PATH="/opt/venv/bin:$PATH"-# Install Python dependencies (system-wide installation)COPY backend/requirements.txt /tmp/requirements.txt-RUN pip install --no-cache-dir -r /tmp/requirements.txt+RUN --mount=type=cache,target=/root/.cache/pip \+ pip install --upgrade pip && \+ pip install --no-compile -r /tmp/requirements.txt++# Strip what the runtime never uses: bytecode caches (the app runs with+# PYTHONDONTWRITEBYTECODE=1), the packages' own test suites, and pip itself.+RUN find /opt/venv -type d -name "__pycache__" -prune -exec rm -rf {} + && \+ find /opt/venv -type d \( -name "tests" -o -name "test" \) -prune -exec rm -rf {} + && \+ rm -rf /opt/venv/lib/python*/site-packages/pip \+ /opt/venv/lib/python*/site-packages/pip-*.dist-info \+ /opt/venv/bin/pip*FROM python:3.15-slim-trixie@sha256:94d3426f1def7db4a106a232ac121bfd975393e5dfd40a619b955fae45fe7913 AS runtime@@ -38,10 +50,8 @@ RUN groupadd -r -g 999 warracker && \RUN apt-get update && \apt-get install -y --no-install-recommends \nginx \- supervisor \logrotate \cron \- postgresql-client \gettext-base \curl \ca-certificates \@@ -51,8 +61,11 @@ RUN apt-get update && \apt-get clean && \rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*-# Copy Python dependencies from builder (copy entire /usr/local for version-agnostic)-COPY --from=builder /usr/local /usr/local+# Copy the Python virtualenv from the builder (supervisord, gunicorn and+# pybabel all run from it; supervisor is now the pip package, so the runtime+# no longer needs Debian's supervisor package and its system Python)+COPY --from=builder /opt/venv /opt/venv+ENV PATH="/opt/venv/bin:$PATH"# Configure directories with proper permissionsRUN mkdir -p /app /var/www/html /var/log/supervisor /run/nginx && \@@ -113,4 +126,4 @@ EXPOSE 80# ENTRYPOINT runs setup tasks then executes supervisor# Supervisor needs to run as root to manage services with different usersENTRYPOINT ["/app/entrypoint.sh"]-CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]+CMD ["/opt/venv/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]diff --git a/backend/requirements.txt b/backend/requirements.txtindex 267248a..dc5ab33 100644--- a/backend/requirements.txt+++ b/backend/requirements.txt@@ -13,7 +13,7 @@ Authlib==1.9.2requests==2.34.2gevent==26.9.0psycogreen==1.0.2-setuptools==84.2.1+supervisor==4.3.0apprise==1.13.1Flask-Babel==4.0.0Babel==2.18.0diff --git a/docker-compose.yml b/docker-compose.ymlindex 18aee47..e6ff51f 100644--- a/docker-compose.yml+++ b/docker-compose.yml@@ -49,7 +49,7 @@ services:restart: unless-stoppedcommand: >bash -c "- exec /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf+ exec /opt/venv/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf"warrackerdb: