diff --git a/src/ansible_builder/containerfile.py b/src/ansible_builder/containerfile.py index 426f40ae..fc0ee2ac 100644 --- a/src/ansible_builder/containerfile.py +++ b/src/ansible_builder/containerfile.py @@ -106,6 +106,7 @@ def prepare(self) -> None: "", "# Galaxy build stage", "FROM base as galaxy", + "ENV PIP_BREAK_SYSTEM_PACKAGES=1", ]) self._insert_global_args() @@ -135,6 +136,7 @@ def prepare(self) -> None: "", "# Builder build stage", f"FROM {image} as builder", + "ENV PIP_BREAK_SYSTEM_PACKAGES=1", "WORKDIR /build", ]) @@ -156,6 +158,7 @@ def prepare(self) -> None: "", "# Final build stage", "FROM base as final", + "ENV PIP_BREAK_SYSTEM_PACKAGES=1", ]) self._insert_global_args() diff --git a/test/unit/test_containerfile.py b/test/unit/test_containerfile.py index b78be4a2..2ea1e8a5 100644 --- a/test/unit/test_containerfile.py +++ b/test/unit/test_containerfile.py @@ -207,3 +207,50 @@ def test__handle_additional_build_files(build_dir_and_ee_yml): config_dir = tmpdir / '_build' / 'configs' assert config_dir.exists() assert (config_dir / 'ansible.cfg').exists() + + +def test_pep668_env_var_v1(build_dir_and_ee_yml): + """ + Test that we add the pip env var to handle PEP668. + """ + ee_data = """ + version: 1 + """ + tmpdir, ee_path = build_dir_and_ee_yml(ee_data) + c = make_containerfile(tmpdir, ee_path, run_validate=True) + c.prepare() + assert "ENV PIP_BREAK_SYSTEM_PACKAGES=1" in c.steps + + +def test_pep668_env_var_v2(build_dir_and_ee_yml): + """ + Test that we add the pip env var to handle PEP668. + """ + ee_data = """ + version: 2 + images: + base_image: + name: quay.io/user/mycustombaseimage:latest + builder_image: + name: quay.io/user/mycustombuilderimage:latest + """ + tmpdir, ee_path = build_dir_and_ee_yml(ee_data) + c = make_containerfile(tmpdir, ee_path, run_validate=True) + c.prepare() + assert "ENV PIP_BREAK_SYSTEM_PACKAGES=1" in c.steps + + +def test_pep668_env_var_v3(build_dir_and_ee_yml): + """ + Test that we add the pip env var to handle PEP668. + """ + ee_data = """ + version: 3 + images: + base_image: + name: quay.io/user/mycustombaseimage:latest + """ + tmpdir, ee_path = build_dir_and_ee_yml(ee_data) + c = make_containerfile(tmpdir, ee_path, run_validate=True) + c.prepare() + assert "ENV PIP_BREAK_SYSTEM_PACKAGES=1" in c.steps