@@ -82,6 +82,16 @@ def write_dockerfile(dest_dir, entrypoint):
8282 with open (os .path .join (dest_dir , "Dockerfile" ), "w" ) as f :
8383 f .write (dockerfile )
8484
85+ def get_image_digest (image_name , tag ):
86+ result = subprocess .run (
87+ ["docker" , "buildx" , "imagetools" , "inspect" , f"{ image_name } :{ tag } " ],
88+ stdout = subprocess .PIPE , check = True , text = True
89+ )
90+ for line in result .stdout .splitlines ():
91+ if line .strip ().startswith ("Digest:" ):
92+ return line .strip ().split (":" , 1 )[1 ].strip ()
93+ return None
94+
8595def build_and_push_image (dest_dir , image_name , tag ):
8696 # Build
8797 subprocess .run ([
@@ -92,6 +102,10 @@ def build_and_push_image(dest_dir, image_name, tag):
92102 "docker" , "push" , f"{ image_name } :{ tag } "
93103 ], check = True )
94104 print (f"Pushed { image_name } :{ tag } " )
105+ digest = get_image_digest (image_name , tag )
106+ print (f"Image digest: { digest } " )
107+ with open ("/tmp/digest.txt" , "w" ) as f :
108+ f .write (digest )
95109
96110if __name__ == "__main__" :
97111 if len (sys .argv ) != 5 :
0 commit comments