diff --git a/plugins/modules/podman_play.py b/plugins/modules/podman_play.py index 04a30441..b88a614b 100644 --- a/plugins/modules/podman_play.py +++ b/plugins/modules/podman_play.py @@ -37,6 +37,11 @@ Note - You can also override the default path of the authentication file by setting the REGISTRY_AUTH_FILE environment variable. export REGISTRY_AUTH_FILE=path type: path + build: + description: + - Build images even if they are found in the local storage. + - It is required to exist subdirectories matching the image names to be build. + type: bool cert_dir: description: - Use certificates at path (*.crt, *.cert, *.key) to connect to the registry. @@ -51,6 +56,11 @@ Kubernetes configmap YAMLs type: list elements: path + context_dir: + description: + - Use path as the build context directory for each image. + Requires build option be true. + type: path seccomp_profile_root: description: - Directory path for seccomp profiles (default is "/var/lib/kubelet/seccomp"). @@ -164,7 +174,9 @@ def __init__(self, module, executable): self.command.extend(['--start=%s' % str(start).lower()]) for arg, param in { '--authfile': 'authfile', + '--build': 'build', '--cert-dir': 'cert_dir', + '--context-dir': 'context_dir', '--log-driver': 'log_driver', '--seccomp-profile-root': 'seccomp_profile_root', '--tls-verify': 'tls_verify', @@ -267,8 +279,10 @@ def main(): executable=dict(type='str', default='podman'), kube_file=dict(type='path', required=True), authfile=dict(type='path'), + build=dict(type='bool'), cert_dir=dict(type='path'), configmap=dict(type='list', elements='path'), + context_dir=dict(type='path'), seccomp_profile_root=dict(type='path'), username=dict(type='str'), password=dict(type='str', no_log=True), diff --git a/tests/integration/targets/podman_play/tasks/files/Containerfile b/tests/integration/targets/podman_play/tasks/files/Containerfile new file mode 100644 index 00000000..2530caed --- /dev/null +++ b/tests/integration/targets/podman_play/tasks/files/Containerfile @@ -0,0 +1,3 @@ +FROM ubi8-init +RUN dnf -y install httpd; dnf -y clean all +RUN systemctl enable httpd.service \ No newline at end of file diff --git a/tests/integration/targets/podman_play/tasks/files/kube-buil-test.yaml b/tests/integration/targets/podman_play/tasks/files/kube-buil-test.yaml new file mode 100644 index 00000000..3ccd0ca8 --- /dev/null +++ b/tests/integration/targets/podman_play/tasks/files/kube-buil-test.yaml @@ -0,0 +1,21 @@ +# Save the output of this file and use kubectl create -f to import +# it into Kubernetes. +# +# Created with podman-4.4.1 +apiVersion: v1 +kind: Pod +metadata: + annotations: + org.opencontainers.image.base.digest/buil-test: sha256:e08f47885d5794a7d8b6404e9db9b0c0a9fc6c633da3c3af0c355299 + org.opencontainers.image.base.name/buil-test: registry.redhat.io/ubi8-init:latest + creationTimestamp: "2023-09-28T01:12:34Z" + labels: + app: buil-test-pod + name: buil-test-pod +spec: + containers: + - image: localhost/build-test:latest + name: buil-test + ports: + - containerPort: 80 + hostPort: 8080 diff --git a/tests/integration/targets/podman_play/tasks/main.yml b/tests/integration/targets/podman_play/tasks/main.yml index 30f53fa5..acac2875 100644 --- a/tests/integration/targets/podman_play/tasks/main.yml +++ b/tests/integration/targets/podman_play/tasks/main.yml @@ -128,3 +128,9 @@ args: apply: become: true + +- name: Test play kube with on-demand image build + include_tasks: play-with-build.yml + vars: + ansible_python_interpreter: "/usr/bin/python" + \ No newline at end of file diff --git a/tests/integration/targets/podman_play/tasks/play-with-build.yml b/tests/integration/targets/podman_play/tasks/play-with-build.yml new file mode 100644 index 00000000..e7601f53 --- /dev/null +++ b/tests/integration/targets/podman_play/tasks/play-with-build.yml @@ -0,0 +1,51 @@ +--- +- name: Test play kube with on-demand image build + vars: + image_name: build-test + build_context_dir: /tmp/contextdir + kube_dir: /tmp + success_msg: "Successfully tagged localhost/{{ image_name }}:latest" + block: + + - name: Make sure that {{ image_name }} image is absent + containers.podman.podman_image: + name: "{{ image_name }}" + state: absent + + - name: Copy files to known place + copy: + src: kube-buil-test.yaml + dest: "{{ kube_dir }}/kube-buil-test.yaml" + remote_src: false + + - name: Create context dir for build + file: + path: "{{ build_context_dir }}/{{ image_name }}" + state: directory + + - name: Copy Containerfile for build + copy: + src: Containerfile + dest: "{{ build_context_dir }}/{{ image_name }}/Containerfile" + remote_src: false + + - name: Play kube file with image build + containers.podman.podman_play: + kube_file: "{{ kube_dir }}/kube-buil-test.yaml" + build: true + context_dir: "{{ build_context_dir }}" + state: started + register: play_with_build + + - name: Check if the result is changed + assert: + that: + - play_with_build is changed + - success_msg in play_with_build.stdout + + always: + + - name: Cleanup pods + containers.podman.podman_play: + kube_file: "{{ kube_dir }}/kube-buil-test.yaml" + state: absent