First set of changes toward shared base images.
This commit is contained in:
parent
8794547593
commit
5742e6ea4e
3 changed files with 54 additions and 35 deletions
|
@ -186,7 +186,9 @@ class Image(BaseModel):
|
||||||
image_size = BigIntegerField(null=True)
|
image_size = BigIntegerField(null=True)
|
||||||
|
|
||||||
# '/' separated list of ancestory ids, e.g. /1/2/6/7/10/
|
# '/' separated list of ancestory ids, e.g. /1/2/6/7/10/
|
||||||
ancestors = CharField(index=True, default='/', max_length=64535)
|
ancestors = CharField(index=True, default='/', max_length=64535, null=True)
|
||||||
|
|
||||||
|
storage = ForeignKeyField(ImageStorage, index=True, null=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
database = db
|
database = db
|
||||||
|
@ -196,6 +198,18 @@ class Image(BaseModel):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class ImageStorage(BaseModel):
|
||||||
|
storage_uuid = CharField(default=uuid_generator)
|
||||||
|
checksum = CharField(null=True)
|
||||||
|
created = DateTimeField(null=True)
|
||||||
|
comment = TextField(null=True)
|
||||||
|
command = TextField(null=True)
|
||||||
|
image_size = BigIntegerField(null=True)
|
||||||
|
|
||||||
|
# '/' separated list of ancestory ids, e.g. /1/2/6/7/10/
|
||||||
|
ancestors = CharField(index=True, default='/', max_length=64535)
|
||||||
|
|
||||||
|
|
||||||
class RepositoryTag(BaseModel):
|
class RepositoryTag(BaseModel):
|
||||||
name = CharField()
|
name = CharField()
|
||||||
image = ForeignKeyField(Image)
|
image = ForeignKeyField(Image)
|
||||||
|
|
|
@ -772,10 +772,15 @@ def get_repository(namespace_name, repository_name):
|
||||||
|
|
||||||
|
|
||||||
def get_repo_image(namespace_name, repository_name, image_id):
|
def get_repo_image(namespace_name, repository_name, image_id):
|
||||||
joined = Image.select().join(Repository)
|
query = (Image
|
||||||
query = joined.where(Repository.name == repository_name,
|
.select()
|
||||||
|
.join(Repository)
|
||||||
|
.switch(Image)
|
||||||
|
.join(ImageStorage, JOIN_LEFT_OUTER)
|
||||||
|
.where(Repository.name == repository_name,
|
||||||
Repository.namespace == namespace_name,
|
Repository.namespace == namespace_name,
|
||||||
Image.docker_image_id == image_id).limit(1)
|
Image.docker_image_id == image_id)
|
||||||
|
.limit(1))
|
||||||
result = list(query)
|
result = list(query)
|
||||||
if not result:
|
if not result:
|
||||||
return None
|
return None
|
||||||
|
|
|
@ -13,6 +13,7 @@ class Storage(object):
|
||||||
# the code which uses Storage
|
# the code which uses Storage
|
||||||
repositories = 'repositories'
|
repositories = 'repositories'
|
||||||
images = 'images'
|
images = 'images'
|
||||||
|
shared_images = 'sharedimages'
|
||||||
# Set the IO buffer to 64kB
|
# Set the IO buffer to 64kB
|
||||||
buffer_size = 64 * 1024
|
buffer_size = 64 * 1024
|
||||||
|
|
||||||
|
@ -28,46 +29,45 @@ class Storage(object):
|
||||||
|
|
||||||
return tmpf, fn
|
return tmpf, fn
|
||||||
|
|
||||||
#FIXME(samalba): Move all path resolver in each module (out of the base)
|
def image_path(self, namespace, repository, image_id, storage_uuid):
|
||||||
def images_list_path(self, namespace, repository):
|
if storage_uuid:
|
||||||
return '{0}/{1}/{2}/_images_list'.format(self.repositories,
|
return '{0}/{1}/'.format(self.shared_images, storage_uuid)
|
||||||
namespace,
|
else:
|
||||||
repository)
|
|
||||||
|
|
||||||
def image_path(self, namespace, repository, image_id):
|
|
||||||
return '{0}/{1}/{2}/{3}/'.format(self.images, namespace, repository,
|
return '{0}/{1}/{2}/{3}/'.format(self.images, namespace, repository,
|
||||||
image_id)
|
image_id)
|
||||||
|
|
||||||
def image_json_path(self, namespace, repository, image_id):
|
def image_json_path(self, namespace, repository, image_id, storage_uuid):
|
||||||
return '{0}/{1}/{2}/{3}/json'.format(self.images, namespace,
|
base_path = self.image_path(namespace, repository, image_id, storage_uuid)
|
||||||
repository, image_id)
|
return '{0}/json'.format(base_path)
|
||||||
|
|
||||||
def image_mark_path(self, namespace, repository, image_id):
|
def image_mark_path(self, namespace, repository, image_id, storage_uuid):
|
||||||
return '{0}/{1}/{2}/{3}/_inprogress'.format(self.images, namespace,
|
base_path = self.image_path(namespace, repository, image_id, storage_uuid)
|
||||||
repository, image_id)
|
return '{0}/_inprogress'.format(base_path)
|
||||||
|
|
||||||
def image_checksum_path(self, namespace, repository, image_id):
|
def image_checksum_path(self, namespace, repository, image_id, storage_uuid):
|
||||||
return '{0}/{1}/{2}/{3}/_checksum'.format(self.images, namespace,
|
base_path = self.image_path(namespace, repository, image_id, storage_uuid)
|
||||||
repository, image_id)
|
return '{0}/_checksum'.format(base_path)
|
||||||
|
|
||||||
def image_layer_path(self, namespace, repository, image_id):
|
def image_layer_path(self, namespace, repository, image_id, storage_uuid):
|
||||||
return '{0}/{1}/{2}/{3}/layer'.format(self.images, namespace,
|
base_path = self.image_path(namespace, repository, image_id, storage_uuid)
|
||||||
repository, image_id)
|
return '{0}/layer'.format(base_path)
|
||||||
|
|
||||||
def image_ancestry_path(self, namespace, repository, image_id):
|
def image_ancestry_path(self, namespace, repository, image_id, storage_uuid):
|
||||||
return '{0}/{1}/{2}/{3}/ancestry'.format(self.images, namespace,
|
base_path = self.image_path(namespace, repository, image_id, storage_uuid)
|
||||||
repository, image_id)
|
return '{0}/ancestry'.format(base_path)
|
||||||
|
|
||||||
def repository_namespace_path(self, namespace, repository):
|
def repository_namespace_path(self, namespace, repository):
|
||||||
return '{0}/{1}/{2}/'.format(self.images, namespace, repository)
|
return '{0}/{1}/{2}/'.format(self.images, namespace, repository)
|
||||||
|
|
||||||
def image_file_trie_path(self, namespace, repository, image_id):
|
def image_file_trie_path(self, namespace, repository, image_id,
|
||||||
return '{0}/{1}/{2}/{3}/files.trie'.format(self.images, namespace,
|
storage_uuid):
|
||||||
repository, image_id)
|
base_path = self.image_path(namespace, repository, image_id, storage_uuid)
|
||||||
|
return '{0}/files.trie'.format(base_path)
|
||||||
|
|
||||||
def image_file_diffs_path(self, namespace, repository, image_id):
|
def image_file_diffs_path(self, namespace, repository, image_id,
|
||||||
return '{0}/{1}/{2}/{3}/diffs.json'.format(self.images, namespace,
|
storage_uuid):
|
||||||
repository, image_id)
|
base_path = self.image_path(namespace, repository, image_id, storage_uuid)
|
||||||
|
return '{0}/diffs.json'.format(base_path)
|
||||||
|
|
||||||
def get_direct_download_url(self, path, expires_in=60):
|
def get_direct_download_url(self, path, expires_in=60):
|
||||||
return None
|
return None
|
||||||
|
|
Reference in a new issue