Skip to content

Commit

Permalink
podman_image: add file parameter for Containerfile location (#492)
Browse files Browse the repository at this point in the history
* `podman_image`: correct `path` parameter description

The `path` parameter is the last parameter when running `podman build
...`. As specified in the manpage, it is defined as the build context,
and not necessarily should it contain the Containerfile.

Signed-off-by: Yuriy Gabuev <[email protected]>

* `podman_image`: add `file` parameter for Containerfile location

Add the `file` parameter to `podman_image` module which mirrors the
`--file` command line argument for `podman build ...`. This parameter
specifies the location of the Containerfile to use in case it should be
different from the one contained in the build context directory.

Signed-off-by: Yuriy Gabuev <[email protected]>

* `podman_image`: add integration tests for `file` parameter

Add tests to ensure that:
- building from a directory without a Containerfile (or Dockerfile)
  fails
- specifying the location of Containerfile with `file` parameter works

Signed-off-by: Yuriy Gabuev <[email protected]>

Signed-off-by: Yuriy Gabuev <[email protected]>
  • Loading branch information
ygabuev authored Oct 25, 2022
1 parent 9531d15 commit dbdac4a
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 6 deletions.
11 changes: 10 additions & 1 deletion plugins/modules/podman_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
default: False
type: bool
path:
description: Path to directory containing the build file.
description: Path to the build context directory.
type: str
force:
description:
Expand Down Expand Up @@ -88,6 +88,10 @@
- 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.
Expand Down Expand Up @@ -606,6 +610,10 @@ def build_image(self):
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:
Expand Down Expand Up @@ -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'],
Expand Down
39 changes: 34 additions & 5 deletions tests/integration/targets/podman_image/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -247,4 +275,5 @@
- quay.io/coreos/alpine-sh
- quay.io/coreos/etcd:v3.3.11
- localhost/testimage
- localhost/testimage2
- localhost/dockerimage

0 comments on commit dbdac4a

Please sign in to comment.