Skip to content

Commit

Permalink
Remove non-public images from the git-sha-based target determination (#…
Browse files Browse the repository at this point in the history
…525)

* Remove melt from sha-based target determination

* Print a warning message for skipped docker images.

* Exclude non-public images from the dependency chain.

* Update removing non-pub images so the skipped images are logged.
  • Loading branch information
VJalili authored Apr 19, 2023
1 parent 9dab36b commit c248224
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions scripts/docker/build_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,18 @@ def get_ordered_build_chain_list(self, registry: ContainerRegistry) -> List[str]
}.difference(targets_to_build)
)

# Implementation note: it would be less verbose to add `self.non_public_images` to the `difference`
# method above. However, the following implementation enables simpler logging of the skipped images.
for non_public_image in self.non_public_images:
if non_public_image in new_targets_to_build:
new_targets_to_build.remove(non_public_image)
print_colored(
f"Skipping building the Docker image `{non_public_image}` since it cannot be hosted "
f"publicly. This image needs to be rebuilt, please consider building using the "
f"`--targets` tag and hosting it in a non-public registry.",
Colors.YELLOW
)

# noinspection PyTypeChecker
return sorted(targets_to_build, key=self.get_build_priority)

Expand Down Expand Up @@ -411,11 +423,19 @@ def build_and_push(self):
if self.project_arguments.base_git_commit is not None:
changed_project_files = self.changed_project_files
print(f"changed_project_files: {changed_project_files}", file=sys.stderr)
self.project_arguments.targets = [
target for target, image_dependencies in self.dependencies.items()
if image_dependencies.has_change(changed_project_files)
]
print(f"targets = {self.project_arguments.targets}")
self.project_arguments.targets = []
for target, image_dependencies in self.dependencies.items():
if image_dependencies.has_change(changed_project_files):
if target not in self.non_public_images:
self.project_arguments.targets.append(target)
else:
print_colored(
f"Skipping building the Docker image `{target}` since it cannot be hosted publicly. "
f"This image needs to be rebuilt, please consider building using the "
f"`--targets` tag and hosting it in a non-public registry.",
Colors.YELLOW
)
print_colored(f"targets = {self.project_arguments.targets}", Colors.GREEN)
elif "all" in self.project_arguments.targets:
self.project_arguments.targets = ProjectBuilder.images_built_by_all

Expand Down

0 comments on commit c248224

Please # to comment.