Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop including pip in the final app image #264

Merged
merged 1 commit into from
Sep 9, 2024
Merged

Stop including pip in the final app image #264

merged 1 commit into from
Sep 9, 2024

Conversation

edmorley
Copy link
Member

@edmorley edmorley commented Sep 4, 2024

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:

  • Prevents several classes of user error/confusion/bad app design patterns seen in support tickets (see Exclude pip from the app image #255 for more details).
  • Reduces app image supply chain surface area.
  • Reduces app image size by 13 MB and layer count by 1, meaning less to have to push to a remote registry.
  • Matches the approach used for Poetry, where we don't make Poetry available at run-time either.

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.

@edmorley edmorley added enhancement New feature or request semver: major labels Sep 4, 2024
@edmorley edmorley self-assigned this Sep 4, 2024
@edmorley edmorley marked this pull request as ready for review September 4, 2024 11:25
@edmorley edmorley requested a review from a team as a code owner September 4, 2024 11:25
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:
- Prevents several classes of user error/confusion/bad app design
  patterns seen in support tickets (see #255 for more details).
- Reduces app image supply chain surface area.
- Reduces app image size by 13 MB and layer count by 1, meaning less
  to have to push to the remote registry.
- Matches the approach used for Poetry, where we don't make Poetry
  available at run-time either.

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).

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.
@edmorley edmorley enabled auto-merge (squash) September 9, 2024 09:01
@edmorley edmorley merged commit 05aa01e into main Sep 9, 2024
7 checks passed
@edmorley edmorley deleted the pip-build-only branch September 9, 2024 09:03
heroku-linguist bot added a commit that referenced this pull request Sep 17, 2024
## heroku/python

### Added

- The Python version can now be configured using a `.python-version` file. Both the `3.X` and `3.X.Y` version forms are supported. ([#272](#272))

### Changed

- pip is now only available during the build, and is longer included in the final app image. ([#264](#264))
- Improved the error messages shown when an end-of-life or unknown Python version is requested. ([#272](#272))
heroku-linguist bot added a commit to heroku/cnb-builder-images that referenced this pull request Sep 17, 2024
## heroku/python

### Added

- The Python version can now be configured using a `.python-version` file. Both the `3.X` and `3.X.Y` version forms are supported. ([#272](heroku/buildpacks-python#272))

### Changed

- pip is now only available during the build, and is longer included in the final app image. ([#264](heroku/buildpacks-python#264))
- Improved the error messages shown when an end-of-life or unknown Python version is requested. ([#272](heroku/buildpacks-python#272))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request semver: major
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Exclude pip from the app image
2 participants