Keep secrets and runtime data out of the Docker images
The build context is the repository root and there was no .dockerignore, so
'COPY backend/ ./' swept backend/venv (327 MB), backend/media (the actual
library, 224 MB), backend/logs, backend/staticfiles and backend/.env
(SECRET_KEY plus the database password) into the backend image: 1.43 GB per
architecture, including secrets headed for the registry. The frontend build
stage also copied the host's node_modules over the fresh install.
- Root .dockerignore excludes .git, virtualenvs, __pycache__, db.sqlite3,
logs/staticfiles, .env files, media/, node_modules, dist and the deploy
runtime state (data/, tailscale-state/).
- The backend Dockerfile now asserts the context is clean (.env, venv,
media/library, db.sqlite3 all absent) before collectstatic, so a missing
ignore file fails the build instead of leaking.
- Rebuilt: backend 1.43 GB -> 876 MB ('COPY backend/' is now 268 kB),
frontend stays at 65 MB. Verified by booting the compose stack with the
new image: migrations applied, /health ok, no .env or venv inside, and
/app/media is the mounted (empty) volume; the scheduler runs too.
- Removed the stale local images that still contained the library and the
dev .env.
This commit is contained in:
@@ -30,6 +30,14 @@ COPY backend/ ./
|
||||
COPY deploy/backend-entrypoint.sh /usr/local/bin/j621-entrypoint
|
||||
COPY deploy/scheduler-entrypoint.sh /usr/local/bin/j621-scheduler
|
||||
|
||||
# Guard: fail the build if the context leaked secrets or runtime data
|
||||
# (.dockerignore excludes them — see the repository root).
|
||||
RUN test ! -e /app/.env \
|
||||
&& test ! -d /app/venv \
|
||||
&& test ! -d /app/media/library \
|
||||
&& test ! -e /app/db.sqlite3 \
|
||||
&& echo "build context clean"
|
||||
|
||||
RUN chmod +x /usr/local/bin/j621-entrypoint /usr/local/bin/j621-scheduler \
|
||||
&& mkdir -p /app/media /app/logs \
|
||||
&& python manage.py collectstatic --noinput
|
||||
|
||||
Reference in New Issue
Block a user