mirror of https://github.com/docker/docs.git
Changing sync to only sync containers that have ports exposed
This commit is contained in:
parent
ffaa2bc565
commit
1a956a6504
|
@ -66,10 +66,9 @@ AppUtil.stop = function (appId) {
|
|||
|
||||
AppUtil.remove = function (appId) {
|
||||
var app = Apps.findOne(appId);
|
||||
Apps.remove({_id: appId});
|
||||
if (app.docker) {
|
||||
Docker.removeContainer(app.docker.Id, function (err) {
|
||||
if (err) { console.error(err); }
|
||||
Apps.remove({_id: appId});
|
||||
var appPath = path.join(Util.KITE_PATH, app.name);
|
||||
Util.deleteFolder(appPath);
|
||||
});
|
||||
|
@ -82,7 +81,11 @@ AppUtil.configVar = function (appId, configVars) {
|
|||
status: 'STARTING'
|
||||
}});
|
||||
var app = Apps.findOne({_id: appId});
|
||||
AppUtil.run(app);
|
||||
AppUtil.run(Apps.findOne(appId), function (err) {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
AppUtil.logs = function (appId) {
|
||||
|
@ -137,7 +140,7 @@ AppUtil.sync = function (callback) {
|
|||
}
|
||||
|
||||
var apps = Apps.find({}).fetch();
|
||||
var dockerIds = _.map(apps, function (app) {
|
||||
var guiIds = _.map(apps, function (app) {
|
||||
if (app.docker && app.docker.Id) {
|
||||
return app.docker.Id;
|
||||
}
|
||||
|
@ -145,7 +148,7 @@ AppUtil.sync = function (callback) {
|
|||
var containerIds = _.map(containers, function (container) {
|
||||
return container.Id;
|
||||
});
|
||||
var diffApps = _.difference(dockerIds, containerIds);
|
||||
var diffApps = _.difference(guiIds, containerIds);
|
||||
_.each(diffApps, function (appContainerId) {
|
||||
var app = Apps.findOne({'docker.Id': appContainerId});
|
||||
if (app && app.status !== 'STARTING') {
|
||||
|
@ -153,14 +156,18 @@ AppUtil.sync = function (callback) {
|
|||
}
|
||||
});
|
||||
var diffContainers = _.reject(containers, function (container) {
|
||||
return _.contains(dockerIds, container.Id);
|
||||
return _.contains(guiIds, container.Id);
|
||||
});
|
||||
_.each(diffContainers, function (container) {
|
||||
var appName = container.Name.substring(1);
|
||||
var startingApp = _.find(apps, function (app) {
|
||||
return app.status === 'STARTING' && app.name === appName;
|
||||
});
|
||||
if (!startingApp && appName !== 'kite-dns') {
|
||||
|
||||
if (startingApp || _.isEmpty(container.NetworkSettings.Ports)) {
|
||||
return;
|
||||
}
|
||||
|
||||
var appPath = path.join(Util.KITE_PATH, appName);
|
||||
if (!fs.existsSync(appPath)) {
|
||||
console.log('Created Kite ' + appName + ' directory.');
|
||||
|
@ -190,9 +197,13 @@ AppUtil.sync = function (callback) {
|
|||
config: config,
|
||||
path: appPath,
|
||||
logs: [],
|
||||
createdAt: new Date(),
|
||||
imageId: Images.findOne({'docker.Id': container.Image})._id
|
||||
createdAt: new Date()
|
||||
};
|
||||
|
||||
var image = Images.findOne({'docker.Id': container.Image});
|
||||
if (image) {
|
||||
appObj.imageId = image._id;
|
||||
}
|
||||
if (container.HostConfig.Binds && container.HostConfig.Binds.length) {
|
||||
appObj.volumesEnabled = true;
|
||||
} else {
|
||||
|
@ -200,7 +211,6 @@ AppUtil.sync = function (callback) {
|
|||
}
|
||||
console.log(appObj);
|
||||
Apps.insert(appObj);
|
||||
}
|
||||
});
|
||||
|
||||
async.each(apps, function (app, callback) {
|
||||
|
|
|
@ -181,37 +181,24 @@ var convertVolumeObjToArray = function (obj) {
|
|||
};
|
||||
|
||||
Docker.getImageData = function (imageId, callback) {
|
||||
Docker.client().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.client().getImage(imageId);
|
||||
image.inspect(function (err, data) {
|
||||
if (err) {
|
||||
callback(err, null);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
if (data.Config && data.Config.Volumes) {
|
||||
data.Config.Volumes = convertVolumeObjToArray(data.Config.Volumes);
|
||||
}
|
||||
if (data.ContainerConfig && data.ContainerConfig.Volumes) {
|
||||
data.ContainerConfig.Volumes = convertVolumeObjToArray(data.ContainerConfig.Volumes);
|
||||
}
|
||||
if (!dockerImage) {
|
||||
callback(null, data);
|
||||
} else {
|
||||
callback(null, _.extend(dockerImage, data));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Docker.listImages = function (callback) {
|
||||
Docker.client().listImages({all: false}, function (err, images) {
|
||||
Docker.listImages = function (opts, callback) {
|
||||
Docker.client().listImages(opts, function (err, images) {
|
||||
if (err) {
|
||||
callback(err, null);
|
||||
} else {
|
||||
|
@ -221,7 +208,7 @@ Docker.listImages = function (callback) {
|
|||
if (err) {
|
||||
cb(err, null);
|
||||
} else {
|
||||
cb(null, data);
|
||||
cb(null, _.extend(image, data));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
|
|
@ -171,7 +171,7 @@ ImageUtil.build = function (image, callback) {
|
|||
buildLogs: []
|
||||
}
|
||||
});
|
||||
Docker.client().buildImage(tarFilePath, {t: image.meta.name + ':' + image.meta.version}, function (err, response) {
|
||||
Docker.client().buildImage(tarFilePath, {forcerm: true, t: image.meta.name + ':' + image.meta.version}, function (err, response) {
|
||||
if (err) { callback(err); return; }
|
||||
console.log('Building Docker image...');
|
||||
response.setEncoding('utf8');
|
||||
|
@ -240,7 +240,7 @@ ImageUtil.remove = function (imageId) {
|
|||
};
|
||||
|
||||
ImageUtil.sync = function (callback) {
|
||||
Docker.listImages(function (err, dockerImages) {
|
||||
Docker.listImages({all: 0}, function (err, dockerImages) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
return;
|
||||
|
@ -269,24 +269,30 @@ ImageUtil.sync = function (callback) {
|
|||
return _.contains(kitematicIds, image.Id);
|
||||
});
|
||||
_.each(diffDockerImages, function (image) {
|
||||
if (!image.RepoTags || _.isEmpty(image.Config.ExposedPorts)) {
|
||||
return;
|
||||
}
|
||||
|
||||
var meta = {};
|
||||
var repoTag = _.first(image.RepoTags);
|
||||
var repoTagTokens = repoTag.split(':');
|
||||
var name = repoTagTokens[0];
|
||||
var version = repoTagTokens[1];
|
||||
meta = {
|
||||
name: name,
|
||||
version: version
|
||||
};
|
||||
var buildingImage = _.find(images, function (image) {
|
||||
return image.status === 'BUILDING' && image.meta.name === name && image.meta.version === version;
|
||||
});
|
||||
if (!buildingImage && name !== '<none>' && version !== '<none>' && name !== 'kite-dns') {
|
||||
if (!buildingImage) {
|
||||
var imageObj = {
|
||||
status: 'READY',
|
||||
docker: image,
|
||||
buildLogs: [],
|
||||
createdAt: new Date(),
|
||||
tags: image.RepoTags,
|
||||
meta: {
|
||||
name: name,
|
||||
version: version
|
||||
}
|
||||
meta: meta
|
||||
};
|
||||
Images.insert(imageObj);
|
||||
}
|
||||
|
|
|
@ -49,10 +49,7 @@ Router.map(function () {
|
|||
if (!settings) {
|
||||
Settings.insert({tracking: true});
|
||||
}
|
||||
console.log('Starting boot2docker utilization monitor...');
|
||||
startUpdatingBoot2DockerUtilization();
|
||||
|
||||
console.log('Starting CLI sync...');
|
||||
startSyncingAppState();
|
||||
Router.go('dashboard_apps');
|
||||
}
|
||||
|
|
|
@ -101,11 +101,16 @@ startUpdatingBoot2DockerUtilization = function () {
|
|||
};
|
||||
|
||||
startSyncingAppState = function () {
|
||||
try {
|
||||
ImageUtil.sync(function (err) {
|
||||
if (err) {console.log(err);}
|
||||
if (err) {throw err;}
|
||||
AppUtil.sync(function (err) {
|
||||
if (err) {console.log(err);}
|
||||
if (err) {throw err;}
|
||||
Meteor.setTimeout(startSyncingAppState, 2000);
|
||||
});
|
||||
});
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
Meteor.setTimeout(startSyncingAppState, 2000);
|
||||
}
|
||||
};
|
|
@ -14,7 +14,9 @@
|
|||
{{#if hasItem images}}
|
||||
<div class="images line-item-collection">
|
||||
{{#each images}}
|
||||
{{#if this.tags}}
|
||||
{{> dashboardSingleImage}}
|
||||
{{/if}}
|
||||
{{/each}}
|
||||
</div>
|
||||
{{else}}
|
||||
|
|
Loading…
Reference in New Issue