@@ -106,23 +106,43 @@ def get_changed_docker_images(
106106 str (files_changed ),
107107 )
108108
109- # Rebuild all images
110- changed_images = [DockerImage (dockerfile_dir , image_description ["name" ], image_description .get ("only_amd64" , False )) for dockerfile_dir , image_description in images_dict .items ()]
111-
112- # for dockerfile_dir, image_description in images_dict.items():
113- # for f in files_changed:
114- # if f.startswith(dockerfile_dir):
115- # name = image_description["name"]
116- # only_amd64 = image_description.get("only_amd64", False)
117- # logging.info(
118- # "Found changed file '%s' which affects "
119- # "docker image '%s' with path '%s'",
120- # f,
121- # name,
122- # dockerfile_dir,
123- # )
124- # changed_images.append(DockerImage(dockerfile_dir, name, only_amd64))
125- # break
109+ # Find changed images
110+ all_images = []
111+ changed_images = []
112+ for dockerfile_dir , image_description in images_dict .items ():
113+ all_images .append (DockerImage (dockerfile_dir , image_description ["name" ], image_description .get ("only_amd64" , False )))
114+ for f in files_changed :
115+ if f .startswith (dockerfile_dir ):
116+ name = image_description ["name" ]
117+ only_amd64 = image_description .get ("only_amd64" , False )
118+ logging .info (
119+ "Found changed file '%s' which affects "
120+ "docker image '%s' with path '%s'" ,
121+ f ,
122+ name ,
123+ dockerfile_dir ,
124+ )
125+ changed_images .append (DockerImage (dockerfile_dir , name , only_amd64 ))
126+ break
127+
128+ # Rebuild all images on push, release, or scheduled run
129+ if pr_info .number in [0 ,1 ]:
130+ changed_images = all_images
131+
132+ else :
133+ # Rebuild all on opened PR
134+ if pr_info .event ['action' ] in ['opened' , 'reopened' ]:
135+ changed_images = all_images
136+
137+ # Check that image for the PR exists
138+ elif pr_info .event ['action' ] == 'synchronize' :
139+ unchanged_images = [
140+ image for image in all_images if image not in changed_images
141+ ]
142+ logging .info (f"Unchanged images: { unchanged_images } " )
143+ for image in unchanged_images :
144+ if subprocess .run (f"docker manifest inspect { image .repo } :{ pr_info .number } " , shell = True ).returncode != 0 :
145+ changed_images .append (image )
126146
127147 # The order is important: dependents should go later than bases, so that
128148 # they are built with updated base versions.
0 commit comments