def run_task(self):
     image_info_of_dependencies = self.get_values_from_futures(
         self.dependencies_futures)
     if image_info_of_dependencies is None:
         image_info_of_dependencies = dict()
     _build_context_hasher = BuildContextHasher(self.logger,
                                                self.image_description)
     image_hash = _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_value=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
     self.return_object(image_info)
 def save_image(self, image_info: ImageInfo, tag_for_save: str,
                save_file_path: pathlib.Path):
     self.remove_save_file_if_necassary(save_file_path)
     with self._get_docker_client() as docker_client:
         image = docker_client.images.get(
             image_info.get_target_complete_name())
         generator = image.save(named=tag_for_save)
         self.write_image_to_file(save_file_path, image_info, generator)
Beispiel #3
0
 def _handle_output(self, output_generator, image_info: ImageInfo):
     log_file_path = Path(self.get_log_path(), "docker-build.log")
     with BuildLogHandler(log_file_path, self.logger, image_info) as log_handler:
         still_running_logger = StillRunningLogger(
             self.logger, "build image %s" % image_info.get_target_complete_name())
         for log_line in output_generator:
             still_running_logger.log()
             log_handler.handle_log_lines(log_line)
 def _handle_output(self, output_generator, image_info: ImageInfo):
     log_file_path = self.get_log_path().joinpath(
         "pull_docker_db_image.log")
     with PullLogHandler(log_file_path, self.logger,
                         image_info) as log_hanlder:
         still_running_logger = StillRunningLogger(
             self.logger,
             "pull image %s" % image_info.get_source_complete_name())
         for log_line in output_generator:
             still_running_logger.log()
             log_hanlder.handle_log_lines(log_line)
Beispiel #5
0
 def build(self, image_info: ImageInfo):
     if image_info.image_state == ImageState.NEEDS_TO_BE_BUILD.name:
         task = self.create_child_task(DockerBuildImageTask,
                                       image_name=self.image_name,
                                       image_info=image_info)
         yield from self.run_dependencies(task)
         image_info.image_state = ImageState.WAS_BUILD.name  # TODO clone and change
         return image_info
     elif image_info.image_state == ImageState.CAN_BE_LOADED.name:
         task = self.create_child_task(DockerLoadImageTask,
                                       image_name=self.image_name,
                                       image_info=image_info)
         yield from self.run_dependencies(task)
         image_info.image_state = ImageState.WAS_LOADED.name
         return image_info
     elif image_info.image_state == ImageState.REMOTE_AVAILABLE.name:
         task = self.create_child_task(DockerPullImageTask,
                                       image_name=self.image_name,
                                       image_info=image_info)
         yield from self.run_dependencies(task)
         image_info.image_state = ImageState.WAS_PULLED.name
         return image_info
     elif image_info.image_state == ImageState.TARGET_LOCALLY_AVAILABLE.name:
         image_info.image_state = ImageState.USED_LOCAL.name
         return image_info
     elif image_info.image_state == ImageState.SOURCE_LOCALLY_AVAILABLE.name:
         image_info.image_state = ImageState.WAS_TAGED.name
         self.rename_source_image_to_target_image(image_info)
         return image_info
     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 write_image_to_file(self, save_file_path: pathlib.Path,
                         image_info: ImageInfo,
                         output_generator: Generator):
     self.logger.info(
         f"Saving image {image_info.get_target_complete_name()} to file {save_file_path}"
     )
     with save_file_path.open("wb") as file:
         still_running_logger = StillRunningLogger(
             self.logger,
             "save image %s" % image_info.get_target_complete_name())
         for chunk in output_generator:
             still_running_logger.log()
             file.write(chunk)
 def _pull_docker_db_images_if_necassary(self):
     image_name = "exasol/docker-db"
     docker_db_image_info = ImageInfo(
         target_repository_name=image_name,
         source_repository_name=image_name,
         source_tag=self.docker_db_image_version,
         target_tag=self.docker_db_image_version,
         hash_value="",
         commit="",
         image_description=None)
     with self._get_docker_client() as docker_client:
         try:
             docker_client.images.get(
                 docker_db_image_info.get_source_complete_name())
         except docker.errors.ImageNotFound as e:
             self.logger.info(
                 "Pulling docker-db image %s",
                 docker_db_image_info.get_source_complete_name())
             output_generator = docker_client.api.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
 def get_tag_for_save(self, image_info: ImageInfo):
     tag_for_save = re.sub(DOCKER_HUB_REGISTRY_URL_REGEX, "",
                           image_info.get_target_complete_name())
     return tag_for_save