Add code for saving and displaying the size of images

This commit is contained in:
Joseph Schorr 2014-01-03 16:32:00 -05:00
parent 8e4bbdf1dd
commit 0a63690e25
7 changed files with 42 additions and 0 deletions

View file

@ -168,6 +168,7 @@ class Image(BaseModel):
created = DateTimeField(null=True)
comment = TextField(null=True)
repository = ForeignKeyField(Repository)
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)

View file

@ -706,6 +706,21 @@ def set_image_checksum(docker_image_id, repository, checksum):
return fetched
def set_image_size(docker_image_id, namespace_name, repository_name, image_size):
joined = Image.select().join(Repository)
image_list = list(joined.where(Repository.name == repository_name,
Repository.namespace == namespace_name,
Image.docker_image_id == docker_image_id))
if not image_list:
raise DataModelException('No image with specified id and repository')
fetched = image_list[0]
fetched.image_size = image_size
fetched.save()
return fetched
def set_image_metadata(docker_image_id, namespace_name, repository_name,
created_date_str, comment, parent=None):
joined = Image.select().join(Repository)

View file

@ -887,6 +887,7 @@ def image_view(image):
'comment': image.comment,
'ancestors': image.ancestors,
'dbid': image.id,
'size': image.image_size,
}

View file

@ -125,7 +125,9 @@ def put_image_layer(namespace, repository, image_id):
sr.add_handler(sum_hndlr)
store.stream_write(layer_path, sr)
csums.append('sha256:{0}'.format(h.hexdigest()))
image_size = None
try:
image_size = tmp.tell()
tmp.seek(0)
csums.append(checksums.compute_tarsum(tmp, json_data))
tmp.close()
@ -148,6 +150,10 @@ def put_image_layer(namespace, repository, image_id):
# Checksum is ok, we remove the marker
store.remove(mark_path)
# Save the size of the image if we know it.
if image_size is not None:
model.set_image_size(image_id, namespace, repository, image_size)
# The layer is ready for download, send a job to the work queue to
# process it.
logger.debug('Queing diffs job for image: %s' % image_id)

View file

@ -3,6 +3,7 @@ import string
import shutil
import os
import hashlib
import random
from datetime import datetime, timedelta
from flask import url_for
@ -55,6 +56,8 @@ def __create_subtree(repo, structure, parent):
repo.name, str(creation_time),
'no comment', parent)
model.set_image_size(docker_image_id, repo.namespace, repo.name, random.randrange(1, 1024 * 1024 * 1024))
# Populate the diff file
diff_path = store.image_file_diffs_path(repo.namespace, repo.name,
docker_image_id)

View file

@ -1025,6 +1025,17 @@ quayApp.directive('dockerAuthDialog', function () {
});
quayApp.filter('bytes', function() {
return function(bytes, precision) {
if (!bytes || isNaN(parseFloat(bytes)) || !isFinite(bytes)) return '';
if (typeof precision === 'undefined') precision = 1;
var units = ['bytes', 'kB', 'MB', 'GB', 'TB', 'PB'],
number = Math.floor(Math.log(bytes) / Math.log(1024));
return (bytes / Math.pow(1024, Math.floor(number))).toFixed(precision) + ' ' + units[number];
}
});
quayApp.filter('visibleLogFilter', function () {
return function (logs, allowed) {
if (!allowed) {

View file

@ -124,6 +124,11 @@ sudo docker push quay.io/{{repo.namespace}}/{{repo.name}}</pre>
<dd am-time-ago="parseDate(currentImage.created)"></dd>
<dt>Image ID</dt>
<dd><a href="{{'/repository/' + repo.namespace + '/' + repo.name + '/image/' + currentImage.id}}">{{ currentImage.id }}</a></dd>
<dt>Compressed Image Size</dt>
<dd><span class="context-tooltip"
title="The amount of data sent between Docker and Quay.io when pushing/pulling"
bs-tooltip="tooltip.title" data-container="body">{{ currentImage.size | bytes }}</span>
</dd>
</dl>
<!-- Image changes loading -->