Rename Image.image_id to Image.docker_image_id to reduce confusion.
This commit is contained in:
parent
4746f9c324
commit
96896b9067
7 changed files with 33 additions and 20 deletions
|
@ -86,7 +86,7 @@ class Image(BaseModel):
|
|||
# to be globally unique we can't treat them as such for permissions and
|
||||
# security reasons. So rather than Repository <-> Image being many to many
|
||||
# each image now belongs to exactly one repository.
|
||||
image_id = CharField()
|
||||
docker_image_id = CharField()
|
||||
checksum = CharField(null=True)
|
||||
created = DateTimeField(null=True)
|
||||
comment = TextField(null=True)
|
||||
|
@ -99,7 +99,7 @@ class Image(BaseModel):
|
|||
database = db
|
||||
indexes = (
|
||||
# we don't really want duplicates
|
||||
(('repository', 'image_id'), True),
|
||||
(('repository', 'docker_image_id'), True),
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -182,25 +182,26 @@ def create_repository(namespace, name, owner):
|
|||
return repo
|
||||
|
||||
|
||||
def create_image(image_id, repository):
|
||||
new_image = Image.create(image_id=image_id, repository=repository)
|
||||
def create_image(docker_image_id, repository):
|
||||
new_image = Image.create(docker_image_id=docker_image_id,
|
||||
repository=repository)
|
||||
return new_image
|
||||
|
||||
|
||||
def set_image_checksum(image_id, repository, checksum):
|
||||
fetched = Image.get(Image.image_id == image_id,
|
||||
def set_image_checksum(docker_image_id, repository, checksum):
|
||||
fetched = Image.get(Image.docker_image_id == docker_image_id,
|
||||
Image.repository == repository)
|
||||
fetched.checksum = checksum
|
||||
fetched.save()
|
||||
return fetched
|
||||
|
||||
|
||||
def set_image_metadata(image_id, namespace_name, repository_name,
|
||||
def set_image_metadata(docker_image_id, namespace_name, repository_name,
|
||||
created_date_str, comment, parent=None):
|
||||
joined = Image.select().join(Repository)
|
||||
image_list = list(joined.where(Repository.name == repository_name,
|
||||
Repository.namespace == namespace_name,
|
||||
Image.image_id == image_id))
|
||||
Image.docker_image_id == docker_image_id))
|
||||
|
||||
if not image_list:
|
||||
raise DataModelException('No image with specified id and repository')
|
||||
|
@ -232,9 +233,9 @@ def list_repository_tags(namespace_name, repository_name):
|
|||
|
||||
def get_tag_image(namespace_name, repository_name, tag_name):
|
||||
joined = Image.select().join(RepositoryTag).join(Repository)
|
||||
fetched = joined.where(Repository.name == repository_name,
|
||||
Repository.namespace == namespace_name,
|
||||
RepositoryTag.name == tag_name)
|
||||
fetched = list(joined.where(Repository.name == repository_name,
|
||||
Repository.namespace == namespace_name,
|
||||
RepositoryTag.name == tag_name))
|
||||
|
||||
if not fetched:
|
||||
raise DataModelException('Unable to find image for tag.')
|
||||
|
@ -242,8 +243,16 @@ def get_tag_image(namespace_name, repository_name, tag_name):
|
|||
return fetched[0]
|
||||
|
||||
|
||||
def get_image_by_id(image_id):
|
||||
return Image.get(Image.image_id == image_id)
|
||||
def get_image_by_id(namespace_name, repository_name, docker_image_id):
|
||||
joined = Image.select().join(Repository)
|
||||
fetched = list(joined.where(Repository.name == repository_name,
|
||||
Repository.namespace == namespace_name,
|
||||
Image.docker_image_id == docker_image_id))
|
||||
|
||||
if not fetched:
|
||||
raise DataModelException('Unable to find image for tag with repo.')
|
||||
|
||||
return fetched[0]
|
||||
|
||||
|
||||
def get_parent_images(image_obj):
|
||||
|
@ -259,10 +268,10 @@ def get_parent_images(image_obj):
|
|||
|
||||
|
||||
def create_or_update_tag(namespace_name, repository_name, tag_name,
|
||||
tag_image_id):
|
||||
tag_docker_image_id):
|
||||
repo = Repository.get(Repository.name == repository_name,
|
||||
Repository.namespace == namespace_name)
|
||||
image = Image.get(Image.image_id == tag_image_id)
|
||||
image = Image.get(Image.docker_image_id == tag_docker_image_id)
|
||||
|
||||
try:
|
||||
tag = RepositoryTag.get(RepositoryTag.repository == repo,
|
||||
|
|
|
@ -154,7 +154,7 @@ def delete_repository(namespace, repository):
|
|||
|
||||
def image_view(image):
|
||||
return {
|
||||
'id': image.image_id,
|
||||
'id': image.docker_image_id,
|
||||
'created': image.created,
|
||||
'comment': image.comment,
|
||||
}
|
||||
|
|
|
@ -123,8 +123,8 @@ def create_repository(namespace, repository):
|
|||
new_repo_images = {desc['id']: desc for desc in image_descriptions}
|
||||
added_images = dict(new_repo_images)
|
||||
for existing in model.get_repository_images(namespace, repository):
|
||||
if existing.image_id in new_repo_images:
|
||||
added_images.pop(existing.image_id)
|
||||
if existing.docker_image_id in new_repo_images:
|
||||
added_images.pop(existing.docker_image_id)
|
||||
else:
|
||||
existing.repositoryimage.delete()
|
||||
|
||||
|
@ -169,7 +169,7 @@ def get_repository_images(namespace, repository):
|
|||
all_images = []
|
||||
for image in model.get_repository_images(namespace, repository):
|
||||
new_image_view = {
|
||||
'id': image.image_id,
|
||||
'id': image.docker_image_id,
|
||||
'checksum': image.checksum,
|
||||
}
|
||||
all_images.append(new_image_view)
|
||||
|
|
|
@ -291,7 +291,7 @@ def put_image_json(namespace, repository, image_id):
|
|||
# on a failed push
|
||||
# save the metadata
|
||||
if parent_id:
|
||||
parent_obj = model.get_image_by_id(parent_id)
|
||||
parent_obj = model.get_image_by_id(namespace, repository, parent_id)
|
||||
else:
|
||||
parent_obj = None
|
||||
|
||||
|
|
4
initdb.py
Normal file
4
initdb.py
Normal file
|
@ -0,0 +1,4 @@
|
|||
from data.database import initialize_db
|
||||
|
||||
if __name__ == '__main__':
|
||||
initialize_db()
|
BIN
test.db
BIN
test.db
Binary file not shown.
Reference in a new issue