48 lines
1.6 KiB
Python
48 lines
1.6 KiB
Python
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')
|