Skip to content

Commit f2ed372

Browse files
authored
Refactor image pushing logic with Docker Hub support
1 parent 6d42841 commit f2ed372

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

ddiff.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -207,21 +207,25 @@ def run_registry():
207207
cmd = f"{container_runtime} run -it -d -p{ddiff_port}:5000 {volume_arg} --name {ddiff_container_name}{tls_verify_flag} registry:2.8.3"
208208
run_command(cmd)
209209

210-
def _skopeo_source_ref(host_tag):
210+
def _skopeo_source_ref(host_tag, from_docker_hub):
211211
"""Return the correct skopeo source transport:reference for Podman."""
212212
# Podman stores short names under the localhost/ prefix in containers-storage
213-
if not host_tag.startswith("localhost/"):
214-
host_tag = f"localhost/{host_tag}"
215-
return f"containers-storage:{host_tag}"
216213

217-
def push_images(tags):
214+
if from_docker_hub:
215+
return f"docker://docker.io/{host_tag}"
216+
else:
217+
if not host_tag.startswith("localhost/"):
218+
host_tag = f"localhost/{host_tag}"
219+
return f"containers-storage:{host_tag}"
220+
221+
def push_images(tags, from_docker_hub=False):
218222
print_debug("Pushing to the registry...")
219223
for host_tag in tags:
220224
registry_tag = f"{ddiff_url_base}/{_prepare_tag(host_tag)}"
221225
if push_pull_with_skopeo:
222226
run_command(
223227
f"skopeo copy --dest-tls-verify=false --format=v2s2 "
224-
f"{_skopeo_source_ref(host_tag)} docker://{registry_tag}"
228+
f"{_skopeo_source_ref(host_tag, from_docker_hub=from_docker_hub)} docker://{registry_tag}"
225229
)
226230
else:
227231
assert container_runtime == "docker", "Only docker is supported without skopeo"
@@ -247,7 +251,8 @@ def pull_images(tags):
247251
# print_debug("Done.")
248252

249253
def diff_image(base_tag, target_tag):
250-
push_images([base_tag, target_tag])
254+
push_images([base_tag], from_docker_hub=True)
255+
push_images(target_tag)
251256

252257
base_tag = _prepare_tag(base_tag)
253258
target_tag = _prepare_tag(target_tag)

0 commit comments

Comments
 (0)