|
|
|
@ -14,12 +14,24 @@ var focused = null; |
|
|
|
|
function Docker() { |
|
|
|
|
|
|
|
|
|
function same(array1, array2) { |
|
|
|
|
if (!array1 && !array2) return true; |
|
|
|
|
if (!array1 || !array2) return false; |
|
|
|
|
return (array1.length == array2.length) |
|
|
|
|
&& array1.every(function(element, index) { |
|
|
|
|
return element === array2[index];
|
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function quote(text) { |
|
|
|
|
if (text.match('"')) { |
|
|
|
|
if (!text.match("'")) return "'"+text+"'"; |
|
|
|
|
else return '"'+text.replace(/"/g, '\\"')+'"'; |
|
|
|
|
} else { |
|
|
|
|
if (text.match(' ')) return '"'+text+'"'; |
|
|
|
|
else return text; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var _docker = this; |
|
|
|
|
|
|
|
|
|
this.Images = function() { |
|
|
|
@ -56,9 +68,7 @@ function Docker() { |
|
|
|
|
if ((pos=instance.env.indexOf(e))>-1) instance.env.splice(pos, 1) |
|
|
|
|
}) |
|
|
|
|
if (same(nodes[id].cmd, instance.cmd)) instance.cmd = null |
|
|
|
|
else console.log(instance.cmd+" != "+nodes[id].cmd) |
|
|
|
|
if (same(nodes[id].entrypoint, instance.entrypoint)) instance.entrypoint = null |
|
|
|
|
else console.log(instance.entrypoint+" != "+nodes[id].entrypoint) |
|
|
|
|
} |
|
|
|
|
this.set = function(c) { |
|
|
|
|
if (typeof c == "string") c = JSON.parse(c); |
|
|
|
@ -202,7 +212,7 @@ function Docker() { |
|
|
|
|
this.subgraph = function(name) { |
|
|
|
|
return this.graph(this.subnet(name)); |
|
|
|
|
} |
|
|
|
|
this.creation = function(name) { |
|
|
|
|
this.configuration = function(name) { |
|
|
|
|
var ns = this.subnet(name); |
|
|
|
|
var creates = []; |
|
|
|
|
for (n in ns) { |
|
|
|
@ -227,14 +237,44 @@ function Docker() { |
|
|
|
|
creates.push(instance); |
|
|
|
|
} |
|
|
|
|
creates.sort(function(a, b) { |
|
|
|
|
if (a.volumesfrom.indexOf(b)>=0) return 1; // a after b
|
|
|
|
|
if (b.volumesfrom.indexOf(a)>=0) return -1; // a before b
|
|
|
|
|
if (a.volumesfrom.indexOf(b.name)>=0) return 1; // a after b
|
|
|
|
|
if (b.volumesfrom.indexOf(a.name)>=0) return -1; // a before b
|
|
|
|
|
for (var i=0; i<a.links.length; ++i) if (a.links[i].to == b.name) return 1; // a after b;
|
|
|
|
|
for (var i=0; i<b.links.length; ++i) if (b.links[i].to == a.name) return -1; // a before b;
|
|
|
|
|
if ((b.volumesfrom.length || b.links.length) && !(a.volumesfrom.length || a.links.length)) return 1; // a after b;
|
|
|
|
|
if ((a.volumesfrom.length || a.links.length) && !(b.volumesfrom.length || b.links.length)) return 1; // a after b;
|
|
|
|
|
return 0; // a and b do not depend on each other
|
|
|
|
|
}); |
|
|
|
|
return creates; |
|
|
|
|
} |
|
|
|
|
this.creation = function(name) { |
|
|
|
|
var res = []; |
|
|
|
|
this.configuration(name).forEach(function(n) { |
|
|
|
|
var cmd = "docker create -d --name "+quote(n.name); |
|
|
|
|
n.ports.forEach(function(p) { |
|
|
|
|
cmd += " --publish "+(p.ip?quote(p.ip)+":":"")+p.external+":"+p.internal; |
|
|
|
|
}); |
|
|
|
|
n.env.forEach(function(e) { |
|
|
|
|
cmd += ' --env '+quote(e); |
|
|
|
|
}); |
|
|
|
|
n.volumes.forEach(function(v) { |
|
|
|
|
cmd += ' --volume '+quote(v.outside)+':'+quote(v.inside); |
|
|
|
|
}); |
|
|
|
|
n.volumesfrom.forEach(function(v) { |
|
|
|
|
cmd += ' --volumes-from '+quote(v); |
|
|
|
|
}) |
|
|
|
|
n.links.forEach(function(l) { |
|
|
|
|
cmd += ' --link '+quote(l.link)+':'+quote(l.to); |
|
|
|
|
}); |
|
|
|
|
if (n.entrypoint && n.entrypoint.length) cmd += ' --entrypoint '+quote(n.entrypoint.join(" ")); |
|
|
|
|
cmd += " "+n.image; |
|
|
|
|
if (n.cmd) n.cmd.forEach(function(c) { |
|
|
|
|
cmd+= ' '+quote(c); |
|
|
|
|
}); |
|
|
|
|
res.push(cmd); |
|
|
|
|
}) |
|
|
|
|
return res; |
|
|
|
|
} |
|
|
|
|
function setup() { |
|
|
|
|
delete nodes; nodes = []; |
|
|
|
|
containers.forEach(function(c, i) { |
|
|
|
@ -740,7 +780,9 @@ function bash_data(data) { |
|
|
|
|
} else { |
|
|
|
|
$("#screen").append('<span class="'+data.type+'">'+ansifilter(htmlenc(data.text))+'</span>'); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
$("#screen").animate({ |
|
|
|
|
scrollTop: $("#screen").scrollHeight() |
|
|
|
|
}, 500);} |
|
|
|
|
|
|
|
|
|
function overview() { |
|
|
|
|
focused = null; |
|
|
|
|