def run(self): metadata = { "path": os.path.join(self.workflow.source.workdir, EXPORTED_SQUASHED_IMAGE_NAME) } if self.dont_load: # squash the image, don't load it back to docker Squash(log=self.log, image=self.image, from_layer=self.from_layer, tag=self.tag, output_path=metadata["path"], load_image=False).run() else: # squash the image and output both tarfile and Docker engine image new_id = Squash(log=self.log, image=self.image, from_layer=self.from_layer, tag=self.tag, output_path=metadata["path"], load_image=True).run() self.workflow.builder.image_id = new_id metadata.update(get_exported_image_metadata(metadata["path"])) self.workflow.exported_image_sequence.append(metadata) if self.remove_former_image: self.tasker.remove_image(self.image)
def test_exit_if_no_output_path_provided_and_loading_is_disabled_too(self): squash = Squash(self.log, 'image', self.docker_client, load_image=False, output_path=None) squash.run() self.log.warn.assert_called_with( "No output path specified and loading into Docker is not selected either; squashed image would not accessible, proceeding with squashing doesn't make sense" )
def run(self): if self.dont_load: metadata = {} self.workflow.exported_image_sequence.append(metadata) metadata["path"] = \ os.path.join(self.workflow.source.workdir, EXPORTED_SQUASHED_IMAGE_NAME) # squash the image, don't load it back to docker Squash(log=self.log, image=self.image, from_layer=self.from_layer, tag=self.tag, output_path=metadata["path"]).run() metadata.update(get_exported_image_metadata(metadata["path"])) else: # squash the image and load it back to engine new_id = Squash(log=self.log, image=self.image, from_layer=self.from_layer, tag=self.tag).run() self.workflow.builder.image_id = new_id if self.remove_former_image: self.tasker.remove_image(self.image)
def __enter__(self): from_layer = self.docker.history( self.image.tag)[self.number_of_layers]['Id'] squash = Squash(self.log, self.image.tag, self.docker, tag=self.tag, from_layer=from_layer, output_path=self.output_path) self.image_id = squash.run() if not self.output_path: self.squashed_layer = self._squashed_layer() self.layers = [o['Id'] for o in self.docker.history(self.tag)] self.metadata = self.docker.inspect_image(self.tag) return self
def setUp(self): self.docker_client = mock.Mock() self.log = mock.Mock() self.image = "whatever" self.squash = Squash(self.log, self.image, self.docker_client)
def test_handle_case_when_no_image_is_provided(self): squash = Squash(self.log, None, self.docker_client) with self.assertRaises(SquashError) as cm: squash.run() self.assertEquals(str(cm.exception), "Image is not provided")
def test_handle_case_when_no_image_is_provided(self): squash = Squash(self.log, None, self.docker_client) with self.assertRaises(SystemExit) as cm: squash.run() self.assertEqual(cm.exception.code, 1) self.log.error.assert_called_with("Image is not provided, exiting")