@@ -43,8 +43,29 @@ def image_of_commit_exists(commit_hash: str) -> bool:
4343 return mz_image_tag_exists (commit_to_image_tag (commit_hash ))
4444
4545
46+ def mz_image_tag_exists_cmdline (image_name : str ) -> bool :
47+ command = [
48+ "docker" ,
49+ "manifest" ,
50+ "inspect" ,
51+ image_name ,
52+ ]
53+ try :
54+ subprocess .check_output (command , stderr = subprocess .STDOUT , text = True )
55+ EXISTENCE_OF_IMAGE_NAMES_FROM_EARLIER_CHECK [image_name ] = True
56+ return True
57+ except subprocess .CalledProcessError as e :
58+ if "no such manifest:" in e .output :
59+ print (f"Failed to fetch image manifest '{ image_name } ' (does not exist)" )
60+ EXISTENCE_OF_IMAGE_NAMES_FROM_EARLIER_CHECK [image_name ] = False
61+ else :
62+ print (f"Failed to fetch image manifest '{ image_name } ' ({ e .output } )" )
63+ # do not cache the result of unknown error messages
64+ return False
65+
66+
4667def mz_image_tag_exists (image_tag : str ) -> bool :
47- image_name = f"materialize /materialized:{ image_tag } "
68+ image_name = f"{ image_registry () } /materialized:{ image_tag } "
4869
4970 if image_name in EXISTENCE_OF_IMAGE_NAMES_FROM_EARLIER_CHECK :
5071 image_exists = EXISTENCE_OF_IMAGE_NAMES_FROM_EARLIER_CHECK [image_name ]
@@ -67,30 +88,16 @@ def mz_image_tag_exists(image_tag: str) -> bool:
6788 # when the image doesn't exist, see https://www.docker.com/increase-rate-limits/,
6889 # so use the API instead.
6990
91+ if image_registry () != "materialize" :
92+ return mz_image_tag_exists_cmdline (image_name )
93+
7094 try :
7195 response = requests .get (
7296 f"https://hub.docker.com/v2/repositories/materialize/materialized/tags/{ image_tag } "
7397 )
7498 result = response .json ()
7599 except (requests .exceptions .ConnectionError , requests .exceptions .JSONDecodeError ):
76- command = [
77- "docker" ,
78- "manifest" ,
79- "inspect" ,
80- image_name ,
81- ]
82- try :
83- subprocess .check_output (command , stderr = subprocess .STDOUT , text = True )
84- EXISTENCE_OF_IMAGE_NAMES_FROM_EARLIER_CHECK [image_name ] = True
85- return True
86- except subprocess .CalledProcessError as e :
87- if "no such manifest:" in e .output :
88- print (f"Failed to fetch image manifest '{ image_name } ' (does not exist)" )
89- EXISTENCE_OF_IMAGE_NAMES_FROM_EARLIER_CHECK [image_name ] = False
90- else :
91- print (f"Failed to fetch image manifest '{ image_name } ' ({ e .output } )" )
92- # do not cache the result of unknown error messages
93- return False
100+ return mz_image_tag_exists_cmdline (image_name )
94101
95102 if result .get ("images" ):
96103 EXISTENCE_OF_IMAGE_NAMES_FROM_EARLIER_CHECK [image_name ] = True
@@ -198,3 +205,11 @@ def _select_image_name_from_candidates(
198205 )
199206
200207 return image_name_candidates [0 ]
208+
209+
210+ def image_registry () -> str :
211+ return (
212+ "ghcr.io/materializeinc/materialize"
213+ if ui .env_is_truthy ("MZ_GHCR" , "1" )
214+ else "materialize"
215+ )
0 commit comments