docker_image: improve/fix handling of image IDs (#87)

* Improve/fix handling of image IDs in docker_image.

* Fix syntax error.

* Linting.

* Fix name collision.

* Add various tests.

* Fix tests.

* Improve image finding by ID, and fix various related bugs.

* accept_not_there -> accept_missing_image.

* Remove unnecessary dummy variable.
This commit is contained in:
Felix Fontein
2021-02-28 10:40:11 +01:00
committed by GitHub
parent ed9bf1117f
commit f2d16da643
6 changed files with 149 additions and 25 deletions
@@ -70,13 +70,66 @@
force_tag: yes
register: tag_3
- name: Tag image with ID instead of name
docker_image:
source: local
name: "{{ present_1.image.Id }}"
repository: "{{ docker_test_image_hello_world_base }}:alias"
register: tag_4
- assert:
that:
- tag_1 is changed
- tag_2 is not changed
- tag_3 is not changed
- tag_4 is not changed
- name: Cleanup alias tag
docker_image:
name: "{{ docker_test_image_hello_world_base }}:alias"
state: absent
- name: Tag image with ID instead of name (use ID for repository, must fail)
docker_image:
source: local
name: "{{ docker_test_image_hello_world }}"
repository: "{{ present_1.image.Id }}"
register: fail_1
ignore_errors: true
- name: Push image with ID (must fail)
docker_image:
source: local
name: "{{ present_1.image.Id }}"
push: true
register: fail_2
ignore_errors: true
- name: Pull image ID (must fail)
docker_image:
source: pull
name: "{{ present_1.image.Id }}"
force_source: true
register: fail_3
ignore_errors: true
- name: buildargs
docker_image:
source: build
name: "{{ present_1.image.Id }}"
build:
path: "{{ output_dir }}/files"
force_source: true
register: fail_4
ignore_errors: yes
- assert:
that:
- fail_1 is failed
- "'`repository` must not be an image ID' in fail_1.msg"
- fail_2 is failed
- "'Cannot push an image by ID' in fail_2.msg"
- fail_3 is failed
- "'Image name must not be an image ID for source=pull' in fail_3.msg"
- fail_4 is failed
- "'Image name must not be an image ID for source=build' in fail_4.msg"
@@ -241,6 +241,13 @@
source: pull
register: archive_image
- name: Archive image by ID
docker_image:
name: "{{ archive_image.image.Id }}"
archive_path: "{{ output_dir }}/image_id.tar"
source: pull
register: archive_image_id
- name: Create invalid archive
copy:
dest: "{{ output_dir }}/image-invalid.tar"
@@ -290,6 +297,13 @@
api_version: "1.22"
register: load_image_4
- name: load image (ID, idempotency)
docker_image:
name: "{{ archive_image.image.Id }}"
load_path: "{{ output_dir }}/image_id.tar"
source: load
register: load_image_5
- assert:
that:
- load_image is changed
@@ -302,6 +316,7 @@
- '"Detected no loaded images. Archive potentially corrupt?" == load_image_3.msg'
- load_image_4 is changed
- "'The API version of your Docker daemon is < 1.23, which does not return the image loading result from the Docker daemon. Therefore, we cannot verify whether the expected image was loaded, whether multiple images where loaded, or whether the load actually succeeded. You should consider upgrading your Docker daemon.' in load_image_4.warnings"
- load_image_5 is not changed
####################################################################
## build.path ######################################################