def build(self, image_info: ImageInfo): image_info_json = image_info.to_json() if image_info.image_state == ImageState.NEEDS_TO_BE_BUILD.name: yield DockerBuildImageTask(image_name=self.image_name, image_info_json=image_info_json) image_info.image_state = ImageState.WAS_BUILD.name elif image_info.image_state == ImageState.CAN_BE_LOADED.name: yield DockerLoadImageTask(image_name=self.image_name, image_info_json=image_info_json) image_info.image_state = ImageState.WAS_LOADED.name elif image_info.image_state == ImageState.REMOTE_AVAILABLE.name: yield DockerPullImageTask(image_name=self.image_name, image_info_json=image_info_json) image_info.image_state = ImageState.WAS_PULLED.name elif image_info.image_state == ImageState.TARGET_LOCALLY_AVAILABLE.name: image_info.image_state = ImageState.USED_LOCAL.name elif image_info.image_state == ImageState.SOURCE_LOCALLY_AVAILABLE.name: image_info.image_state = ImageState.WAS_TAGED.name docker_client_config().get_client().images.get( image_info.get_source_complete_name()).tag( repository=image_info.target_repository_name, tag=image_info.get_target_complete_tag()) else: raise Exception( "Task %s: Image state %s not supported for image %s", self.task_id, image_info.image_state, image_info.get_target_complete_name())
def run_task(self): image_info_of_dependencies = DependencyImageInfoCollector( ).get_from_dict_of_inputs(self.input()) image_hash = self._build_context_hasher.generate_image_hash( image_info_of_dependencies) image_info = ImageInfo( source_repository_name=self._source_repository_name, target_repository_name=self._target_repository_name, source_tag=self._source_image_tag, target_tag=self._target_image_tag, hash=image_hash, commit=self.get_commit_id(), build_name=build_config().build_name, depends_on_images=image_info_of_dependencies, image_state=None, image_description=self.image_description) target_image_target = DockerImageTarget( self._target_repository_name, image_info.get_target_complete_tag()) source_image_target = DockerImageTarget( self._source_repository_name, image_info.get_source_complete_tag()) image_state = self.get_image_state(source_image_target, target_image_target, image_info_of_dependencies) image_info.image_state = image_state.name # TODO setter for image_state with self._image_info_target.open("w") as f: f.write(image_info.to_json())