Fix for mapping translations for existing images.
This commit is contained in:
parent
f8eb0c983f
commit
f339160ab9
2 changed files with 18 additions and 5 deletions
|
@ -884,16 +884,26 @@ def create_repository(namespace, name, creating_user, visibility='private'):
|
||||||
return repo
|
return repo
|
||||||
|
|
||||||
|
|
||||||
def __translate_ancestry(old_ancestry, translations):
|
def __translate_ancestry(old_ancestry, translations, existing_images):
|
||||||
if old_ancestry == '/':
|
if old_ancestry == '/':
|
||||||
return '/'
|
return '/'
|
||||||
|
|
||||||
|
def translate_id(old_id):
|
||||||
|
if old_id not in translations:
|
||||||
|
# Figure out which docker_image_id the old id refers to, then find a
|
||||||
|
# a local one
|
||||||
|
old = Image.select(Image.docker_image_id).where(Image.id == old_id).get()
|
||||||
|
translations[old_id] = existing_images[old.docker_image_id]
|
||||||
|
|
||||||
|
return translations[old_id]
|
||||||
|
|
||||||
old_ids = [int(id_str) for id_str in old_ancestry.split('/')[1:-1]]
|
old_ids = [int(id_str) for id_str in old_ancestry.split('/')[1:-1]]
|
||||||
new_ids = [str(translations[old_id]) for old_id in old_ids]
|
new_ids = [str(translate_id(old_id)) for old_id in old_ids]
|
||||||
return '/%s/' % '/'.join(new_ids)
|
return '/%s/' % '/'.join(new_ids)
|
||||||
|
|
||||||
|
|
||||||
def create_or_link_image(docker_image_id, repository, username, translations):
|
def create_or_link_image(docker_image_id, repository, username, translations,
|
||||||
|
existing_images):
|
||||||
with transaction_factory(db):
|
with transaction_factory(db):
|
||||||
query = (Image
|
query = (Image
|
||||||
.select(Image, ImageStorage)
|
.select(Image, ImageStorage)
|
||||||
|
@ -916,7 +926,7 @@ def create_or_link_image(docker_image_id, repository, username, translations):
|
||||||
logger.debug(msg, docker_image_id, to_copy.storage.uuid)
|
logger.debug(msg, docker_image_id, to_copy.storage.uuid)
|
||||||
|
|
||||||
new_image_ancestry = __translate_ancestry(to_copy.ancestors,
|
new_image_ancestry = __translate_ancestry(to_copy.ancestors,
|
||||||
translations)
|
translations, existing_images)
|
||||||
|
|
||||||
storage = to_copy.storage
|
storage = to_copy.storage
|
||||||
origin_image_id = to_copy.id
|
origin_image_id = to_copy.id
|
||||||
|
|
|
@ -187,15 +187,18 @@ def create_repository(namespace, repository):
|
||||||
added_images = OrderedDict([(desc['id'], desc)
|
added_images = OrderedDict([(desc['id'], desc)
|
||||||
for desc in image_descriptions])
|
for desc in image_descriptions])
|
||||||
new_repo_images = dict(added_images)
|
new_repo_images = dict(added_images)
|
||||||
|
|
||||||
|
existing_image_translations = {}
|
||||||
for existing in model.get_repository_images(namespace, repository):
|
for existing in model.get_repository_images(namespace, repository):
|
||||||
if existing.docker_image_id in new_repo_images:
|
if existing.docker_image_id in new_repo_images:
|
||||||
|
existing_image_translations[existing.docker_image_id] = existing.id
|
||||||
added_images.pop(existing.docker_image_id)
|
added_images.pop(existing.docker_image_id)
|
||||||
|
|
||||||
username = get_authenticated_user() and get_authenticated_user().username
|
username = get_authenticated_user() and get_authenticated_user().username
|
||||||
translations = {}
|
translations = {}
|
||||||
for image_description in added_images.values():
|
for image_description in added_images.values():
|
||||||
model.create_or_link_image(image_description['id'], repo, username,
|
model.create_or_link_image(image_description['id'], repo, username,
|
||||||
translations)
|
translations, existing_image_translations)
|
||||||
|
|
||||||
response = make_response('Created', 201)
|
response = make_response('Created', 201)
|
||||||
|
|
||||||
|
|
Reference in a new issue