mirror of
https://github.com/ansible-collections/community.docker.git
synced 2025-12-16 03:52:05 +00:00
fix: Handle tag@digest format in push_image method
Extends the tag@digest fix to also cover push operations in docker_image.py.
The push_image() method was passing combined tag@digest format directly to
the Docker API's /images/{name}/push endpoint, which fails with
"invalid tag format" errors.
This fix:
1. Imports build_pull_arguments() into docker_image.py
2. Uses the helper in push_image() before calling the API
3. When tag contains @ (but isn't a pure digest), passes the full
reference as the image name and omits the tag parameter
This complements the previous fix to pull_image() methods, ensuring
both pull and push operations handle tag@digest correctly.
This commit is contained in:
parent
2019cd8f3c
commit
31cebc66bf
@ -405,6 +405,7 @@ from ansible_collections.community.docker.plugins.module_utils._image_archive im
|
|||||||
)
|
)
|
||||||
from ansible_collections.community.docker.plugins.module_utils._util import (
|
from ansible_collections.community.docker.plugins.module_utils._util import (
|
||||||
DockerBaseClass,
|
DockerBaseClass,
|
||||||
|
build_pull_arguments,
|
||||||
clean_dict_booleans_for_docker_api,
|
clean_dict_booleans_for_docker_api,
|
||||||
is_image_name_id,
|
is_image_name_id,
|
||||||
is_valid_tag,
|
is_valid_tag,
|
||||||
@ -784,6 +785,10 @@ class ImageManager(DockerBaseClass):
|
|||||||
push_repository, push_tag = parse_repository_tag(
|
push_repository, push_tag = parse_repository_tag(
|
||||||
push_repository
|
push_repository
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Handle combined tag@digest format - Docker API doesn't accept it in tag param
|
||||||
|
push_name, push_tag_param = build_pull_arguments(push_repository, push_tag)
|
||||||
|
|
||||||
push_registry, dummy = resolve_repository_name(push_repository)
|
push_registry, dummy = resolve_repository_name(push_repository)
|
||||||
headers = {}
|
headers = {}
|
||||||
header = get_config_header(self.client, push_registry)
|
header = get_config_header(self.client, push_registry)
|
||||||
@ -792,12 +797,17 @@ class ImageManager(DockerBaseClass):
|
|||||||
# See https://github.com/moby/moby/issues/50614.
|
# See https://github.com/moby/moby/issues/50614.
|
||||||
header = base64.urlsafe_b64encode(b"{}")
|
header = base64.urlsafe_b64encode(b"{}")
|
||||||
headers["X-Registry-Auth"] = header
|
headers["X-Registry-Auth"] = header
|
||||||
|
|
||||||
|
params: dict[str, t.Any] = {}
|
||||||
|
if push_tag_param is not None:
|
||||||
|
params["tag"] = push_tag_param
|
||||||
|
|
||||||
response = self.client._post_json(
|
response = self.client._post_json(
|
||||||
self.client._url("/images/{0}/push", push_repository),
|
self.client._url("/images/{0}/push", push_name),
|
||||||
data=None,
|
data=None,
|
||||||
headers=headers,
|
headers=headers,
|
||||||
stream=True,
|
stream=True,
|
||||||
params={"tag": push_tag},
|
params=params,
|
||||||
)
|
)
|
||||||
self.client._raise_for_status(response)
|
self.client._raise_for_status(response)
|
||||||
for line in self.client._stream_helper(response, decode=True):
|
for line in self.client._stream_helper(response, decode=True):
|
||||||
|
|||||||
@ -12,6 +12,10 @@ The Docker SDK and API don't accept "tag@digest" in the tag parameter.
|
|||||||
build_pull_arguments handles this by:
|
build_pull_arguments handles this by:
|
||||||
- Returning full reference as name when tag contains @
|
- Returning full reference as name when tag contains @
|
||||||
- Returning None for tag in that case
|
- Returning None for tag in that case
|
||||||
|
|
||||||
|
This function is used by:
|
||||||
|
- pull_image() in _common.py and _common_api.py (for pulling images)
|
||||||
|
- push_image() in docker_image.py (for pushing images)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user