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

Resolve Ansible Builder Errors for Podman on Windows #717

Open
wants to merge 3 commits into
base: devel
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions src/ansible_builder/containerfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def prepare(self) -> None:
else:
# 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(f'COPY --chmod=755 {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 Expand Up @@ -313,11 +313,11 @@ def _create_folder_copy_files(self) -> None:
# Later intermediate stages depend on base image containing these scripts.
# Copy them to a location that we do not need in the final image.
context_dir = Path(self.build_outputs_dir).stem
self.steps.append(f'COPY {context_dir}/scripts/ /output/scripts/')
self.steps.append(f'COPY --chmod=755 {context_dir}/scripts/ /output/scripts/')

# The final image will have /output purged, but certain scripts we want
# to retain in that image.
self.steps.append(f'COPY {context_dir}/scripts/entrypoint {constants.FINAL_IMAGE_BIN_PATH}/entrypoint')
self.steps.append(f'COPY --chmod=755 {context_dir}/scripts/entrypoint {constants.FINAL_IMAGE_BIN_PATH}/entrypoint')

def _handle_additional_build_files(self) -> None:
"""
Expand Down
3 changes: 2 additions & 1 deletion src/ansible_builder/ee_schema.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import posixpath

from jsonschema import validate, SchemaError, ValidationError

Expand Down Expand Up @@ -472,7 +473,7 @@ def _handle_options_defaults(ee_def: dict):
"""
options = ee_def.setdefault('options', {})

entrypoint_path = os.path.join(constants.FINAL_IMAGE_BIN_PATH, "entrypoint")
entrypoint_path = posixpath.join(constants.FINAL_IMAGE_BIN_PATH, "entrypoint")

options.setdefault('skip_ansible_check', False)
options.setdefault('skip_pip_install', False)
Expand Down
27 changes: 24 additions & 3 deletions test/unit/test_containerfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,26 @@ def test_v3_various(build_dir_and_ee_yml):
assert 'CMD ["csh"]' in c.steps


def test__posix_separator_in_entrypoint_on_windows(build_dir_and_ee_yml, mocker):
"""
Test that the generated entrypoint uses the POSIX separator on Windows.
"""
ee_data = """
version: 3
images:
base_image:
name: quay.io/user/mycustombaseimage:latest
"""
import ntpath
mocker.patch("os.path", ntpath)

tmpdir, ee_path = build_dir_and_ee_yml(ee_data)
c = make_containerfile(tmpdir, ee_path, run_validate=True)
c.prepare()

assert 'ENTRYPOINT ["/opt/builder/bin/entrypoint", "dumb-init"]' in c.steps


def test__handle_additional_build_files(build_dir_and_ee_yml):
"""
Test additional build file handling works as expected.
Expand Down Expand Up @@ -296,7 +316,7 @@ def test_v1_builder_image(build_dir_and_ee_yml):
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 "COPY --chmod=755 _build/scripts/pip_install /output/scripts/pip_install" in c.steps
assert "RUN /output/scripts/pip_install $PYCMD" in c.steps


Expand All @@ -315,8 +335,9 @@ def test_v2_builder_image(build_dir_and_ee_yml):
tmpdir, ee_path = build_dir_and_ee_yml(ee_data)
c = make_containerfile(tmpdir, ee_path, run_validate=True)
c.prepare()
print(c.steps)
assert "FROM $EE_BUILDER_IMAGE AS builder" in c.steps
assert "COPY _build/scripts/pip_install /output/scripts/pip_install" in c.steps
assert "COPY --chmod=755 _build/scripts/pip_install /output/scripts/pip_install" in c.steps
assert "RUN /output/scripts/pip_install $PYCMD" in c.steps


Expand All @@ -334,7 +355,7 @@ def test_v2_builder_image_default(build_dir_and_ee_yml):
c = make_containerfile(tmpdir, ee_path, run_validate=True)
c.prepare()
assert "FROM base AS builder" in c.steps
assert "COPY _build/scripts/pip_install /output/scripts/pip_install" not in c.steps
assert "COPY --chmod=755 _build/scripts/pip_install /output/scripts/pip_install" not in c.steps


def test_prepare_introspect_assemble_steps(build_dir_and_ee_yml):
Expand Down
Loading