heroku / buildpacks-python

Heroku's Cloud Native Buildpack for Python applications.
BSD 3-Clause "New" or "Revised" License
27 stars 3 forks source link

Stop including pip in the final app image #264

Closed edmorley closed 1 month ago

edmorley commented 1 month ago

After #254, pip is now installed into its own layer rather than into the system site-packages directory inside the Python layer.

This means its now possible to exclude pip from the final app image, by making the pip layer be a build-only layer.

Excluding pip from the final app image:

Users that need pip at run-time for a temporary debugging task can run python -m ensurepip --default-pip in the container at run-time to make it available again (this command doesn't even have to download anything - it uses the pip bundled with Python).

Or if pip is an actual run-time dependency of the app, then the app can add pip to its requirements.txt (which much more clearly conveys the requirements of the app, and also allows the app to pick what pip version it needs at run-time - something that isn't possible with the pip installed by the buildpack).

Should we find that pip's absence causes confusion in the future, we could always add a wrapper/shim pip script in the app image which does something like echo "pip isn't installed at run-time, if you need it temporarily run 'python -m ensurepip --default-pip' to install it" && exit 1 to improve discoverability. We'll also document pip (and Poetry) being available at build-time only in the docs that will be added by #11.

Closes #255. GUS-W-16697386.