docker: save tarballs of layers with diff id

parent 6d884603
......@@ -368,13 +368,11 @@ async def wait_event(emitter, event_name, timeout=None):
emitter.once(event_name, _handler)
return await asyncio.wait_for(future, timeout)
def gunzip(path: str) -> None:
def gunzip(input_path: str, output_path: str) -> None:
"""Decompress .gz file"""
with gzip.open(path, 'rb') as gzfile:
with gzip.open(input_path, 'rb') as gzfile:
data = gzfile.read()
path = path.rstrip('.gz')
with open(path, "wb") as tarf:
with open(output_path, "wb") as tarf:
tarf.write(data)
def clean_keys(dict_: dict, keys: list) -> None:
......
......@@ -188,6 +188,7 @@ class DockerLayer(BaseModel, CommonDockerObjectFunctions):
local_image_refs = JSONStringField(default=list)
cache_path = CharField(null=True, default=None) # .tar file in cache dir
cache_gz_path = CharField(null=True, default=None) # .tar.gz file in cache dir
docker_path = CharField(null=True) # layer's directory under /var/lib/docker
def set_local_image_refs(self, image_id: str):
......
......@@ -131,7 +131,7 @@ class DockerPackaging(BasePackagePlugin): # pylint: disable=too-many-instance-a
self.log.debug("new layer from remote %s", str(layer))
def save_local_paths(self, layer: DockerLayer):
"""Update 'cache_path' and 'docker_path' with paths of local node"""
"""Update 'cache_path' and 'cache_gz_path' and 'docker_path' with paths of local node"""
try:
docker_path = self.util.layerdir_path.format(
layer_dir_name=self.util.get_cache_id_from_chain_id(layer.chain_id))
......@@ -143,12 +143,19 @@ class DockerPackaging(BasePackagePlugin): # pylint: disable=too-many-instance-a
except FileNotFoundError:
layer.docker_path = None
cache_path = self.util.get_layer_tar_file(layer.diff_id)
if os.path.exists(cache_path):
layer.cache_path = cache_path
else:
layer.cache_path = None
if layer.digest:
cache_path = os.path.join(self.util.layer_cache_path, del_idpref(layer.digest) + '.tar')
if os.path.exists(cache_path):
layer.cache_path = cache_path
cache_gz_path = self.util.get_layer_gz_file(layer.digest)
if os.path.exists(cache_gz_path):
layer.cache_gz_path = cache_gz_path
else:
layer.cache_path = None
layer.cache_gz_path = None
async def fetch_images_from_peer(self, peer: Peer):
"""fetch image list from the node and update local db"""
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment