finish v1 registry refactor
This commit is contained in:
parent
c14437e54a
commit
8435c254c3
3 changed files with 65 additions and 42 deletions
|
@ -14,6 +14,7 @@ from auth.permissions import (ReadRepositoryPermission,
|
|||
ModifyRepositoryPermission)
|
||||
from auth.registry_jwt_auth import get_granted_username
|
||||
from data import model, database
|
||||
from data.model import v1
|
||||
from digest import checksums
|
||||
from endpoints.v1 import v1_bp
|
||||
from endpoints.decorators import anon_protect
|
||||
|
@ -29,7 +30,7 @@ logger = logging.getLogger(__name__)
|
|||
|
||||
def _finish_image(namespace, repository, image_id):
|
||||
# Checksum is ok, we remove the marker
|
||||
update_image_uploading(namespace, repository, image_id, False)
|
||||
v1.update_image_uploading(namespace, repository, image_id, False)
|
||||
|
||||
# Send a job to the work queue to replicate the image layer.
|
||||
# TODO(jzelinskie): make this not use imagestorage
|
||||
|
@ -41,7 +42,7 @@ def require_completion(f):
|
|||
@wraps(f)
|
||||
def wrapper(namespace, repository, *args, **kwargs):
|
||||
image_id = kwargs['image_id']
|
||||
if is_image_uploading(namespace, repository, image_id):
|
||||
if v1.is_image_uploading(namespace, repository, image_id):
|
||||
abort(400, 'Image %(image_id)s is being uploaded, retry later',
|
||||
issue='upload-in-progress', image_id=image_id)
|
||||
return f(namespace, repository, *args, **kwargs)
|
||||
|
@ -83,8 +84,8 @@ def head_image_layer(namespace, repository, image_id, headers):
|
|||
|
||||
logger.debug('Checking repo permissions')
|
||||
if permission.can() or model.repository.repository_is_public(namespace, repository):
|
||||
logger.debug('Looking up blob placement locations')
|
||||
locations = blob_placement_locations_docker_v1(namespace, repository, image_id)
|
||||
logger.debug('Looking up placement locations')
|
||||
locations = v1.placement_locations_docker_v1(namespace, repository, image_id)
|
||||
if locations is None:
|
||||
logger.debug('Could not find any blob placement locations')
|
||||
abort(404, 'Image %(image_id)s not found', issue='unknown-image',
|
||||
|
@ -116,8 +117,10 @@ def get_image_layer(namespace, repository, image_id, headers):
|
|||
|
||||
logger.debug('Checking repo permissions')
|
||||
if permission.can() or model.repository.repository_is_public(namespace, repository):
|
||||
logger.debug('Looking up blob placement locations and path')
|
||||
locations, path = blob_placement_locations_and_path_docker_v1(namespace, repository, image_id)
|
||||
logger.debug('Looking up placement locations and path')
|
||||
locations, path = v1.placement_locations_and_path_docker_v1(namespace,
|
||||
repository,
|
||||
image_id)
|
||||
if not locations or not path:
|
||||
abort(404, 'Image %(image_id)s not found', issue='unknown-image',
|
||||
image_id=image_id)
|
||||
|
@ -152,7 +155,7 @@ def put_image_layer(namespace, repository, image_id):
|
|||
abort(403)
|
||||
|
||||
logger.debug('Retrieving image')
|
||||
if storage_exists_docker_v1(namespace, repository, image_id):
|
||||
if v1.storage_exists(namespace, repository, image_id):
|
||||
exact_abort(409, 'Image already exists')
|
||||
|
||||
logger.debug('Storing layer data')
|
||||
|
@ -182,7 +185,7 @@ def put_image_layer(namespace, repository, image_id):
|
|||
sr.add_handler(piece_hasher.update)
|
||||
|
||||
# Add a handler which computes the checksum.
|
||||
v1_metadata = docker_v1_metadata(namespace, repository, image_id)
|
||||
v1_metadata = v1.docker_v1_metadata(namespace, repository, image_id)
|
||||
h, sum_hndlr = checksums.simple_checksum_handler(v1_metadata.compat_json)
|
||||
sr.add_handler(sum_hndlr)
|
||||
|
||||
|
@ -191,7 +194,7 @@ def put_image_layer(namespace, repository, image_id):
|
|||
sr.add_handler(content_sum_hndlr)
|
||||
|
||||
# Stream write the data to storage.
|
||||
locations, path = blob_placement_locations_and_path_docker_v1(namespace, repository, image_id)
|
||||
locations, path = v1.placement_locations_and_path_docker_v1(namespace, repository, image_id)
|
||||
with database.CloseForLongOperation(app.config):
|
||||
try:
|
||||
store.stream_write(locations, path, sr)
|
||||
|
@ -200,10 +203,11 @@ def put_image_layer(namespace, repository, image_id):
|
|||
abort(520, 'Image %(image_id)s could not be written. Please try again.', image_id=image_id)
|
||||
|
||||
# Save the size of the image.
|
||||
update_image_size(namespace, repository, image_id, size_info.compressed_size, size_info.uncompressed_size)
|
||||
v1.update_image_sizes(namespace, repository, image_id, size_info.compressed_size,
|
||||
size_info.uncompressed_size)
|
||||
|
||||
# Save the BitTorrent pieces.
|
||||
create_bittorrent_pieces(namespace, repository, image_id, piece_hasher.final_piece_hashes())
|
||||
v1.create_bittorrent_pieces(namespace, repository, image_id, piece_hasher.final_piece_hashes())
|
||||
|
||||
# Append the computed checksum.
|
||||
csums = []
|
||||
|
@ -217,7 +221,6 @@ def put_image_layer(namespace, repository, image_id):
|
|||
except (IOError, checksums.TarError) as exc:
|
||||
logger.debug('put_image_layer: Error when computing tarsum %s', exc)
|
||||
|
||||
v1_metadata = docker_v1_metadata(namespace, repository, image_id)
|
||||
if v1_metadata.checksum is None:
|
||||
# We don't have a checksum stored yet, that's fine skipping the check.
|
||||
# Not removing the mark though, image is not downloadable yet.
|
||||
|
@ -269,7 +272,7 @@ def put_image_checksum(namespace, repository, image_id):
|
|||
issue='missing-checksum-cookie', image_id=image_id)
|
||||
|
||||
logger.debug('Looking up repo image')
|
||||
v1_metadata = docker_v1_metadata(namespace_name, repo_name, image_id)
|
||||
v1_metadata = v1.docker_v1_metadata(namespace, repository, image_id)
|
||||
if not v1_metadata:
|
||||
abort(404, 'Image not found: %(image_id)s', issue='unknown-image', image_id=image_id)
|
||||
|
||||
|
@ -278,7 +281,7 @@ def put_image_checksum(namespace, repository, image_id):
|
|||
abort(404, 'Image not found: %(image_id)s', issue='unknown-image', image_id=image_id)
|
||||
|
||||
logger.debug('Marking image path')
|
||||
if not is_image_uploading(namespace, repository, image_id):
|
||||
if not v1.is_image_uploading(namespace, repository, image_id):
|
||||
abort(409, 'Cannot set checksum for image %(image_id)s',
|
||||
issue='image-write-error', image_id=image_id)
|
||||
|
||||
|
@ -289,7 +292,7 @@ def put_image_checksum(namespace, repository, image_id):
|
|||
if len(checksum_parts) != 2:
|
||||
abort(400, 'Invalid checksum format')
|
||||
|
||||
store_docker_v1_checksum(namespace, repository, image_id, checksum, content_checksum)
|
||||
v1.store_docker_v1_checksum(namespace, repository, image_id, checksum, content_checksum)
|
||||
|
||||
if checksum not in session.get('checksum', []):
|
||||
logger.debug('session checksums: %s', session.get('checksum', []))
|
||||
|
@ -317,12 +320,12 @@ def get_image_json(namespace, repository, image_id, headers):
|
|||
abort(403)
|
||||
|
||||
logger.debug('Looking up repo image')
|
||||
v1_metadata = docker_v1_metadata(namespace_name, repo_name, image_id)
|
||||
v1_metadata = v1.docker_v1_metadata(namespace, repository, image_id)
|
||||
if v1_metadata is None:
|
||||
flask_abort(404)
|
||||
|
||||
logger.debug('Looking up repo layer size')
|
||||
size = image_size(namespace_name, repo_name, image_id)
|
||||
size = v1.get_image_size(namespace, repository, image_id)
|
||||
if size is not None:
|
||||
# Note: X-Docker-Size is optional and we *can* end up with a NULL image_size,
|
||||
# so handle this case rather than failing.
|
||||
|
@ -345,7 +348,7 @@ def get_image_ancestry(namespace, repository, image_id, headers):
|
|||
if not permission.can() and not model.repository.repository_is_public(namespace, repository):
|
||||
abort(403)
|
||||
|
||||
ancestry_docker_ids = image_ancestry(namespace, repository, image_id)
|
||||
ancestry_docker_ids = v1.image_ancestry(namespace, repository, image_id)
|
||||
if ancestry_docker_ids is None:
|
||||
abort(404, 'Image %(image_id)s not found', issue='unknown-image', image_id=image_id)
|
||||
|
||||
|
@ -386,36 +389,36 @@ def put_image_json(namespace, repository, image_id):
|
|||
|
||||
logger.debug('Looking up repo image')
|
||||
|
||||
if not repository_exists(namespace, repository):
|
||||
if not v1.repository_exists(namespace, repository):
|
||||
abort(404, 'Repository does not exist: %(namespace)s/%(repository)s', issue='no-repo',
|
||||
namespace=namespace, repository=repository)
|
||||
|
||||
v1_metadata = docker_v1_metadata(namespace, repository, image_id)
|
||||
v1_metadata = v1.docker_v1_metadata(namespace, repository, image_id)
|
||||
if v1_metadata is None:
|
||||
username = get_authenticated_user() and get_authenticated_user().username
|
||||
if not username:
|
||||
username = get_granted_username()
|
||||
|
||||
logger.debug('Image not found, creating or linking image with initiating user context: %s', username)
|
||||
create_or_link_image(username, repository, image_id, store.preferred_locations[0])
|
||||
v1_metadata = docker_v1_metadata(namespace, repository, image_id)
|
||||
v1.create_or_link_image(username, repository, image_id, store.preferred_locations[0])
|
||||
v1_metadata = v1.docker_v1_metadata(namespace, repository, image_id)
|
||||
|
||||
# Create a temporary tag to prevent this image from getting garbage collected while the push
|
||||
# is in progress.
|
||||
create_temp_hidden_tag(namespace_name, repo_name, app.config['PUSH_TEMP_TAG_EXPIRATION_SEC'])
|
||||
v1.create_temp_hidden_tag(namespace, repository, app.config['PUSH_TEMP_TAG_EXPIRATION_SEC'])
|
||||
|
||||
parent_id = data.get('parent', None)
|
||||
if parent_id:
|
||||
logger.debug('Looking up parent image')
|
||||
if docker_v1_metadata(namespace, repository, parent_id) is None:
|
||||
if v1.docker_v1_metadata(namespace, repository, parent_id) is None:
|
||||
abort(400, 'Image %(image_id)s depends on non existing parent image %(parent_id)s',
|
||||
issue='invalid-request', image_id=image_id, parent_id=parent_id)
|
||||
|
||||
logger.debug('Checking if image already exists')
|
||||
if v1_metadata and not is_image_uploading(namespace, repository, image_id):
|
||||
if v1_metadata and not v1.is_image_uploading(namespace, repository, image_id):
|
||||
exact_abort(409, 'Image already exists')
|
||||
|
||||
update_image_uploading(namespace, repository, image_id, True)
|
||||
v1.update_image_uploading(namespace, repository, image_id, True)
|
||||
|
||||
# If we reach that point, it means that this is a new image or a retry
|
||||
# on a failed push, save the metadata
|
||||
|
@ -423,8 +426,7 @@ def put_image_json(namespace, repository, image_id):
|
|||
command = json.dumps(command_list) if command_list else None
|
||||
|
||||
logger.debug('Setting image metadata')
|
||||
update_docker_v1_metadata(namespace, repository, image_id, data.get('created'),
|
||||
data.get('comment'), command, uploaded_metadata, parent_image)
|
||||
v1.update_docker_v1_metadata(namespace, repository, image_id, data.get('created'),
|
||||
data.get('comment'), command, uploaded_metadata, parent_id)
|
||||
|
||||
return make_response('true', 200)
|
||||
|
||||
|
|
Reference in a new issue