Fixed bug when image doesn't finish building.

This commit is contained in:
Sean Li 2014-10-09 11:25:47 -07:00
Родитель 0f07fc9b51
Коммит 0f6b7746aa
9 изменённых файлов: 62 добавлений и 28 удалений

2
.gitignore поставляемый
Просмотреть файл

@ -10,7 +10,7 @@ bin
# Resources
resources/cache
resources/base-images.tar.gz
resources/base-images-*.tar.gz
resources/virtualbox-*.pkg
resources/boot2docker*
resources/node-webkit

Просмотреть файл

@ -169,6 +169,13 @@ var convertVolumeObjToArray = function (obj) {
};
Docker.getImageData = function (imageId, callback) {
docker.listImages({all: false}, function (err, images) {
if (err) {
callback(err, null);
} else {
var dockerImage = _.find(images, function (image) {
return image.Id === imageId;
});
var image = docker.getImage(imageId);
image.inspect(function (err, data) {
if (err) {
@ -180,7 +187,19 @@ Docker.getImageData = function (imageId, callback) {
if (data.ContainerConfig && data.ContainerConfig.Volumes) {
data.ContainerConfig.Volumes = convertVolumeObjToArray(data.ContainerConfig.Volumes);
}
/*console.log('Image ID');
console.log(imageId);
console.log('Raw Docker Data:');
console.log(dockerImage);
console.log('Inspected Data:');
console.log(data);*/
if (!dockerImage) {
callback(null, data);
} else {
callback(null, _.extend(dockerImage, data));
}
}
});
}
});
};
@ -196,8 +215,7 @@ Docker.listImages = function (callback) {
if (err) {
cb(err, null);
} else {
var mergedData = _.extend(image, data);
cb(null, mergedData);
cb(null, data);
}
});
}
@ -273,7 +291,7 @@ Docker.resolveDefaultImages = function () {
image.inspect(function (err) {
if (err) {
if (err.reason === 'no such image') {
docker.loadImage(path.join(Util.getBinDir(), 'base-images.tar.gz'), {}, function (err) {
docker.loadImage(path.join(Util.getBinDir(), Docker.DEFAULT_IMAGES_FILENAME), {}, function (err) {
if (err) {
innerCallback(err);
return;

Просмотреть файл

@ -44,9 +44,13 @@ ImageUtil.getMetaData = function (directory) {
if (!kiteJSON.name) {
kiteJSON.name = _.last(directory.split(path.sep));
}
if (!kiteJSON.version) {
kiteJSON.version = 'latest';
}
} else {
kiteJSON = {
name: _.last(directory.split(path.sep))
name: _.last(directory.split(path.sep)),
version: 'latest'
};
}
return kiteJSON;
@ -222,6 +226,7 @@ ImageUtil.build = function (image, callback) {
}
var imageData = null;
Docker.getImageData(image.meta.name + ':' + image.meta.version, function (err, data) {
console.log(data);
if (err) {
console.error(err);
Images.update(image._id, {
@ -277,19 +282,19 @@ ImageUtil.sync = function () {
} else {
var images = Images.find({}).fetch();
_.each(images, function (image) {
if (image.docker && image.docker.Id) {
var image = Images.findOne(image._id);
if (image && image.docker && image.docker.Id) {
var duplicateImages = Images.find({'docker.Id': image.docker.Id, _id: {$ne: image._id}}).fetch();
_.each(duplicateImages, function (duplicateImage) {
Images.remove(duplicateImage._id);
});
var imageData = _.find(dockerImages, function (dockerImage) {
return dockerImage.Id === image.docker.Id;
});
if (imageData && imageData.RepoTags) {
var repoTag = _.first(imageData.RepoTags);
var repoTagTokens = repoTag.split(':');
var name = repoTagTokens[0];
var version = repoTagTokens[1];
Images.update(image._id, {
$set: {
'meta.name': name,
'meta.version': version
tags: imageData.RepoTags
}
});
}
@ -314,7 +319,7 @@ ImageUtil.sync = function () {
_.each(diffImages, function (imageId) {
var image = Images.findOne({'docker.Id': imageId});
if (image && image.status !== 'BUILDING') {
//ImageUtil.remove(image._id);
ImageUtil.remove(image._id);
}
});
var diffDockerImages = _.reject(dockerImages, function (image) {
@ -328,17 +333,19 @@ ImageUtil.sync = function () {
var buildingImage = _.find(images, function (image) {
return image.status === 'BUILDING' && image.meta.name === name && image.meta.version === version;
});
if (!buildingImage) {
if (!buildingImage && name !== '<none>' && version !== '<none>') {
var imageObj = {
status: 'READY',
docker: image,
buildLogs: [],
createdAt: new Date(),
tags: image.RepoTags,
meta: {
name: name,
version: version
}
};
console.log(imageObj);
Images.insert(imageObj);
}
});

Просмотреть файл

@ -67,6 +67,10 @@ Handlebars.registerHelper('isUpdating', function () {
return Session.get('isUpdating');
});
Handlebars.registerHelper('displayTags', function (tags, delimiter) {
return tags.join(delimiter);
});
var fixBoot2DockerVM = function (callback) {
Boot2Docker.check(function (err) {
if (err) {

Просмотреть файл

@ -1,5 +1,5 @@
Template.dashboard_apps.helpers({
apps: function () {
return Apps.find({name: {$ne: 'kite-dns'}}, {sort: {createdAt: -1}});
return Apps.find({}, {sort: {createdAt: -1}});
}
});

Просмотреть файл

@ -49,6 +49,7 @@ Template.modal_create_image.events({
};
var imageMetaData = ImageUtil.getMetaData(directory);
imageObj.meta = imageMetaData;
imageObj.tags = [imageMetaData.name + ':' + imageMetaData.version];
var imageId = Images.insert(imageObj);
var imagePath = path.join(Util.KITE_IMAGES_PATH, imageId);
Images.update(imageId, {

Просмотреть файл

@ -1,5 +1,5 @@
Template.dashboard_images.helpers({
images: function () {
return Images.find({'meta.name': {$ne: 'kite-dns'}}, {sort: {createdAt: -1}});
return Images.find({}, {sort: {createdAt: -1}});
}
});

Просмотреть файл

@ -18,7 +18,7 @@
{{/if}}
{{/if}}
{{/if}}
<a onclick="trackLink('image detail')" href="/images/{{_id}}" class="name">{{meta.name}}:{{meta.version}}</a>
<a onclick="trackLink('image detail')" href="/images/{{_id}}" class="name">{{displayTags tags ', '}}</a>
{{#if $eq status 'BUILDING'}}
<small>Creating image. This may take a couple minutes...</small>
{{else}}
@ -33,8 +33,10 @@
<a onclick="trackLink('open image folder')" href="#" class="btn-icon btn-folder" target="_blank" data-toggle="tooltip" data-placement="bottom" title="Folder"><span class="typcn typcn-folder-open"></span></a>
{{/if}}
{{#if $neq status 'BUILDING'}}
{{#if originPath}}
<a onclick="trackLink('rebuild image')" href="#" class="btn-icon btn-rebuild" target="_blank" data-toggle="tooltip" data-placement="bottom" title="Rebuild"><span class="typcn typcn-refresh-outline"></span></a>
{{/if}}
{{/if}}
<a onclick="trackLink('image logs')" href="/images/{{_id}}/logs" class="btn-icon" data-toggle="tooltip" data-placement="bottom" title="Logs"><span class="typcn typcn-document-text"></span></a>
<a onclick="trackLink('image settings')" href="/images/{{_id}}/settings" class="btn-icon" data-toggle="tooltip" data-placement="bottom" title="Settings"><span class="typcn typcn-cog-outline"></span></a>
</div>

Просмотреть файл

@ -18,8 +18,10 @@
<a onclick="trackLink('open image folder')" href="#" class="btn-folder" data-toggle="tooltip" data-placement="bottom" title="Folder" data-container="body"><span class="typcn typcn-folder-open"></span></a>
{{/if}}
{{#if $neq status 'BUILDING'}}
{{#if originPath}}
<a onclick="trackLink('rebuild image')" href="#" class="btn-rebuild" data-toggle="tooltip" data-placement="bottom" title="Rebuild" data-container="body"><span class="typcn typcn-refresh-outline"></span></a>
{{/if}}
{{/if}}
</span>
</h3>
<div class="options">