1
0
Fork 0
mirror of https://github.com/containers/ansible-podman-collections.git synced 2026-02-04 07:11:49 +00:00

Add autodiscovery for build context in podman_image (#757)

Signed-off-by: Sagi Shnaidman <sshnaidm@redhat.com>
This commit is contained in:
Sergey 2024-05-26 00:02:20 +03:00 committed by GitHub
parent e29e2cfb19
commit b3dc57c1cf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 33 additions and 5 deletions

View file

@ -443,6 +443,7 @@ RETURN = r"""
"""
import json
import os
import re
import shlex
@ -529,9 +530,15 @@ class PodmanImageManager(object):
digest_before = None
if not image or self.force:
if self.path:
if self.state == 'build' or self.path:
# Build the image
self.results['actions'].append('Built image {image_name} from {path}'.format(image_name=self.image_name, path=self.path))
build_file = self.build.get('file') if self.build else None
if not self.path and build_file:
self.path = os.path.dirname(build_file)
elif not self.path and not build_file:
self.module.fail_json(msg='Path to build context or file is required when building an image')
self.results['actions'].append('Built image {image_name} from {path}'.format(
image_name=self.image_name, path=self.path))
if not self.module.check_mode:
self.results['image'], self.results['stdout'] = self.build_image()
image = self.results['image']

View file

@ -209,15 +209,34 @@
register: oci_build3
ignore_errors: true
- name: Build OCI image, point to location of Containerfile
- name: Build OCI image, point to location of Containerfile without path
containers.podman.podman_image:
executable: "{{ test_executable | default('podman') }}"
name: testimage2
path: /var/tmp/build/subdir
state: build
build:
file: /var/tmp/build/Dockerfile
register: oci_build4
- name: Build OCI image, point to location of Containerfile and path
containers.podman.podman_image:
executable: "{{ test_executable | default('podman') }}"
name: testimage3
path: /var/tmp/build
build:
file: /var/tmp/build/Dockerfile
register: oci_build5
- name: Build OCI image, point to location of Containerfile and path
containers.podman.podman_image:
executable: "{{ test_executable | default('podman') }}"
name: testimage5x
state: build
build:
format: oci
register: oci_build6
ignore_errors: true
- name: Inspect first image
containers.podman.podman_image_info:
executable: "{{ test_executable | default('podman') }}"
@ -237,7 +256,9 @@
- oci_build2 is not changed
- oci_build3 is not changed
- oci_build3 is failed
- oci_build4 is changed
- oci_build4 is success
- oci_build5 is success
- oci_build6 is failed
- "'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"