Properly handle the empty layer when pushing schema 2 manifests

Docker doesn't send us the contents of this layer, so we are forced to synthesize it ourselves
This commit is contained in:
Joseph Schorr 2018-11-25 16:16:59 +02:00
parent 947c029afa
commit 4985040d31
13 changed files with 173 additions and 25 deletions

View file

@ -1,4 +1,8 @@
import json
import tarfile
from cachetools import lru_cache
from io import BytesIO
from image.docker.interfaces import ContentRetriever
@ -22,3 +26,12 @@ class ContentRetrieverForTesting(ContentRetriever):
digests = {}
digests[digest] = padded_string
return ContentRetrieverForTesting(digests)
@lru_cache(maxsize=1)
def generate_empty_layer_data():
""" Generates the layer data for an "empty" layer. """
with BytesIO() as f:
tar_file = tarfile.open(fileobj=f, mode='w|gw')
tar_file.close()
return f.getvalue()