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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed

- pip is now only available during the build, and is longer included in the final app image. ([#264](https://github.com/heroku/buildpacks-python/pull/264))

## [0.17.1] - 2024-09-07

### Changed
Expand Down
6 changes: 3 additions & 3 deletions src/layers/pip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub(crate) fn install_pip(
layer_name!("pip"),
CachedLayerDefinition {
build: true,
launch: true,
launch: false,
invalid_metadata_action: &|_| InvalidMetadataAction::DeleteLayer,
restored_layer_action: &|cached_metadata: &PipLayerMetadata, _| {
let cached_pip_version = cached_metadata.pip_version.clone();
Expand All @@ -49,15 +49,15 @@ pub(crate) fn install_pip(
// reduce build log spam and prevent users from thinking they need to manually upgrade.
// https://pip.pypa.io/en/stable/cli/pip/#cmdoption-disable-pip-version-check
.chainable_insert(
Scope::All,
Scope::Build,
ModificationBehavior::Override,
"PIP_DISABLE_PIP_VERSION_CHECK",
"1",
)
// Move the Python user base directory to this layer instead of under HOME:
// https://docs.python.org/3/using/cmdline.html#envvar-PYTHONUSERBASE
.chainable_insert(
Scope::All,
Scope::Build,
ModificationBehavior::Override,
"PYTHONUSERBASE",
layer.path(),
Expand Down
18 changes: 5 additions & 13 deletions tests/pip_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use libcnb_test::{assert_contains, assert_empty, BuildpackReference, PackResult,

#[test]
#[ignore = "integration test"]
#[allow(clippy::too_many_lines)]
fn pip_basic_install_and_cache_reuse() {
let mut config = default_build_config("tests/fixtures/pip_basic");
config.buildpacks(vec![
Expand Down Expand Up @@ -69,14 +68,13 @@ fn pip_basic_install_and_cache_reuse() {

// Check that at run-time:
// - The correct env vars are set.
// - pip is available (rather than just during the build).
// - Both pip and Python can find the typing-extensions package.
// - pip isn't available.
// - Python can find the typing-extensions package.
let command_output = context.run_shell_command(
indoc! {"
set -euo pipefail
printenv | sort | grep -vE '^(_|HOME|HOSTNAME|OLDPWD|PWD|SHLVL)='
echo
pip list
! command -v pip > /dev/null || { echo 'pip unexpectedly found!' && exit 1; }
python -c 'import typing_extensions'
"}
);
Expand All @@ -85,18 +83,12 @@ fn pip_basic_install_and_cache_reuse() {
command_output.stdout,
formatdoc! {"
LANG=C.UTF-8
LD_LIBRARY_PATH=/layers/heroku_python/venv/lib:/layers/heroku_python/python/lib:/layers/heroku_python/pip/lib
PATH=/layers/heroku_python/venv/bin:/layers/heroku_python/python/bin:/layers/heroku_python/pip/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
PIP_DISABLE_PIP_VERSION_CHECK=1
LD_LIBRARY_PATH=/layers/heroku_python/venv/lib:/layers/heroku_python/python/lib
PATH=/layers/heroku_python/venv/bin:/layers/heroku_python/python/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
PIP_PYTHON=/layers/heroku_python/venv
PYTHONHOME=/layers/heroku_python/python
PYTHONUNBUFFERED=1
PYTHONUSERBASE=/layers/heroku_python/pip
VIRTUAL_ENV=/layers/heroku_python/venv

Package Version
----------------- -------
typing_extensions 4.12.2
"}
);

Expand Down