From c3cb1dfa8788a920921fbd2ace2ce8aa2e59292a Mon Sep 17 00:00:00 2001 From: yackob03 Date: Thu, 6 Feb 2014 15:34:19 -0500 Subject: [PATCH] Add a tool to fix the images that were wrong before c8f0780 fixed tags. --- tools/audittagimages.py | 48 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 tools/audittagimages.py diff --git a/tools/audittagimages.py b/tools/audittagimages.py new file mode 100644 index 000000000..e521a78c3 --- /dev/null +++ b/tools/audittagimages.py @@ -0,0 +1,48 @@ +from data.database import Image, RepositoryTag, Repository + +from app import app + + +store = app.config['STORAGE'] + + +tag_query = (RepositoryTag + .select(RepositoryTag, Image, Repository) + .join(Repository) + .switch(RepositoryTag) + .join(Image)) + +for tag in tag_query: + if tag.image.repository.id != tag.repository.id: + print('Repository tag pointing to external image: %s/%s:%s' % + (tag.repository.namespace, tag.repository.name, tag.name)) + + proper_image_layer_path = store.image_layer_path(tag.repository.namespace, + tag.repository.name, + tag.image.docker_image_id) + + has_storage = False + if store.exists(proper_image_layer_path): + print('Storage already in place: %s' % proper_image_layer_path) + has_storage = True + else: + print('Storage missing: %s' % proper_image_layer_path) + + has_db_entry = False + new_image = None + try: + new_image = Image.get(Image.docker_image_id == tag.image.docker_image_id, + Image.repository == tag.repository) + has_db_entry = True + print('DB image in place: %s invalid image id: %s' % (new_image.id, + tag.image.id)) + except Image.DoesNotExist: + print('DB image missing: %s' % tag.image.docker_image_id) + + if has_storage and has_db_entry: + print('Switching tag to proper image %s/%s/%s -> %s' % + (tag.repository.namespace, tag.repository.name, tag.name, + new_image.id)) + tag.image = new_image + tag.save() + print('Done')