mirror of https://github.com/docker/docs.git
Container status sync'ed across app and docker host.
This commit is contained in:
parent
8f0dc52325
commit
f69ddb1251
|
@ -1,12 +1,17 @@
|
||||||
var exec = require('exec');
|
var exec = require('exec');
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
|
var fs = require('fs');
|
||||||
var Convert = require('ansi-to-html');
|
var Convert = require('ansi-to-html');
|
||||||
var convert = new Convert();
|
var convert = new Convert();
|
||||||
|
|
||||||
AppUtil = {};
|
AppUtil = {};
|
||||||
|
|
||||||
|
AppUtil.create = function () {
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
AppUtil.run = function (app) {
|
AppUtil.run = function (app) {
|
||||||
var image = Images.findOne({_id: app.imageId});
|
var image = Images.findOne({'docker.Id': app.docker.Image});
|
||||||
// Delete old container if one already exists
|
// Delete old container if one already exists
|
||||||
Docker.removeContainer(app.name, function (err) {
|
Docker.removeContainer(app.name, function (err) {
|
||||||
if (err) { console.error(err); }
|
if (err) { console.error(err); }
|
||||||
|
@ -166,3 +171,83 @@ AppUtil.recover = function () {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
AppUtil.sync = function () {
|
||||||
|
Docker.listContainers(function (err, containers) {
|
||||||
|
if (err) {
|
||||||
|
console.error(err);
|
||||||
|
} else {
|
||||||
|
var apps = Apps.find({}).fetch();
|
||||||
|
_.each(apps, function (app) {
|
||||||
|
if (app.docker && app.docker.Id) {
|
||||||
|
Docker.getContainerData(app.docker.Id, function (err, data) {
|
||||||
|
console.log(data);
|
||||||
|
var status = 'STARTING';
|
||||||
|
if (data.State.Running) {
|
||||||
|
status = 'READY';
|
||||||
|
} else {
|
||||||
|
status = 'ERROR';
|
||||||
|
}
|
||||||
|
Apps.update(app._id, {
|
||||||
|
$set: {
|
||||||
|
docker: data,
|
||||||
|
status: status
|
||||||
|
}
|
||||||
|
})
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
var dockerIds = _.map(apps, function (app) {
|
||||||
|
return app.docker.Id;
|
||||||
|
});
|
||||||
|
var containerIds = _.map(containers, function (container) {
|
||||||
|
return container.Id;
|
||||||
|
});
|
||||||
|
var diffApps = _.difference(dockerIds, containerIds);
|
||||||
|
_.each(diffApps, function (appContainerId) {
|
||||||
|
var app = Apps.findOne({'docker.Id': appContainerId});
|
||||||
|
if (app) {
|
||||||
|
AppUtil.remove(app._id);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
var diffContainers = _.reject(containers, function (container) {
|
||||||
|
return _.contains(dockerIds, container.Id);
|
||||||
|
});
|
||||||
|
_.each(diffContainers, function (container) {
|
||||||
|
var appName = container.Name.substring(1);
|
||||||
|
var appPath = path.join(Util.KITE_PATH, appName);
|
||||||
|
if (!fs.existsSync(appPath)) {
|
||||||
|
console.log('Created Kite ' + appName + ' directory.');
|
||||||
|
fs.mkdirSync(appPath, function (err) {
|
||||||
|
if (err) { throw err; }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
var envVars = container.Config.Env;
|
||||||
|
var config = {};
|
||||||
|
_.each(envVars, function (envVar) {
|
||||||
|
var eqPos = envVar.indexOf('=');
|
||||||
|
var envKey = envVar.substring(0, eqPos);
|
||||||
|
var envVal = envVar.substring(eqPos + 1);
|
||||||
|
config[envKey] = envVal;
|
||||||
|
});
|
||||||
|
var status = 'STARTING';
|
||||||
|
if (container.State.Running) {
|
||||||
|
status = 'READY';
|
||||||
|
} else {
|
||||||
|
status = 'ERROR';
|
||||||
|
}
|
||||||
|
var appObj = {
|
||||||
|
name: appName,
|
||||||
|
docker: container,
|
||||||
|
status: status,
|
||||||
|
config: config,
|
||||||
|
path: appPath,
|
||||||
|
logs: [],
|
||||||
|
createdAt: new Date()
|
||||||
|
};
|
||||||
|
console.log(appObj);
|
||||||
|
Apps.insert(appObj);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
|
@ -61,9 +61,15 @@ Docker.getContainerData = function (containerId, callback) {
|
||||||
callback(err, null);
|
callback(err, null);
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
data.Config.Volumes = convertVolumeObjToArray(data.Config.Volumes);
|
if (data.Config && data.Config.Volumes) {
|
||||||
data.Volumes = convertVolumeObjToArray(data.Volumes);
|
data.Config.Volumes = convertVolumeObjToArray(data.Config.Volumes);
|
||||||
data.VolumesRW = convertVolumeObjToArray(data.VolumesRW);
|
}
|
||||||
|
if (data.Volumes) {
|
||||||
|
data.Volumes = convertVolumeObjToArray(data.Volumes);
|
||||||
|
}
|
||||||
|
if (data.VolumesRW) {
|
||||||
|
data.VolumesRW = convertVolumeObjToArray(data.VolumesRW);
|
||||||
|
}
|
||||||
callback(null, data);
|
callback(null, data);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -150,7 +150,7 @@ Meteor.setInterval(function () {
|
||||||
if (!Session.get('boot2dockerOff')) {
|
if (!Session.get('boot2dockerOff')) {
|
||||||
fixBoot2DockerVM(function (err) {
|
fixBoot2DockerVM(function (err) {
|
||||||
if (err) { console.log(err); return; }
|
if (err) { console.log(err); return; }
|
||||||
AppUtil.recover();
|
//AppUtil.recover();
|
||||||
fixDefaultImages(function (err) {
|
fixDefaultImages(function (err) {
|
||||||
if (err) { console.log(err); return; }
|
if (err) { console.log(err); return; }
|
||||||
fixDefaultContainers(function (err) {
|
fixDefaultContainers(function (err) {
|
||||||
|
@ -161,3 +161,9 @@ Meteor.setInterval(function () {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, 5000);
|
}, 5000);
|
||||||
|
|
||||||
|
Meteor.setInterval(function () {
|
||||||
|
if (!Session.get('installing')) {
|
||||||
|
AppUtil.sync();
|
||||||
|
}
|
||||||
|
}, 5000);
|
||||||
|
|
|
@ -9,24 +9,26 @@
|
||||||
{{/if}}
|
{{/if}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="padded">
|
<div class="content">
|
||||||
{{#if hasItem apps}}
|
<div class="padded">
|
||||||
<div class="apps line-item-collection">
|
{{#if hasItem apps}}
|
||||||
{{#each apps}}
|
<div class="apps line-item-collection">
|
||||||
{{> dashboard_single_app}}
|
{{#each apps}}
|
||||||
{{/each}}
|
{{> dashboard_single_app}}
|
||||||
</div>
|
{{/each}}
|
||||||
{{else}}
|
</div>
|
||||||
<div class="empty-placeholder">
|
{{else}}
|
||||||
<div class="big-icon"><i class="fa fa-cube"></i></div>
|
<div class="empty-placeholder">
|
||||||
<h4>There are no apps yet.</h4>
|
<div class="big-icon"><i class="fa fa-cube"></i></div>
|
||||||
{{#if $.Session.equals 'boot2dockerState' 'poweroff'}}
|
<h4>There are no apps yet.</h4>
|
||||||
<a href="#" data-toggle="modal" data-target="#modal-create-app" class="btn btn-action" disabled="disabled"><span class="typcn typcn-plus-outline"></span> Create App</a>
|
{{#if $.Session.equals 'boot2dockerState' 'poweroff'}}
|
||||||
{{else}}
|
<a href="#" data-toggle="modal" data-target="#modal-create-app" class="btn btn-action" disabled="disabled"><span class="typcn typcn-plus-outline"></span> Create App</a>
|
||||||
<a href="#" onclick="trackLink('create app')" data-toggle="modal" data-target="#modal-create-app" class="btn btn-action"><span class="typcn typcn-plus-outline"></span> Create App</a>
|
{{else}}
|
||||||
{{/if}}
|
<a href="#" onclick="trackLink('create app')" data-toggle="modal" data-target="#modal-create-app" class="btn btn-action"><span class="typcn typcn-plus-outline"></span> Create App</a>
|
||||||
</div>
|
{{/if}}
|
||||||
{{/if}}
|
</div>
|
||||||
|
{{/if}}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{{> modal_create_app}}
|
{{> modal_create_app}}
|
||||||
{{> modal_create_image}}
|
{{> modal_create_image}}
|
||||||
|
|
|
@ -36,11 +36,6 @@ Template.modal_create_app.events({
|
||||||
createdAt: new Date()
|
createdAt: new Date()
|
||||||
};
|
};
|
||||||
var appId = Apps.insert(appObj);
|
var appId = Apps.insert(appObj);
|
||||||
Apps.update(appId, {
|
|
||||||
$set: {
|
|
||||||
'config.APP_ID': appId
|
|
||||||
}
|
|
||||||
});
|
|
||||||
var app = Apps.findOne(appId);
|
var app = Apps.findOne(appId);
|
||||||
var image = Images.findOne(app.imageId);
|
var image = Images.findOne(app.imageId);
|
||||||
Util.copyVolumes(image.path, app.name, function (err) {
|
Util.copyVolumes(image.path, app.name, function (err) {
|
||||||
|
|
|
@ -9,24 +9,26 @@
|
||||||
{{/if}}
|
{{/if}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="padded">
|
<div class="content">
|
||||||
{{#if hasItem images}}
|
<div class="padded">
|
||||||
<div class="images line-item-collection">
|
{{#if hasItem images}}
|
||||||
{{#each images}}
|
<div class="images line-item-collection">
|
||||||
{{> dashboard_single_image}}
|
{{#each images}}
|
||||||
{{/each}}
|
{{> dashboard_single_image}}
|
||||||
</div>
|
{{/each}}
|
||||||
{{else}}
|
</div>
|
||||||
<div class="empty-placeholder">
|
{{else}}
|
||||||
<div class="big-icon"><i class="fa fa-camera"></i></div>
|
<div class="empty-placeholder">
|
||||||
<h4>There are no images yet.</h4>
|
<div class="big-icon"><i class="fa fa-camera"></i></div>
|
||||||
{{#if $.Session.equals 'boot2dockerState' 'poweroff'}}
|
<h4>There are no images yet.</h4>
|
||||||
<a href="#" data-toggle="modal" data-target="#modal-create-image" class="btn btn-action" disabled="disabled"><span class="typcn typcn-plus-outline"></span> Create Image</a>
|
{{#if $.Session.equals 'boot2dockerState' 'poweroff'}}
|
||||||
{{else}}
|
<a href="#" data-toggle="modal" data-target="#modal-create-image" class="btn btn-action" disabled="disabled"><span class="typcn typcn-plus-outline"></span> Create Image</a>
|
||||||
<a href="#" onclick="trackLink('create image')" data-toggle="modal" data-target="#modal-create-image" class="btn btn-action"><span class="typcn typcn-plus-outline"></span>Create Image</a>
|
{{else}}
|
||||||
{{/if}}
|
<a href="#" onclick="trackLink('create image')" data-toggle="modal" data-target="#modal-create-image" class="btn btn-action"><span class="typcn typcn-plus-outline"></span>Create Image</a>
|
||||||
</div>
|
{{/if}}
|
||||||
{{/if}}
|
</div>
|
||||||
|
{{/if}}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{{> modal_create_app}}
|
{{> modal_create_app}}
|
||||||
{{> modal_create_image}}
|
{{> modal_create_image}}
|
||||||
|
|
|
@ -6,9 +6,7 @@
|
||||||
{{> dashboard_menu}}
|
{{> dashboard_menu}}
|
||||||
<div class="dashboard-body">
|
<div class="dashboard-body">
|
||||||
<div class="mac-window-header"><a href="#">Kitematic</a></div>
|
<div class="mac-window-header"><a href="#">Kitematic</a></div>
|
||||||
<div class="content longer">
|
{{> yield}}
|
||||||
{{> yield}}
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue