mirror of
https://github.com/containers/ansible-podman-collections.git
synced 2026-03-22 02:29:08 +00:00
Update podman_image to specify CPU arch when pulling image (#578)
* Add test to sprcify CPU arch when pulling image Signed-off-by: nishipy <goodisonev4@gmail.com> * Update to specify CPU arch when pulling image Signed-off-by: nishipy <goodisonev4@gmail.com> * Add document for specifying arch Signed-off-by: nishipy <goodisonev4@gmail.com> * Fix for idempotency Signed-off-by: nishipy <goodisonev4@gmail.com> * Update plugins/modules/podman_image.py Signed-off-by: nishipy <goodisonev4@gmail.com> --------- Signed-off-by: nishipy <goodisonev4@gmail.com>
This commit is contained in:
parent
e8c270370d
commit
ab64d5f953
2 changed files with 63 additions and 4 deletions
|
|
@ -15,6 +15,10 @@ DOCUMENTATION = r'''
|
|||
description:
|
||||
- Build, pull, or push images using Podman.
|
||||
options:
|
||||
arch:
|
||||
description:
|
||||
- CPU architecutre for the container image
|
||||
type: str
|
||||
name:
|
||||
description:
|
||||
- Name of the image to pull, push, or delete. It may contain a tag using the format C(image:tag).
|
||||
|
|
@ -267,6 +271,11 @@ EXAMPLES = r"""
|
|||
- name: nginx
|
||||
tag: 3
|
||||
dest: docker.io/acme
|
||||
|
||||
- name: Pull an image for a specific CPU architecture
|
||||
containers.podman.podman_image:
|
||||
name: nginx
|
||||
arch: amd64
|
||||
"""
|
||||
|
||||
RETURN = r"""
|
||||
|
|
@ -422,6 +431,7 @@ class PodmanImageManager(object):
|
|||
self.ca_cert_dir = self.module.params.get('ca_cert_dir')
|
||||
self.build = self.module.params.get('build')
|
||||
self.push_args = self.module.params.get('push_args')
|
||||
self.arch = self.module.params.get('arch')
|
||||
|
||||
repo, repo_tag = parse_repository_tag(self.name)
|
||||
if repo_tag:
|
||||
|
|
@ -526,10 +536,15 @@ class PodmanImageManager(object):
|
|||
rc, images, err = self._run(args, ignore_errors=True)
|
||||
images = json.loads(images)
|
||||
if len(images) > 0:
|
||||
inspect_json = self.inspect_image(image_name)
|
||||
if self._is_target_arch(inspect_json, self.arch) or not self.arch:
|
||||
return images
|
||||
else:
|
||||
|
||||
return None
|
||||
|
||||
def _is_target_arch(self, inspect_json=None, arch=None):
|
||||
return arch and inspect_json[0]['Architecture'] == arch
|
||||
|
||||
def find_image_id(self, image_id=None):
|
||||
if image_id is None:
|
||||
# If image id is set as image_name, remove tag
|
||||
|
|
@ -560,6 +575,9 @@ class PodmanImageManager(object):
|
|||
|
||||
args = ['pull', image_name, '-q']
|
||||
|
||||
if self.arch:
|
||||
args.extend(['--arch', self.arch])
|
||||
|
||||
if self.auth_file:
|
||||
args.extend(['--authfile', self.auth_file])
|
||||
|
||||
|
|
@ -762,6 +780,7 @@ def main():
|
|||
module = AnsibleModule(
|
||||
argument_spec=dict(
|
||||
name=dict(type='str', required=True),
|
||||
arch=dict(type='str'),
|
||||
tag=dict(type='str', default='latest'),
|
||||
pull=dict(type='bool', default=True),
|
||||
push=dict(type='bool', default=False),
|
||||
|
|
|
|||
|
|
@ -277,6 +277,45 @@
|
|||
- "'Failed to find image bad_image' in bad_push.msg"
|
||||
- "'image pull set to False' in bad_push.msg"
|
||||
|
||||
- name: Pull an image for a specific CPU architecture
|
||||
containers.podman.podman_image:
|
||||
executable: "{{ test_executable | default('podman') }}"
|
||||
name: docker.io/library/ubuntu
|
||||
arch: amd64
|
||||
register: pull_arch1
|
||||
|
||||
- name: Pull the same image for the same CPU architecture
|
||||
containers.podman.podman_image:
|
||||
executable: "{{ test_executable | default('podman') }}"
|
||||
name: docker.io/library/ubuntu
|
||||
arch: amd64
|
||||
register: pull_arch2
|
||||
|
||||
- name: Pull the same image but for another CPU architecture
|
||||
containers.podman.podman_image:
|
||||
executable: "{{ test_executable | default('podman') }}"
|
||||
name: docker.io/library/ubuntu
|
||||
arch: arm
|
||||
register: pull_arch3
|
||||
|
||||
- name: Ensure the result of pulling image for another CPU architecture
|
||||
assert:
|
||||
that:
|
||||
- "pull_arch2 is not changed"
|
||||
- "pull_arch3 is changed"
|
||||
|
||||
- name: Get the image info
|
||||
containers.podman.podman_image_info:
|
||||
executable: "{{ test_executable | default('podman') }}"
|
||||
name: docker.io/library/ubuntu
|
||||
register: imageinfo_arch
|
||||
|
||||
- name: Ensure the CPU architecture of the image is as expected
|
||||
assert:
|
||||
that:
|
||||
- item.Architecture == "arm"
|
||||
loop: "{{ imageinfo_arch.images }}"
|
||||
|
||||
always:
|
||||
- name: Cleanup images
|
||||
containers.podman.podman_image:
|
||||
|
|
@ -284,6 +323,7 @@
|
|||
name: "{{ item }}"
|
||||
state: absent
|
||||
loop:
|
||||
- docker.io/library/ubuntu
|
||||
- quay.io/coreos/alpine-sh
|
||||
- quay.io/coreos/etcd:v3.3.11
|
||||
- localhost/testimage
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue