Skip to content

Commit

Permalink
Fix issue 646 bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Shrews committed Feb 1, 2024
1 parent b7a978a commit fe2b956
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 8 deletions.
1 change: 1 addition & 0 deletions docs/definition.rst
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ builder runtime functionality. Valid keys for this section are:
the base image. Pip is necessary for Python requirement installation, among
other things. You may choose to disable this step and handle installing
pip manually if the current method of pip installation does not work for you.
The default is ``False``.

``relax_passwd_permissions``
This boolean value controls whether the ``root`` group (GID 0) is explicitly granted
Expand Down
6 changes: 4 additions & 2 deletions src/ansible_builder/containerfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def prepare(self) -> None:
# Second stage (aka, builder): assemble (pip installs, bindep run)
######################################################################

if self.definition.builder_image:
if self.definition.builder_image or self.definition.version == 1:
# Note: A builder image can be specified only in V1 or V2 schema.
image = "$EE_BUILDER_IMAGE"
else:
Expand All @@ -147,7 +147,9 @@ def prepare(self) -> None:
if image == "base":
self.steps.append("RUN $PYCMD -m pip install --no-cache-dir bindep pyyaml requirements-parser")
else:
# For < v3 with a custom builder image, we always make sure pip is available.
# For an EE schema earlier than v3 with a custom builder image, we always make sure pip is available.
context_dir = Path(self.build_outputs_dir).stem
self.steps.append(f'COPY {context_dir}/scripts/pip_install /output/scripts/pip_install')
self.steps.append("RUN /output/scripts/pip_install $PYCMD")

self._insert_custom_steps('prepend_builder')
Expand Down
49 changes: 43 additions & 6 deletions test/unit/test_containerfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,9 @@ def test__handle_additional_build_files(build_dir_and_ee_yml):
assert (config_dir / 'ansible.cfg').exists()


def test_pep668_env_var_v1(build_dir_and_ee_yml):
def test_pep668_v1(build_dir_and_ee_yml):
"""
Test that we add the pip env var to handle PEP668.
Test PEP668 handling with v1 format.
"""
ee_data = """
version: 1
Expand All @@ -220,11 +220,12 @@ def test_pep668_env_var_v1(build_dir_and_ee_yml):
c = make_containerfile(tmpdir, ee_path, run_validate=True)
c.prepare()
assert "ENV PIP_BREAK_SYSTEM_PACKAGES=1" in c.steps
assert "RUN /output/scripts/pip_install $PYCMD" in c.steps


def test_pep668_env_var_v2(build_dir_and_ee_yml):
def test_pep668_v2(build_dir_and_ee_yml):
"""
Test that we add the pip env var to handle PEP668.
Test PEP668 handling with v2 format.
"""
ee_data = """
version: 2
Expand All @@ -238,11 +239,12 @@ def test_pep668_env_var_v2(build_dir_and_ee_yml):
c = make_containerfile(tmpdir, ee_path, run_validate=True)
c.prepare()
assert "ENV PIP_BREAK_SYSTEM_PACKAGES=1" in c.steps
assert "RUN /output/scripts/pip_install $PYCMD" in c.steps


def test_pep668_env_var_v3(build_dir_and_ee_yml):
def test_pep668_v3(build_dir_and_ee_yml):
"""
Test that we add the pip env var to handle PEP668.
Test PEP668 handling with v3 format.
"""
ee_data = """
version: 3
Expand All @@ -254,3 +256,38 @@ def test_pep668_env_var_v3(build_dir_and_ee_yml):
c = make_containerfile(tmpdir, ee_path, run_validate=True)
c.prepare()
assert "ENV PIP_BREAK_SYSTEM_PACKAGES=1" in c.steps
assert "RUN /output/scripts/pip_install $PYCMD" in c.steps


def test_pep668_v3_skip_pip_install(build_dir_and_ee_yml):
"""
Test PEP668 handling with v3 format and skipping pip installation.
"""
ee_data = """
version: 3
images:
base_image:
name: quay.io/user/mycustombaseimage:latest
options:
skip_pip_install: True
"""
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
assert "RUN /output/scripts/pip_install $PYCMD" not in c.steps


def test_v1_builder_image(build_dir_and_ee_yml):
"""
Test for issue 646 (https://github.com/ansible/ansible-builder/issues/646).
"""
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 "FROM $EE_BUILDER_IMAGE as builder" in c.steps
assert "COPY _build/scripts/pip_install /output/scripts/pip_install" in c.steps
assert "RUN /output/scripts/pip_install $PYCMD" in c.steps

0 comments on commit fe2b956

Please sign in to comment.