refactor(docker): slim multi-stage build, drop image size by ~58%#233
Open
matrixise wants to merge 1 commit into
Open
refactor(docker): slim multi-stage build, drop image size by ~58%#233matrixise wants to merge 1 commit into
matrixise wants to merge 1 commit into
Conversation
Rework the Dockerfile into a real two-stage build: - builder stage: python:3.13-slim + build toolchain, installs all requirements into an isolated venv at /opt/venv - dev stage: python:3.13-slim with only runtime packages (postgresql-client) and the interactive tooling the dev shell needs (fish, neovim, less, ack, iputils-ping), copying the venv from the builder The build toolchain (build-essential, gcc) no longer ships in the final image, cutting it from ~1.69GB to ~715MB. Other fixes: - drop the stray `aws` package from the install line (junk PyPI package; boto3 already provides the AWS SDK) - stop reinstalling ruff via pip -U (it is already pinned in dev.txt) - switch ADD to COPY for the requirements files - add apt cache mounts for /var/lib/apt/lists with sharing=locked - add a .dockerignore to shrink the build context and keep .env/secrets out Add a .dockerignore covering VCS, Python caches, local databases, env files and tooling output.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Reworks the
Dockerfileinto a real two-stage build and trims the image from ~1.69 GB to ~715 MB (-58%).Changes
builderstage (python:3.13-slim+ build toolchain) installs every requirement into an isolated venv at/opt/venv; the finaldevstage (python:3.13-slim) copies only that venv plus runtime/interactive tooling.build-essential/gccno longer ship in the final image.python:3.13→python:3.13-slim.awspackage from the install line. It is an abandoned junk PyPI package, not the AWS CLI;boto3already provides the AWS SDK.ruffviapip -U— it is already pinned indev.txt.ADD→COPYfor the requirements files./var/lib/apt/listswithsharing=locked..dockerignoreto shrink the build context and keep.env/secrets out of it.The final
devstage stays the last stage, sodocker build -t python.ie/website-dev .(used bytask docker:build, no--target) keeps producing the image consumed by both thewebandtestcompose services.Validation
docker buildsucceeds.python pythonie/manage.py check --settings=pythonie.settings.testsreports 0 issues with the source mounted.Image size: 1.69 GB → 715 MB.