3535ddiff_container_name = os .getenv ("DDIFF_CONTAINER_NAME" , "ddiff-registry" )
3636ddiff_register_volume = os .getenv ("DDIFF_REGISTRY_VOLUME" )
3737ddiff_disable_repository = os .getenv ("DDIFF_DISABLE_RESPOSITORY" , False )
38+ ddiff_force_skopeo = os .getenv ("DDIFF_FORCE_SKOPEO" , "" ).lower () in ["1" , "true" , "yes" , "on" ]
39+ ddiff_force_podman = os .getenv ("DDIFF_FORCE_PODMAN" , "" ).lower () in ["1" , "true" , "yes" , "on" ]
40+
41+ container_runtime = "docker"
42+ container_transport = "docker-daemon"
43+ push_pull_with_skopeo = False
3844
3945def print_debug (* args ):
4046 print ("[ddiff]" , * args )
@@ -172,27 +178,38 @@ def _upload_manifest(tag, manifest_path, manifest_media_type=DOCKER_MANIFEST_V2)
172178def run_registry ():
173179 volume_arg = "" if ddiff_register_volume is None else f"-v{ ddiff_register_volume } :/var/lib/registry"
174180
175- cmd = f"docker run -it -d -p{ ddiff_port } :5000 --name { ddiff_container_name } registry:2.8.3"
181+ tls_verify_flag = " --tls-verify=false" if container_runtime == "podman" else ""
182+ cmd = f"{ container_runtime } run -it -d -p{ ddiff_port } :5000 { volume_arg } --name { ddiff_container_name } { tls_verify_flag } registry:2.8.3"
176183 run_command (cmd )
177184
178185def push_images (tags ):
179186 print_debug ("Pushing to the registry..." )
180187 for host_tag in tags :
181188 registry_tag = f"{ ddiff_url_base } /{ _prepare_tag (host_tag )} "
182- run_command (f"docker tag { host_tag } { registry_tag } " )
183- print ("a" , f"docker tag { host_tag } { registry_tag } " )
184- run_command (f"docker push { registry_tag } " )
185- print ("b" )
186- run_command (f"docker rmi { registry_tag } " )
189+ if push_pull_with_skopeo :
190+ run_command (
191+ f"skopeo copy --dest-tls-verify=false --format=v2s2 "
192+ f"{ container_transport } :{ host_tag } docker://{ registry_tag } "
193+ )
194+ else :
195+ run_command (f"docker tag { host_tag } { registry_tag } " )
196+ run_command (f"docker push { registry_tag } " )
197+ run_command (f"docker rmi { registry_tag } " )
187198 # print_debug("Done.")
188199
189200def pull_images (tags ):
190201 print_debug ("Pulling from the registry..." )
191202 for host_tag in tags :
192203 registry_tag = f"{ ddiff_url_base } /{ _prepare_tag (host_tag )} "
193- run_command (f"docker pull { registry_tag } " )
194- run_command (f"docker tag { registry_tag } { host_tag } " )
195- run_command (f"docker rmi { registry_tag } " )
204+ if push_pull_with_skopeo :
205+ run_command (
206+ f"skopeo copy --src-tls-verify=false "
207+ f"docker://{ registry_tag } { container_transport } :{ host_tag } "
208+ )
209+ else :
210+ run_command (f"docker pull { registry_tag } " )
211+ run_command (f"docker tag { registry_tag } { host_tag } " )
212+ run_command (f"docker rmi { registry_tag } " )
196213 # print_debug("Done.")
197214
198215def diff_image (base_tag , target_tag ):
@@ -311,7 +328,7 @@ def build_image(build_args):
311328 assert not target_tag is None
312329
313330 print_debug (f"Building image with tag: { target_tag } \n we will diff image blobs of { target_tag } from { base_tag } " )
314- run_command ("docker build " + " " .join (build_args ))
331+ run_command (f" { container_runtime } build " + " " .join (build_args ))
315332 print_debug (f"Diff image blobs of { target_tag } from { base_tag } " )
316333 diff_image (base_tag , target_tag )
317334
@@ -331,6 +348,23 @@ def list_blobs(tag):
331348 print (blob .replace ("sha256:" , "" ))
332349
333350if __name__ == '__main__' :
351+ if ddiff_force_podman or shutil .which ("docker" ) is None :
352+ if shutil .which ("podman" ) is None :
353+ print_debug ("Docker and podman commands are not available." )
354+ print ("Please install podman first (e.g. https://podman.io/docs/installation) and run again." )
355+ sys .exit (0 )
356+
357+ container_runtime = "podman"
358+ container_transport = "containers-storage"
359+ push_pull_with_skopeo = True
360+ if ddiff_force_podman :
361+ print_debug ("DDIFF_FORCE_PODMAN is enabled. Switching to podman mode." )
362+ else :
363+ print_debug ("Docker command not found. Switching to podman mode." )
364+ elif ddiff_force_skopeo :
365+ push_pull_with_skopeo = True
366+ print_debug ("DDIFF_FORCE_SKOPEO is enabled. Using skopeo for push/pull." )
367+
334368 if len (sys .argv ) < 2 or not sys .argv [1 ] in ["server" , "push" , "pull" , "diff" , "load" , "build" , "list" ]:
335369 print ("Usage: ddiff [command] [args...]" )
336370 print ("Commands:" )
0 commit comments