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

Warn or error if a virtual environment was included in the app source #271

Open
edmorley opened this issue Sep 11, 2024 · 0 comments
Open
Labels
enhancement New feature or request

Comments

@edmorley
Copy link
Member

edmorley commented Sep 11, 2024

When using Python virtual environments, it's common to store the virtual environment (aka venv / virtualenv) inside the project directory, inside a directory named .venv/ or venv/. (At least when creating them manually, or using 'uv' which prefers storing them inside the project. Poetry/Pipenv prefer a global venv location outside of the project.)

This directory should always be added to the .gitignore, but sometimes users forget, meaning it is committed to the Git repo, and will be included in the app source when using a Git based deployment mechanism (such as git push heroku main).

In addition, even if users add the .venv/ to their .gitignore, it will still be included in the app source when building locally using pack build, unless they know to also exclude the directory via the project.toml exclude field:
https://github.com/buildpacks/spec/blob/main/extensions/project-descriptor.md#iobuildpacksinclude-optional-and-iobuildpacksexclude-optional

(Even if they have added the .venv to their .dockerignore that won't help, since Pack CLI doesn't use that file - at least not yet; perhaps we should suggest this upstream?)

We should warn or even error if a .venv/ or venv/ directory is present during the build, since:

  • virtual environments are always machine-specific (os/arch specific, plus typically path specific and not relocatable) so a local venv won't work in the app image anyway
  • the buildpack installs deps into its own venv in a layer, so even if the local venv did work, it would be redundant anyway
  • including a local venv bloats the final app image size (and git repo, if committed)
  • having two venvs in the image will cause confusion when users are debugging, since they might think the one inside the app source directory is what is being used (when it won't be)

GUS-W-12421020.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant