Add code for resumable downloads from S3
This commit is contained in:
parent
d851feef6e
commit
0d89fd7f26
3 changed files with 17 additions and 2 deletions
|
@ -101,6 +101,13 @@ def get_image_layer(namespace, repository, image_id, headers):
|
||||||
profile.debug('Looking up repo image')
|
profile.debug('Looking up repo image')
|
||||||
repo_image = model.get_repo_image(namespace, repository, image_id)
|
repo_image = model.get_repo_image(namespace, repository, image_id)
|
||||||
|
|
||||||
|
# Add the Accept-Ranges header if the storage engine supports resumable
|
||||||
|
# downloads.
|
||||||
|
extra_headers = {}
|
||||||
|
|
||||||
|
if store.get_supports_resumable_downloads():
|
||||||
|
extra_headers['Accept-Ranges'] = 'bytes';
|
||||||
|
|
||||||
profile.debug('Looking up the layer path')
|
profile.debug('Looking up the layer path')
|
||||||
try:
|
try:
|
||||||
path = store.image_layer_path(repo_image.storage.uuid)
|
path = store.image_layer_path(repo_image.storage.uuid)
|
||||||
|
@ -110,10 +117,12 @@ def get_image_layer(namespace, repository, image_id, headers):
|
||||||
|
|
||||||
if direct_download_url:
|
if direct_download_url:
|
||||||
profile.debug('Returning direct download URL')
|
profile.debug('Returning direct download URL')
|
||||||
return redirect(direct_download_url)
|
resp = redirect(direct_download_url)
|
||||||
|
resp.headers = dict(headers, **extra_headers)
|
||||||
|
return resp
|
||||||
|
|
||||||
profile.debug('Streaming layer data')
|
profile.debug('Streaming layer data')
|
||||||
return Response(store.stream_read(repo_image.storage.locations, path), headers=headers)
|
return Response(store.stream_read(repo_image.storage.locations, path), headers=dict(headers, **extra_headers))
|
||||||
except (IOError, AttributeError):
|
except (IOError, AttributeError):
|
||||||
profile.debug('Image not found')
|
profile.debug('Image not found')
|
||||||
abort(404, 'Image %(image_id)s not found', issue='unknown-image',
|
abort(404, 'Image %(image_id)s not found', issue='unknown-image',
|
||||||
|
|
|
@ -57,6 +57,9 @@ class BaseStorage(StoragePaths):
|
||||||
def get_direct_download_url(self, path, expires_in=60):
|
def get_direct_download_url(self, path, expires_in=60):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def get_supports_resumable_downloads(self):
|
||||||
|
return False
|
||||||
|
|
||||||
def get_content(self, path):
|
def get_content(self, path):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|
|
@ -83,6 +83,9 @@ class S3Storage(BaseStorage):
|
||||||
key.set_contents_from_string(content, encrypt_key=True)
|
key.set_contents_from_string(content, encrypt_key=True)
|
||||||
return path
|
return path
|
||||||
|
|
||||||
|
def get_supports_resumable_downloads(self):
|
||||||
|
return True
|
||||||
|
|
||||||
def get_direct_download_url(self, path, expires_in=60):
|
def get_direct_download_url(self, path, expires_in=60):
|
||||||
self._initialize_s3()
|
self._initialize_s3()
|
||||||
path = self._init_path(path)
|
path = self._init_path(path)
|
||||||
|
|
Reference in a new issue