diff --git a/plugins/modules/podman_image.py b/plugins/modules/podman_image.py index 79024bf..3f72743 100644 --- a/plugins/modules/podman_image.py +++ b/plugins/modules/podman_image.py @@ -43,7 +43,7 @@ DOCUMENTATION = r''' default: False type: bool path: - description: Path to directory containing the build file. + description: Path to the build context directory. type: str force: description: @@ -88,6 +88,10 @@ DOCUMENTATION = r''' - build_args - buildargs suboptions: + file: + description: + - Path to the Containerfile if it is not in the build context directory. + type: path volume: description: - Specify multiple volume / mount options to mount one or more mounts to a container. @@ -606,6 +610,10 @@ class PodmanImageManager(object): if self.build.get('rm'): args.append('--rm') + containerfile = self.build.get('file') + if containerfile: + args.extend(['--file', containerfile]) + volume = self.build.get('volume') if volume: for v in volume: @@ -767,6 +775,7 @@ def main(): options=dict( annotation=dict(type='dict'), force_rm=dict(type='bool', default=False), + file=dict(type='path'), format=dict( type='str', choices=['oci', 'docker'], diff --git a/tests/integration/targets/podman_image/tasks/main.yml b/tests/integration/targets/podman_image/tasks/main.yml index 867a25a..4726b2f 100644 --- a/tests/integration/targets/podman_image/tasks/main.yml +++ b/tests/integration/targets/podman_image/tasks/main.yml @@ -152,9 +152,9 @@ - specific_image2 is not changed - "'v3.3.11' in images.stdout" - - name: Create a build dir + - name: Create a build directory with a subdirectory file: - path: /var/tmp/build + path: /var/tmp/build/subdir state: directory - name: Copy Containerfile @@ -176,18 +176,46 @@ path: /var/tmp/build register: oci_build2 - - name: Inspect build image + - name: Build OCI image from a directory without Containerfile (should fail) + containers.podman.podman_image: + executable: "{{ test_executable | default('podman') }}" + name: testimage2 + path: /var/tmp/build/subdir + register: oci_build3 + ignore_errors: true + + - name: Build OCI image, point to location of Containerfile + containers.podman.podman_image: + executable: "{{ test_executable | default('podman') }}" + name: testimage2 + path: /var/tmp/build/subdir + build: + file: /var/tmp/build/Dockerfile + register: oci_build4 + + - name: Inspect first image containers.podman.podman_image_info: executable: "{{ test_executable | default('podman') }}" name: testimage register: testimage_info - - name: Ensure OCI image was built properly + - name: Inspect second image + containers.podman.podman_image_info: + executable: "{{ test_executable | default('podman') }}" + name: testimage2 + register: testimage2_info + + - name: Ensure OCI images were built properly assert: that: - oci_build1 is changed - oci_build2 is not changed + - oci_build3 is not changed + - oci_build3 is failed + - oci_build4 is changed - "'localhost/testimage:latest' in testimage_info.images[0]['RepoTags'][0]" + - "'localhost/testimage2:latest' in testimage2_info.images[0]['RepoTags'][0]" + - "'no such file or directory' in oci_build3.msg" - name: Build Docker image containers.podman.podman_image: @@ -207,7 +235,7 @@ format: docker register: docker_build2 - - name: Inspect build image + - name: Inspect built image containers.podman.podman_image_info: executable: "{{ test_executable | default('podman') }}" name: dockerimage @@ -247,4 +275,5 @@ - quay.io/coreos/alpine-sh - quay.io/coreos/etcd:v3.3.11 - localhost/testimage + - localhost/testimage2 - localhost/dockerimage