possibility to download configuration
This commit is contained in:
@@ -70,6 +70,46 @@ module.exports = function() {
|
||||
updatecontainers();
|
||||
}
|
||||
|
||||
function imageinspect(error, stdout, stderr) {
|
||||
if (error || stderr)
|
||||
return fail("inspect docker images failed", {
|
||||
error: error, stderr: stderr, stdout: stdout
|
||||
});
|
||||
emit("images", stdout);
|
||||
}
|
||||
|
||||
function imagelist(error, stdout, stderr) {
|
||||
if (error || stderr)
|
||||
return fail("list docker images failed", {
|
||||
error: error, stderr: stderr, stdout: stdout
|
||||
});
|
||||
exec("docker inspect "+stdout.trim().replace(/\n/g, " "), imageinspect);
|
||||
}
|
||||
|
||||
function updateimages(error, stdout, stderr) {
|
||||
if (error || stderr)
|
||||
return fail("update docker images failed", {
|
||||
error: error, stderr: stderr, stdout: stdout
|
||||
});
|
||||
exec("docker images -q", imagelist);
|
||||
}
|
||||
|
||||
function modify(cmd, name) {
|
||||
if (!name.match(/^[a-z0-9][-_:.+a-z0-9]*$/i))
|
||||
return fail("illegal instance name");
|
||||
exec("docker "+cmd+" "+name, updatecontainers);
|
||||
}
|
||||
|
||||
function containers() {
|
||||
console.log("-> containers");
|
||||
updatecontainers();
|
||||
}
|
||||
|
||||
function images() {
|
||||
console.log("-> images");
|
||||
updateimages();
|
||||
}
|
||||
|
||||
function start(name) {
|
||||
console.log("-> start("+name+")");
|
||||
modify("start", name);
|
||||
@@ -111,36 +151,39 @@ module.exports = function() {
|
||||
|
||||
var bash_connections = {};
|
||||
|
||||
function bash_start(name) {
|
||||
console.log("-> bash-start("+name+")");
|
||||
function new_bash(name) {
|
||||
if (!name.match(/^[a-z0-9][-_:.+a-z0-9]*$/i))
|
||||
return fail("illegal instance name");
|
||||
if (bash_connections[name]) return fail("bash already open");
|
||||
if (bash_connections[name]) return;
|
||||
bash_connections[name] =
|
||||
pty.spawn("docker", ["exec", "-it", name, "bash", "-i"]);
|
||||
bash_connections[name].stdout.on('data', function(data) {
|
||||
emit('bash-data', {name: name, type: 'stdout', text: data.toString()});
|
||||
});
|
||||
// bash_connections[name].stderr.on('data', function(data) {
|
||||
// emit('bash-data', {name: name, type: 'stdout', text: data.toString()});
|
||||
// });
|
||||
}
|
||||
|
||||
function bash_start(name) {
|
||||
console.log("-> bash-start("+name+")");
|
||||
new_bash(name);
|
||||
}
|
||||
|
||||
function bash_input(data) {
|
||||
console.log("-> bash-input("+data.name+", "+data.text+")");
|
||||
if (!bash_connections[data.name]) return fail("bash not open");
|
||||
new_bash(name);
|
||||
bash_connections[data.name].stdin.resume();
|
||||
bash_connections[data.name].stdin.write(data.text);
|
||||
}
|
||||
|
||||
// function bash_end(name, text) {
|
||||
// console.log("-> bash-end("+name+")");
|
||||
// if (!bash_connections[name]) return fail("bash not open");
|
||||
// bash_connections[name].stdin.close();
|
||||
// }
|
||||
function bash_end(name, text) {
|
||||
console.log("-> bash-end("+name+")");
|
||||
if (!bash_connections[name]) return;
|
||||
bash_connections[name].stdin.close();
|
||||
delete bash_connections[name]; bash_connections[name] = null;
|
||||
}
|
||||
|
||||
socket
|
||||
.on("containers", containers)
|
||||
.on("images", images)
|
||||
.on("start", start)
|
||||
.on("stop", stop)
|
||||
.on("pause", pause)
|
||||
@@ -148,8 +191,8 @@ module.exports = function() {
|
||||
.on("remove", remove)
|
||||
.on('logs', logs)
|
||||
.on('bash-start', bash_start)
|
||||
.on('bash-input', bash_input);
|
||||
//.on('bash-end', bash_end);
|
||||
.on('bash-input', bash_input)
|
||||
.on('bash-end', bash_end);
|
||||
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user