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 _handle_output(self, output_generator, image_info: ImageInfo): log_file_path = self.prepate_log_file_path(image_info) with PullLogHandler(log_file_path, self.logger, self.__repr__(), image_info) as log_hanlder: still_running_logger = StillRunningLogger( self.logger, self.__repr__(), "pull image %s" % image_info.get_source_complete_name()) for log_line in output_generator: still_running_logger.log() log_hanlder.handle_log_line(log_line)
def pull_docker_db_images_if_necassary(self): image_name = "exasol/docker-db" image_tag = "6.0.12-d1" docker_db_image_info = ImageInfo(target_repository_name=image_name, source_repository_name=image_name, source_tag=image_tag, target_tag=image_tag, hash="", commit="", image_description=None) try: self._client.images.get( docker_db_image_info.get_source_complete_name()) except docker.errors.ImageNotFound as e: self.logger.info("Task %s: Pulling docker-db image %s", self.__repr__(), docker_db_image_info.get_source_complete_name()) output_generator = self._low_level_client.pull( docker_db_image_info.source_repository_name, tag=docker_db_image_info.source_tag, stream=True) self._handle_output(output_generator, docker_db_image_info) return docker_db_image_info