mirror of https://github.com/docker/docs.git
Refactoring and bug fixes.
This commit is contained in:
parent
b9a089180d
commit
1249b23510
|
@ -33,11 +33,10 @@ AppUtil.restartHelper = function (app) {
|
||||||
if (err) { console.error(err); }
|
if (err) { console.error(err); }
|
||||||
Docker.getContainerData(app.docker.Id, function (err, data) {
|
Docker.getContainerData(app.docker.Id, function (err, data) {
|
||||||
if (err) { console.error(err); }
|
if (err) { console.error(err); }
|
||||||
// Use dig to refresh the DNS
|
Util.refreshDNS(app, function (err) {
|
||||||
exec('/usr/bin/dig ' + app.name + '.kite @172.17.42.1', function(err, stdout, stderr) {
|
if (err) {
|
||||||
console.log(err);
|
console.error(err);
|
||||||
console.log(stdout);
|
}
|
||||||
console.log(stderr);
|
|
||||||
Apps.update(app._id, {$set: {
|
Apps.update(app._id, {$set: {
|
||||||
status: 'READY',
|
status: 'READY',
|
||||||
docker: data
|
docker: data
|
||||||
|
@ -58,11 +57,10 @@ AppUtil.start = function (appId) {
|
||||||
if (err) { console.error(err); }
|
if (err) { console.error(err); }
|
||||||
Docker.getContainerData(app.docker.Id, function (err, data) {
|
Docker.getContainerData(app.docker.Id, function (err, data) {
|
||||||
if (err) { console.error(err); }
|
if (err) { console.error(err); }
|
||||||
// Use dig to refresh the DNS
|
Util.refreshDNS(app, function (err) {
|
||||||
exec('/usr/bin/dig ' + app.name + '.kite @172.17.42.1', function(err, stdout, stderr) {
|
if (err) {
|
||||||
console.log(err);
|
console.error(err);
|
||||||
console.log(stdout);
|
}
|
||||||
console.log(stderr);
|
|
||||||
Apps.update(app._id, {$set: {
|
Apps.update(app._id, {$set: {
|
||||||
status: 'READY',
|
status: 'READY',
|
||||||
docker: data
|
docker: data
|
||||||
|
@ -178,9 +176,9 @@ AppUtil.sync = function () {
|
||||||
if (app.docker && app.docker.Id) {
|
if (app.docker && app.docker.Id) {
|
||||||
Docker.getContainerData(app.docker.Id, function (err, data) {
|
Docker.getContainerData(app.docker.Id, function (err, data) {
|
||||||
var status = 'STARTING';
|
var status = 'STARTING';
|
||||||
if (data.State.Running) {
|
if (data && data.State && data.State.Running) {
|
||||||
status = 'READY';
|
status = 'READY';
|
||||||
} else {
|
} else if (data && data.State && !data.State.Running) {
|
||||||
status = 'ERROR';
|
status = 'ERROR';
|
||||||
}
|
}
|
||||||
Apps.update(app._id, {
|
Apps.update(app._id, {
|
||||||
|
|
|
@ -84,7 +84,7 @@ Docker.runContainer = function (app, image, callback) {
|
||||||
});
|
});
|
||||||
console.log(envParam);
|
console.log(envParam);
|
||||||
docker.createContainer({
|
docker.createContainer({
|
||||||
Image: image._id.toLowerCase(),
|
Image: image.docker.Id,
|
||||||
Tty: false,
|
Tty: false,
|
||||||
Env: envParam,
|
Env: envParam,
|
||||||
Hostname: app.name,
|
Hostname: app.name,
|
||||||
|
@ -94,7 +94,7 @@ Docker.runContainer = function (app, image, callback) {
|
||||||
console.log('Created container: ' + container.id);
|
console.log('Created container: ' + container.id);
|
||||||
// Bind volumes
|
// Bind volumes
|
||||||
var binds = [];
|
var binds = [];
|
||||||
if (image.docker.Config.Volumes.length > 0) {
|
if (image.docker.Config.Volumes && image.docker.Config.Volumes.length > 0) {
|
||||||
_.each(image.docker.Config.Volumes, function (vol) {
|
_.each(image.docker.Config.Volumes, function (vol) {
|
||||||
binds.push('/var/lib/docker/binds/' + app.name + vol.Path + ':' + vol.Path);
|
binds.push('/var/lib/docker/binds/' + app.name + vol.Path + ':' + vol.Path);
|
||||||
});
|
});
|
||||||
|
@ -106,11 +106,10 @@ Docker.runContainer = function (app, image, callback) {
|
||||||
}, function (err) {
|
}, function (err) {
|
||||||
if (err) { callback(err, null); return; }
|
if (err) { callback(err, null); return; }
|
||||||
console.log('Started container: ' + container.id);
|
console.log('Started container: ' + container.id);
|
||||||
// Use dig to refresh the DNS
|
Util.refreshDNS(app, function (err) {
|
||||||
exec('/usr/bin/dig ' + app.name + '.kite @172.17.42.1', function(err, stdout, stderr) {
|
if (err) {
|
||||||
console.log(err);
|
console.error(err);
|
||||||
console.log(stdout);
|
}
|
||||||
console.log(stderr);
|
|
||||||
callback(null, container);
|
callback(null, container);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -170,7 +169,7 @@ var convertVolumeObjToArray = function (obj) {
|
||||||
};
|
};
|
||||||
|
|
||||||
Docker.getImageData = function (imageId, callback) {
|
Docker.getImageData = function (imageId, callback) {
|
||||||
var image = docker.getImage(imageId.toLowerCase());
|
var image = docker.getImage(imageId);
|
||||||
image.inspect(function (err, data) {
|
image.inspect(function (err, data) {
|
||||||
if (err) {
|
if (err) {
|
||||||
callback(err, null);
|
callback(err, null);
|
||||||
|
@ -215,7 +214,7 @@ Docker.listImages = function (callback) {
|
||||||
};
|
};
|
||||||
|
|
||||||
Docker.removeImage = function (imageId, callback) {
|
Docker.removeImage = function (imageId, callback) {
|
||||||
var image = docker.getImage(imageId.toLowerCase());
|
var image = docker.getImage(imageId);
|
||||||
image.remove({force: true}, function (err) {
|
image.remove({force: true}, function (err) {
|
||||||
if (err) { callback(err); return; }
|
if (err) { callback(err); return; }
|
||||||
console.log('Deleted image: ' + imageId);
|
console.log('Deleted image: ' + imageId);
|
||||||
|
|
|
@ -196,7 +196,7 @@ ImageUtil.build = function (image, callback) {
|
||||||
buildLogs: []
|
buildLogs: []
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
docker.buildImage(tarFilePath, {t: image._id.toLowerCase()}, function (err, response) {
|
docker.buildImage(tarFilePath, {t: image.meta.name + ':' + image.meta.version}, function (err, response) {
|
||||||
if (err) { callback(err); }
|
if (err) { callback(err); }
|
||||||
console.log('Building Docker image...');
|
console.log('Building Docker image...');
|
||||||
response.setEncoding('utf8');
|
response.setEncoding('utf8');
|
||||||
|
@ -221,8 +221,9 @@ ImageUtil.build = function (image, callback) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
}
|
}
|
||||||
var imageData = null;
|
var imageData = null;
|
||||||
Docker.getImageData(image._id, function (err, data) {
|
Docker.getImageData(image.meta.name + ':' + image.meta.version, function (err, data) {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
console.error(err);
|
||||||
Images.update(image._id, {
|
Images.update(image._id, {
|
||||||
$set: {
|
$set: {
|
||||||
status: 'ERROR'
|
status: 'ERROR'
|
||||||
|
@ -313,7 +314,7 @@ ImageUtil.sync = function () {
|
||||||
_.each(diffImages, function (imageId) {
|
_.each(diffImages, function (imageId) {
|
||||||
var image = Images.findOne({'docker.Id': imageId});
|
var image = Images.findOne({'docker.Id': imageId});
|
||||||
if (image && image.status !== 'BUILDING') {
|
if (image && image.status !== 'BUILDING') {
|
||||||
ImageUtil.remove(image._id);
|
//ImageUtil.remove(image._id);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
var diffDockerImages = _.reject(dockerImages, function (image) {
|
var diffDockerImages = _.reject(dockerImages, function (image) {
|
||||||
|
|
|
@ -4,10 +4,25 @@ var nodeCrypto = require('crypto');
|
||||||
var request = require('request');
|
var request = require('request');
|
||||||
var progress = require('request-progress');
|
var progress = require('request-progress');
|
||||||
var ncp = require('ncp').ncp;
|
var ncp = require('ncp').ncp;
|
||||||
|
var exec = require('exec');
|
||||||
ncp.limit = 16;
|
ncp.limit = 16;
|
||||||
|
|
||||||
Util = {};
|
Util = {};
|
||||||
|
|
||||||
|
Util.refreshDNS = function (app, callback) {
|
||||||
|
// Use dig to refresh the DNS
|
||||||
|
exec('/usr/bin/dig ' + app.name + '.kite @172.17.42.1', function (err, stdout, stderr) {
|
||||||
|
console.log(err);
|
||||||
|
console.log(stdout);
|
||||||
|
console.log(stderr);
|
||||||
|
if (err) {
|
||||||
|
callback(err);
|
||||||
|
} else {
|
||||||
|
callback(null);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
Util.getHomePath = function () {
|
Util.getHomePath = function () {
|
||||||
return process.env[(process.platform === 'win32') ? 'USERPROFILE' : 'HOME'];
|
return process.env[(process.platform === 'win32') ? 'USERPROFILE' : 'HOME'];
|
||||||
};
|
};
|
||||||
|
@ -56,17 +71,21 @@ Util.copyFolder = function (src, dest, callback) {
|
||||||
};
|
};
|
||||||
|
|
||||||
Util.copyVolumes = function (directory, appName, callback) {
|
Util.copyVolumes = function (directory, appName, callback) {
|
||||||
var volumesPath = path.join(directory, 'volumes');
|
if (directory) {
|
||||||
if (fs.existsSync(volumesPath)) {
|
var volumesPath = path.join(directory, 'volumes');
|
||||||
var destinationPath = path.join(Util.KITE_PATH, appName);
|
if (fs.existsSync(volumesPath)) {
|
||||||
Util.copyFolder(volumesPath, destinationPath, function (err) {
|
var destinationPath = path.join(Util.KITE_PATH, appName);
|
||||||
if (err) {
|
Util.copyFolder(volumesPath, destinationPath, function (err) {
|
||||||
callback(err);
|
if (err) {
|
||||||
return;
|
callback(err);
|
||||||
}
|
return;
|
||||||
console.log('Copied volumes for: ' + appName);
|
}
|
||||||
|
console.log('Copied volumes for: ' + appName);
|
||||||
|
callback(null);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
callback(null);
|
callback(null);
|
||||||
});
|
}
|
||||||
} else {
|
} else {
|
||||||
callback(null);
|
callback(null);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue