-
Notifications
You must be signed in to change notification settings - Fork 3
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
Heroku-24: Remove Python from the run image #276
Conversation
1ebb4ba
to
e0ca5a8
Compare
52b41fd
to
7139860
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@edmorley this seems fine but, out of curiosity, why was python added to the run image in the first place?
Looking at the Git log, the following early commits (and changed patch lines) reference Python:
(This makes use of an alias I have in my bash profile: It appears 10 years ago the Cedar-10 images (which only existed in a single image; there weren't build vs run images then) used to install Python, Ruby, Erlang etc from source: This was then switched to using Python from APT in: And then when Heroku-16 was created (which was the first stack version to have split build and run images), this was copy-pasted into the run image (rather than the build image) without any explanation: ( So Python's inclusion seems more like a leftover from the pre build vs run image days (and a time where image size was less of a concern in general), rather than needing it for a specific purpose in the run image. |
e0ca5a8
to
e376a4b
Compare
7139860
to
aff47f8
Compare
Since: - Python apps will (or should be) be using Python provided by the Python buildpack instead. - Non-Python buildpacks/apps typically don't need Python at runtime. - Having Python in the run image has caused confusion in support tickets where the Python buildpack wasn't present (such as it being accidentally replaced when adding second buildpack), since at runtime apps then fail with a less obvious `ModuleNotFound` error instead of `python: command not found`. - None of our other officially supported languages (that have their own buildpacks) are also installed as system packages in the base image. - Removing Python reduces the run image size by 34 MB, and in a CNB world image size is a much bigger concern, so we need to be more selective about what packages we include. - Once Heroku-24 GAs we can't remove packages (since it will break backwards compatibility given stack rebasing), however, we can add packages - so we should err on the side of trying out removing packages now. Python is still in the build image since various non-Python use-cases need it (for example Node.js packages that use node-gyp require Python at install time), plus several other system packages in the build image depend on it anyway. I've intentionally removed the `python-is-python3` package entirely (rather than still including it in the build image), since the vast majority of tooling will (or should be) checking for the presence of `python3` directly (given that's the default name on Ubuntu unless the backward compat package is installed). And for most end-user/app use-cases we would prefer they use the Python buildpack (rather than system Python), so a `python: command not found` will nudge them in that direction. We can always add `python-is-python3` back later if this turns out to be a bigger issue than expected. Note: The classic PHP buildpack does use Python in its `heroku-php-apache2` and `heroku-php-nginx` scripts, however, it's only used when `realpath` doesn't exist (eg macOS), so is unused on Heroku. The buildpack will need to adjust for the `python-is-python3` removal, but arguably should have done that previously (given during the Python 2 -> 3 transition the major version of `python` changed). (If it needs to support environments where only the command `python` exists, and not `python3`, then it can use something like: `PYTHON=$(which python3 || which python)`) Before (once the other PRs are merged): ``` -----> Size breakdown... heroku/heroku:24 424MB heroku/heroku:24-build 1.11GB ``` After: ``` -----> Size breakdown... heroku/heroku:24 390MB (34 MB reduction) heroku/heroku:24-build 1.11GB (unchanged) ``` Towards #266. GUS-W-15159536.
aff47f8
to
e033b35
Compare
(This is stacked on top of #275.)
Since:
venv
(virtual environment) +ensurepip
modules don't work.ModuleNotFoundError
orImportError
error instead ofpython: command not found
.lsb_release
). However, as of Ubuntu 24.04lsb_release
no longer depends upon Python, so we're finally able to remove system Python if we wish.For more details, see:
https://salesforce.quip.com/aNvHAENM0GdT
Python is still in the build image since various non-Python use-cases need it (for example Node.js packages that use node-gyp require Python at install time), plus several other system packages in the build image depend on
python3
anyway (so it's going to be installed regardless).I've intentionally removed the
python-is-python3
package entirely (rather than still including it in the build image), since the vast majority of tooling will (or should be) checking for the presence ofpython3
directly (given that's the default name on Ubuntu unless the backward compat package is installed; node-gyp does for example). And for most end-user/app use-cases we would prefer they use the Python buildpack (rather than system Python), so apython: command not found
will nudge them in that direction. We can always addpython-is-python3
back later if this turns out to be a bigger issue than expected.Before (once the other PRs are merged):
After:
Note: The classic PHP buildpack does use Python in its
heroku-php-apache2
andheroku-php-nginx
scripts, however, it's only used whenrealpath
doesn't exist (eg macOS), so is unused on Heroku. The buildpack will need to adjust for thepython-is-python3
removal, but arguably should have done that previously (given during the Python 2 -> 3 transition the major version ofpython
changed). (If it needs to support environments where only the commandpython
exists, and notpython3
, then it can use something like:PYTHON=$(which python3 || which python)
)There is also Direwolf test or two that will need updating, but (a) migrating those will be fairly easy (add the Python buildpack or switch to another alternative), (b) we shouldn't be bloating the run image for internal testing use-cases.
Towards #266.
GUS-W-15159536.