parent
8d05d40cf7
commit
762cd56e64
10 changed files with 155 additions and 112 deletions
|
@ -1,7 +1,6 @@
|
|||
import logging
|
||||
import json
|
||||
import hashlib
|
||||
import uuid
|
||||
|
||||
from flask import redirect, Blueprint, abort, send_file, make_response
|
||||
|
||||
|
@ -86,7 +85,7 @@ def _write_synthetic_image_to_storage(verb, linked_storage_uuid, linked_location
|
|||
logger.debug('Exception when building %s image %s: %s', verb, linked_storage_uuid, ex)
|
||||
|
||||
with database.UseThenDisconnect(app.config):
|
||||
model.storage.delete_derived_storage_by_uuid(linked_storage_uuid)
|
||||
model.image.delete_derived_storage_by_uuid(linked_storage_uuid)
|
||||
|
||||
queue_file.add_exception_handler(handle_exception)
|
||||
|
||||
|
@ -137,10 +136,10 @@ def _repo_verb_signature(namespace, repository, tag, verb, checker=None, **kwarg
|
|||
# Verify that the image exists and that we have access to it.
|
||||
store = Storage(app)
|
||||
result = _verify_repo_verb(store, namespace, repository, tag, verb, checker)
|
||||
(repo_image, tag_image, image_json) = result
|
||||
(repo_image, _, _) = result
|
||||
|
||||
# Lookup the derived image storage for the verb.
|
||||
derived = model.storage.find_derived_storage(repo_image.storage, verb)
|
||||
derived = model.image.find_derived_storage_for_image(repo_image, verb)
|
||||
if derived is None or derived.uploading:
|
||||
return make_response('', 202)
|
||||
|
||||
|
@ -166,27 +165,26 @@ def _repo_verb(namespace, repository, tag, verb, formatter, sign=False, checker=
|
|||
# Log the action.
|
||||
track_and_log('repo_verb', repo_image.repository, tag=tag, verb=verb, **kwargs)
|
||||
|
||||
# Lookup/create the derived image storage for the verb.
|
||||
#derived = model.storage.find_or_create_derived_storage(repo_image.storage, verb,
|
||||
# store.preferred_locations[0])
|
||||
# Lookup/create the derived image storage for the verb and repo image.
|
||||
derived = model.image.find_or_create_derived_storage(repo_image, verb,
|
||||
store.preferred_locations[0])
|
||||
|
||||
#if not derived.uploading:
|
||||
# logger.debug('Derived %s image %s exists in storage', verb, derived.uuid)
|
||||
# derived_layer_path = model.storage.get_layer_path(derived)
|
||||
# download_url = store.get_direct_download_url(derived.locations, derived_layer_path)
|
||||
# if download_url:
|
||||
# logger.debug('Redirecting to download URL for derived %s image %s', verb, derived.uuid)
|
||||
# return redirect(download_url)
|
||||
if not derived.uploading:
|
||||
logger.debug('Derived %s image %s exists in storage', verb, derived.uuid)
|
||||
derived_layer_path = model.storage.get_layer_path(derived)
|
||||
download_url = store.get_direct_download_url(derived.locations, derived_layer_path)
|
||||
if download_url:
|
||||
logger.debug('Redirecting to download URL for derived %s image %s', verb, derived.uuid)
|
||||
return redirect(download_url)
|
||||
|
||||
# # Close the database handle here for this process before we send the long download.
|
||||
# database.close_db_filter(None)
|
||||
# Close the database handle here for this process before we send the long download.
|
||||
database.close_db_filter(None)
|
||||
|
||||
# logger.debug('Sending cached derived %s image %s', verb, derived.uuid)
|
||||
# return send_file(store.stream_read_file(derived.locations, derived_layer_path))
|
||||
logger.debug('Sending cached derived %s image %s', verb, derived.uuid)
|
||||
return send_file(store.stream_read_file(derived.locations, derived_layer_path))
|
||||
|
||||
derived_uuid = str(uuid.uuid4())
|
||||
|
||||
logger.debug('Building and returning derived %s image %s', verb, derived_uuid)
|
||||
logger.debug('Building and returning derived %s image %s', verb, derived.uuid)
|
||||
|
||||
# Load the image's JSON layer.
|
||||
if not image_json:
|
||||
|
@ -207,23 +205,23 @@ def _repo_verb(namespace, repository, tag, verb, formatter, sign=False, checker=
|
|||
args, finished=_cleanup)
|
||||
|
||||
client_queue_file = QueueFile(queue_process.create_queue(), 'client')
|
||||
#storage_queue_file = QueueFile(queue_process.create_queue(), 'storage')
|
||||
storage_queue_file = QueueFile(queue_process.create_queue(), 'storage')
|
||||
|
||||
# If signing is required, add a QueueFile for signing the image as we stream it out.
|
||||
#signing_queue_file = None
|
||||
#if sign and signer.name:
|
||||
# signing_queue_file = QueueFile(queue_process.create_queue(), 'signing')
|
||||
signing_queue_file = None
|
||||
if sign and signer.name:
|
||||
signing_queue_file = QueueFile(queue_process.create_queue(), 'signing')
|
||||
|
||||
# Start building.
|
||||
queue_process.run()
|
||||
|
||||
# Start the storage saving.
|
||||
#storage_args = (verb, derived_uuid, derived.locations, storage_queue_file)
|
||||
#QueueProcess.run_process(_write_synthetic_image_to_storage, storage_args, finished=_cleanup)
|
||||
storage_args = (verb, derived.uuid, derived.locations, storage_queue_file)
|
||||
QueueProcess.run_process(_write_synthetic_image_to_storage, storage_args, finished=_cleanup)
|
||||
|
||||
#if sign and signer.name:
|
||||
# signing_args = (verb, derived_uuid, signing_queue_file)
|
||||
# QueueProcess.run_process(_sign_sythentic_image, signing_args, finished=_cleanup)
|
||||
if sign and signer.name:
|
||||
signing_args = (verb, derived.uuid, signing_queue_file)
|
||||
QueueProcess.run_process(_sign_sythentic_image, signing_args, finished=_cleanup)
|
||||
|
||||
# Close the database handle here for this process before we send the long download.
|
||||
database.close_db_filter(None)
|
||||
|
|
Reference in a new issue