summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Fontein <felix@fontein.de>2021-01-08 21:32:48 +0100
committerGitHub <noreply@github.com>2021-01-08 14:32:48 -0600
commit0f65b901f7944f53d17306e1c76fea08e09ef126 (patch)
treec4ab314c48df1bc81d023bc97fdfa53ee12643b9
parent95f65b9249da7f014be371c2181824baf885bbe0 (diff)
downloadansible-0f65b901f7944f53d17306e1c76fea08e09ef126.tar.gz
docker_image: always push, also when tagging is not necessary
Backport of https://github.com/ansible-collections/community.docker/commit/117f1322138c9910add8f43adb2f08e7ee5998d8 (#73066)
-rw-r--r--changelogs/fragments/community.docker-53-docker_image-tag-push.yml2
-rw-r--r--lib/ansible/modules/cloud/docker/docker_image.py4
-rw-r--r--test/integration/targets/docker-registry/tasks/tests/docker_image.yml78
3 files changed, 81 insertions, 3 deletions
diff --git a/changelogs/fragments/community.docker-53-docker_image-tag-push.yml b/changelogs/fragments/community.docker-53-docker_image-tag-push.yml
new file mode 100644
index 0000000000..30254673b9
--- /dev/null
+++ b/changelogs/fragments/community.docker-53-docker_image-tag-push.yml
@@ -0,0 +1,2 @@
+bugfixes:
+- "docker_image - if ``push=true`` is used with ``repository``, and the image does not need to be tagged, still push. This can happen if ``repository`` and ``name`` are equal (https://github.com/ansible-collections/community.docker/issues/52, https://github.com/ansible-collections/community.docker/pull/53)."
diff --git a/lib/ansible/modules/cloud/docker/docker_image.py b/lib/ansible/modules/cloud/docker/docker_image.py
index 363a66505f..0599ae509c 100644
--- a/lib/ansible/modules/cloud/docker/docker_image.py
+++ b/lib/ansible/modules/cloud/docker/docker_image.py
@@ -715,8 +715,8 @@ class ImageManager(DockerBaseClass):
if image and image['Id'] == self.results['image']['Id']:
self.results['changed'] = False
- if push:
- self.push_image(repo, repo_tag)
+ if push:
+ self.push_image(repo, repo_tag)
def build_image(self):
'''
diff --git a/test/integration/targets/docker-registry/tasks/tests/docker_image.yml b/test/integration/targets/docker-registry/tasks/tests/docker_image.yml
index 58b319517d..1e8ea9d42c 100644
--- a/test/integration/targets/docker-registry/tasks/tests/docker_image.yml
+++ b/test/integration/targets/docker-registry/tasks/tests/docker_image.yml
@@ -10,7 +10,7 @@
- name: Registering image name
set_fact:
- inames: "{{ inames + [iname, test_image_base ~ ':latest', hello_world_image_base ~ ':latest'] }}"
+ inames: "{{ inames + [iname, test_image_base ~ ':latest', hello_world_image_base ~ ':latest', hello_world_image_base ~ ':newtag', hello_world_image_base ~ ':newtag2'] }}"
####################################################################
## interact with test registry #####################################
@@ -101,6 +101,82 @@
- facts_2.images | length == 0
- facts_3.images | length == 1
+- name: Tag different image with new tag
+ docker_image:
+ name: quay.io/ansible/docker-test-containers:alpine3.8
+ repository: "{{ hello_world_image_base }}:newtag"
+ push: no
+ source: pull
+
+- name: Push different image with new tag
+ docker_image:
+ name: "{{ hello_world_image_base }}"
+ repository: "{{ hello_world_image_base }}"
+ tag: newtag
+ push: yes
+ source: local
+ register: push_1_different
+
+- name: Push different image with new tag (idempotent)
+ docker_image:
+ name: "{{ hello_world_image_base }}"
+ repository: "{{ hello_world_image_base }}"
+ tag: newtag
+ push: yes
+ source: local
+ register: push_2_different
+
+- assert:
+ that:
+ - push_1_different is changed
+ - push_2_different is not changed
+
+- name: Tag same image with new tag
+ docker_image:
+ name: quay.io/ansible/docker-test-containers:alpine3.8
+ repository: "{{ hello_world_image_base }}:newtag2"
+ push: no
+ source: pull
+
+- name: Push same image with new tag
+ docker_image:
+ name: "{{ hello_world_image_base }}"
+ repository: "{{ hello_world_image_base }}"
+ tag: newtag2
+ push: yes
+ source: local
+ register: push_1_same
+
+- name: Push same image with new tag (idempotent)
+ docker_image:
+ name: "{{ hello_world_image_base }}"
+ repository: "{{ hello_world_image_base }}"
+ tag: newtag2
+ push: yes
+ source: local
+ register: push_2_same
+
+- assert:
+ that:
+ # NOTE: This should be:
+ # - push_1_same is changed
+ # Unfortunately docker does *NOT* report whether the tag already existed or not.
+ # Here are the logs returned by client.push() for both tasks (which are exactly the same):
+ # push_1_same:
+ # {"status": "The push refers to repository [localhost:32796/test/hello-world]"},
+ # {"id": "3fc64803ca2d", "progressDetail": {}, "status": "Preparing"},
+ # {"id": "3fc64803ca2d", "progressDetail": {}, "status": "Layer already exists"},
+ # {"status": "newtag2: digest: sha256:92251458088c638061cda8fd8b403b76d661a4dc6b7ee71b6affcf1872557b2b size: 528"},
+ # {"aux": {"Digest": "sha256:92251458088c638061cda8fd8b403b76d661a4dc6b7ee71b6affcf1872557b2b", "Size": 528, "Tag": "newtag2"}, "progressDetail": {}}
+ # push_2_same:
+ # {"status": "The push refers to repository [localhost:32796/test/hello-world]"},
+ # {"id": "3fc64803ca2d", "progressDetail": {}, "status": "Preparing"},
+ # {"id": "3fc64803ca2d", "progressDetail": {}, "status": "Layer already exists"},
+ # {"status": "newtag2: digest: sha256:92251458088c638061cda8fd8b403b76d661a4dc6b7ee71b6affcf1872557b2b size: 528"},
+ # {"aux": {"Digest": "sha256:92251458088c638061cda8fd8b403b76d661a4dc6b7ee71b6affcf1872557b2b", "Size": 528, "Tag": "newtag2"}, "progressDetail": {}}
+ - push_1_same is not changed
+ - push_2_same is not changed
+
####################################################################
## repository ######################################################
####################################################################