create docker run commands from configuration json
This commit is contained in:
		
							
								
								
									
										15
									
								
								ChangeLog
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								ChangeLog
									
									
									
									
									
								
							| @@ -1,3 +1,18 @@ | |||||||
|  | 2016-01-19 16:20  marc | ||||||
|  |  | ||||||
|  | 	* nodejs/package.json.in, nodejs/public/javascripts/servicedock.js, | ||||||
|  | 	  nodejs/public/stylesheets/servicedock.css, | ||||||
|  | 	  nodejs/sockets/index.js, nodejs/views/index.ejs: new features log | ||||||
|  | 	  and bash | ||||||
|  |  | ||||||
|  | 2016-01-18 14:04  marc | ||||||
|  |  | ||||||
|  | 	* ChangeLog, ax_init_standard_project.m4, bootstrap.sh, | ||||||
|  | 	  build-in-docker.conf, build-in-docker.sh, configure.ac, | ||||||
|  | 	  debian/control.in, doc/doxyfile.in, html, makefile.am, | ||||||
|  | 	  nodejs/makefile.am, nodejs/package.json, nodejs/package.json.in, | ||||||
|  | 	  resolve-debbuilddeps.sh: updated build from html/php to nodejs | ||||||
|  |  | ||||||
| 2016-01-17 23:07  marc | 2016-01-17 23:07  marc | ||||||
|  |  | ||||||
| 	* ChangeLog, html/makefile.am, html/servicedock.js, | 	* ChangeLog, html/makefile.am, html/servicedock.js, | ||||||
|   | |||||||
| @@ -14,11 +14,23 @@ var focused = null; | |||||||
| function Docker() { | function Docker() { | ||||||
|  |  | ||||||
|     function same(array1, array2) { |     function same(array1, array2) { | ||||||
|  |         if (!array1 && !array2) return true; | ||||||
|  |         if (!array1 || !array2) return false; | ||||||
|         return (array1.length == array2.length) |         return (array1.length == array2.length) | ||||||
|             && array1.every(function(element, index) { |             && array1.every(function(element, index) { | ||||||
|                 return element === array2[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; |     var _docker = this; | ||||||
|  |  | ||||||
| @@ -56,9 +68,7 @@ function Docker() { | |||||||
|                 if ((pos=instance.env.indexOf(e))>-1) instance.env.splice(pos, 1) |                 if ((pos=instance.env.indexOf(e))>-1) instance.env.splice(pos, 1) | ||||||
|             }) |             }) | ||||||
|             if (same(nodes[id].cmd, instance.cmd)) instance.cmd = null |             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 |             if (same(nodes[id].entrypoint, instance.entrypoint)) instance.entrypoint = null | ||||||
|             else console.log(instance.entrypoint+" != "+nodes[id].entrypoint) |  | ||||||
|         } |         } | ||||||
|         this.set = function(c) { |         this.set = function(c) { | ||||||
|             if (typeof c == "string") c = JSON.parse(c); |             if (typeof c == "string") c = JSON.parse(c); | ||||||
| @@ -202,7 +212,7 @@ function Docker() { | |||||||
|         this.subgraph = function(name) { |         this.subgraph = function(name) { | ||||||
|             return this.graph(this.subnet(name)); |             return this.graph(this.subnet(name)); | ||||||
|         } |         } | ||||||
|         this.creation = function(name) { |         this.configuration = function(name) { | ||||||
|             var ns = this.subnet(name); |             var ns = this.subnet(name); | ||||||
|             var creates = []; |             var creates = []; | ||||||
|             for (n in ns) { |             for (n in ns) { | ||||||
| @@ -227,14 +237,44 @@ function Docker() { | |||||||
|                 creates.push(instance); |                 creates.push(instance); | ||||||
|             } |             } | ||||||
|             creates.sort(function(a, b) { |             creates.sort(function(a, b) { | ||||||
|                 if (a.volumesfrom.indexOf(b)>=0) return 1; // a after b |                 if (a.volumesfrom.indexOf(b.name)>=0) return 1; // a after b | ||||||
|                 if (b.volumesfrom.indexOf(a)>=0) return -1; // a before 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<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; |                 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 0; // a and b do not depend on each other | ||||||
|             }); |             }); | ||||||
|             return creates; |             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() { |         function setup() { | ||||||
|             delete nodes; nodes = []; |             delete nodes; nodes = []; | ||||||
|             containers.forEach(function(c, i) { |             containers.forEach(function(c, i) { | ||||||
| @@ -740,7 +780,9 @@ function bash_data(data) { | |||||||
|     } else { |     } else { | ||||||
|         $("#screen").append('<span class="'+data.type+'">'+ansifilter(htmlenc(data.text))+'</span>'); |         $("#screen").append('<span class="'+data.type+'">'+ansifilter(htmlenc(data.text))+'</span>'); | ||||||
|     } |     } | ||||||
| } |     $("#screen").animate({ | ||||||
|  |         scrollTop: $("#screen").scrollHeight() | ||||||
|  |     }, 500);} | ||||||
|  |  | ||||||
| function overview() { | function overview() { | ||||||
|     focused = null; |     focused = null; | ||||||
|   | |||||||
| @@ -237,11 +237,11 @@ table.docker li+li { | |||||||
|   top: 1.5em; |   top: 1.5em; | ||||||
|   left: 0; |   left: 0; | ||||||
|   right: 0; |   right: 0; | ||||||
|   bottom: 1.5em; |  | ||||||
|   padding: 1em 1em 1em 1em; |   padding: 1em 1em 1em 1em; | ||||||
|   clear: both; |   clear: both; | ||||||
|   overflow: auto; |   overflow: auto; | ||||||
|   z-index: 0; |   z-index: 0; | ||||||
|  |   bottom: 1.5em; | ||||||
| } | } | ||||||
|  |  | ||||||
| #main { | #main { | ||||||
| @@ -332,7 +332,24 @@ table.docker li+li { | |||||||
|  |  | ||||||
| #console { | #console { | ||||||
|   background-color: black; |   background-color: black; | ||||||
|   color: white |   color: white; | ||||||
|  |   overflow: none; | ||||||
|  | } | ||||||
|  | #screen { | ||||||
|  |   position: fixed; | ||||||
|  |   top: 2em; | ||||||
|  |   bottom: 4em; | ||||||
|  |   left: 0; | ||||||
|  |   right: 0; | ||||||
|  |   overflow: auto; | ||||||
|  |   padding: 1ex; | ||||||
|  | } | ||||||
|  | #bash { | ||||||
|  |   position: fixed; | ||||||
|  |   bottom: 1.5em; | ||||||
|  |   left: 0; | ||||||
|  |   right: 0; | ||||||
|  |   padding: 0; | ||||||
| } | } | ||||||
| .bold {font-weight: bold} | .bold {font-weight: bold} | ||||||
| .dim {color: grey} | .dim {color: grey} | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user