Skip to content

Commit

Permalink
Add build and context_dir option to podman_play (#649)
Browse files Browse the repository at this point in the history
* Add test for kube_play with image build

Signed-off-by: nishipy <[email protected]>

* Add build and context_dir options to podman_play

Signed-off-by: nishipy <[email protected]>

* Fix yamllint errors

Signed-off-by: nishipy <[email protected]>

* Fix ci errors

Signed-off-by: nishipy <[email protected]>

---------

Signed-off-by: nishipy <[email protected]>
  • Loading branch information
nishipy authored Oct 19, 2023
1 parent ed8c04f commit b65a3de
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 0 deletions.
14 changes: 14 additions & 0 deletions plugins/modules/podman_play.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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").
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM ubi8-init
RUN dnf -y install httpd; dnf -y clean all
RUN systemctl enable httpd.service
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions tests/integration/targets/podman_play/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

51 changes: 51 additions & 0 deletions tests/integration/targets/podman_play/tasks/play-with-build.yml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit b65a3de

Please sign in to comment.