Docker enhancements and corrections

- delete cache files when container is deleted
- improved handling of user defined networks
-  optimized reading of container and image settings
- improved handling of container IP address assignment
- code optimization and consistency
This commit is contained in:
bergware
2018-04-02 13:18:31 +02:00
parent 9fa3981a8f
commit b6d86dc5f7
7 changed files with 320 additions and 377 deletions

View File

@@ -1,8 +1,8 @@
var eventURL = "/plugins/dynamix.docker.manager/include/Events.php";
var eventURL = '/plugins/dynamix.docker.manager/include/Events.php';
function addDockerContainerContext(container, image, template, started, update, autostart, webui, id, Support, Project) {
var opts = [{header:container, image:"/plugins/dynamix.docker.manager/images/dynamix.docker.manager.png"}];
if (started && (webui !== "" && webui != "#")) {
var opts = [{header:container, image:'/plugins/dynamix.docker.manager/images/dynamix.docker.manager.png'}];
if (started && (webui !== '' && webui != '#')) {
opts.push({text:'WebUI', icon:'fa-globe', href:webui, target:'_blank'});
opts.push({divider:true});
}
@@ -11,13 +11,13 @@ function addDockerContainerContext(container, image, template, started, update,
opts.push({divider:true});
}
if (started) {
opts.push({text:'Stop', icon:'fa-stop', action:function(e){e.preventDefault(); eventControl({action:"stop", container:id}, 'loadlist');}});
opts.push({text:'Restart', icon:'fa-refresh', action:function(e){e.preventDefault(); eventControl({action:"restart", container:id}, 'loadlist');}});
opts.push({text:'Stop', icon:'fa-stop', action:function(e){e.preventDefault(); eventControl({action:'stop', container:id}, 'loadlist');}});
opts.push({text:'Restart', icon:'fa-refresh', action:function(e){e.preventDefault(); eventControl({action:'restart', container:id}, 'loadlist');}});
} else {
opts.push({text:'Start', icon:'fa-play', action:function(e){e.preventDefault(); eventControl({action:"start", container:id}, 'loadlist');}});
opts.push({text:'Start', icon:'fa-play', action:function(e){e.preventDefault(); eventControl({action:'start', container:id}, 'loadlist');}});
}
opts.push({divider:true});
if (location.pathname.indexOf("/Dashboard") === 0) {
if (location.pathname.indexOf('/Dashboard') === 0) {
opts.push({text:'Logs', icon:'fa-navicon', action:function(e){e.preventDefault(); containerLogs(container, id);}});
}
if (template) {
@@ -36,18 +36,18 @@ function addDockerContainerContext(container, image, template, started, update,
}
function addDockerImageContext(image, imageTag) {
var opts = [{header:'(orphan image)'}];
opts.push({text:"Remove", icon:"fa-trash", action:function(e){e.preventDefault(); rmImage(image, imageTag);}});
opts.push({text:'Remove', icon:'fa-trash', action:function(e){e.preventDefault(); rmImage(image, imageTag);}});
context.attach('#'+image, opts);
}
function execUpContainer(container) {
var title = "Updating the container: "+container;
var address = "/plugins/dynamix.docker.manager/include/CreateDocker.php?updateContainer=true&ct[]="+encodeURIComponent(container);
var title = 'Updating the container: '+container;
var address = '/plugins/dynamix.docker.manager/include/CreateDocker.php?updateContainer=true&ct[]='+encodeURIComponent(container);
popupWithIframe(title, address, true, 'loadlist');
}
function popupWithIframe(title, cmd, reload, func) {
pauseEvents();
$("#iframe-popup").html('<iframe id="myIframe" frameborder="0" scrolling="yes" width="100%" height="99%"></iframe>');
$("#iframe-popup").dialog({
$('#iframe-popup').html('<iframe id="myIframe" frameborder="0" scrolling="yes" width="100%" height="99%"></iframe>');
$('#iframe-popup').dialog({
autoOpen:true,
title:title,
draggable:true,
@@ -55,83 +55,83 @@ function popupWithIframe(title, cmd, reload, func) {
height:((screen.height / 5) * 4) || 0,
resizable:true,
modal:true,
show:{effect:"fade", duration:250},
hide:{effect:"fade", duration:250},
show:{effect:'fade', duration:250},
hide:{effect:'fade', duration:250},
open:function(ev, ui) {
$("#myIframe").attr("src", cmd);
$('#myIframe').attr('src', cmd);
},
close:function(event, ui) {
if (reload && !$("#myIframe").contents().find("#canvas").length) {
if (reload && !$('#myIframe').contents().find('#canvas').length) {
if (func) setTimeout(func+'()',0); else location = window.location.href;
} else {
resumeEvents();
}
}
});
$(".ui-dialog .ui-dialog-titlebar").addClass("menu");
$(".ui-dialog .ui-dialog-title").css("text-align", "center").css("width", "100%");
$(".ui-dialog .ui-dialog-content").css("padding", "12");
$('.ui-dialog .ui-dialog-titlebar').addClass('menu');
$('.ui-dialog .ui-dialog-title').css('text-align', 'center').css('width', '100%');
$('.ui-dialog .ui-dialog-content').css('padding', '12');
}
function addContainer() {
var path = location.pathname;
var x = path.indexOf("?");
var x = path.indexOf('?');
if (x!=-1) path = path.substring(0,x);
location = path+"/AddContainer";
location = path+'/AddContainer';
}
function editContainer(container, template) {
var path = location.pathname;
var x = path.indexOf("?");
var x = path.indexOf('?');
if (x!=-1) path = path.substring(0, x);
location = path+"/UpdateContainer?xmlTemplate=edit:"+template;
location = path+'/UpdateContainer?xmlTemplate=edit:'+template;
}
function updateContainer(container) {
var body = "Update container: "+container;
var body = 'Update container: '+container;
swal({
title:"Are you sure?",
title:'Are you sure?',
text:body,
type:"warning",
type:'warning',
showCancelButton:true,
confirmButtonColor:"#8CD4F5",
confirmButtonText:"Yes, update it!"
confirmButtonColor:'#8CD4F5',
confirmButtonText:'Yes, update it!'
},function(){
execUpContainer(container);
});
}
function rmContainer(container, image, id) {
var body = "Remove container: "+container+"<br><br><label><input id=\"removeimagechk\" type=\"checkbox\" checked style=\"display:inline; width:unset; height:unset; margin-top:unset; margin-bottom:unset\">also remove image</label>";
var body = 'Remove container: '+container+'<br><br><label><input id="removeimagechk" type="checkbox" checked style="display:inline;width:unset;height:unset;margin-top:unset;margin-bottom:unset">also remove image</label>';
$('input[type=button]').prop('disabled',true);
swal({
title:"Are you sure?",
title:'Are you sure?',
text:body,
type:"warning",
type:'warning',
html:true,
showCancelButton:true,
confirmButtonColor:"#DD6B55",
confirmButtonText:"Yes, delete it!",
confirmButtonColor:'#DD6B55',
confirmButtonText:'Yes, delete it!',
showLoaderOnConfirm:true
},function(){
$('#'+id).find('i').removeClass('fa-play fa-square').addClass('fa-refresh fa-spin');
if ($("#removeimagechk").prop('checked')) {
eventControl({action:"remove_all", container:container, image:image},'loadlist');
},function(c){
if (!c) {setTimeout(loadlist,0); return;}
if ($('#removeimagechk').prop('checked')) {
eventControl({action:'remove_all', container:id, name:container, image:image},'loadlist');
} else {
eventControl({action:"remove_container", container:container},'loadlist');
eventControl({action:'remove_container', container:id, name:container},'loadlist');
}
});
}
function rmImage(image, imageName) {
var body = "Remove image: "+$('<textarea />').html(imageName).text();
var body = 'Remove image: '+$('<textarea />').html(imageName).text();
$('input[type=button]').prop('disabled',true);
swal({
title:"Are you sure?",
title:'Are you sure?',
text:body,
type:"warning",
type:'warning',
showCancelButton:true,
confirmButtonColor:"#DD6B55",
confirmButtonText:"Yes, delete it!",
confirmButtonColor:'#DD6B55',
confirmButtonText:'Yes, delete it!',
showLoaderOnConfirm:true
},function(){
$('#'+image).find('i').removeClass('fa-play fa-square').addClass('fa-refresh fa-spin');
eventControl({action:"remove_image", image:image},'loadlist');
},function(c){
if (!c) {setTimeout(loadlist,0); return;}
eventControl({action:'remove_image', image:image},'loadlist');
});
}
function eventControl(params, spin) {
@@ -141,8 +141,8 @@ function eventControl(params, spin) {
if (spin) setTimeout(spin+'()',500); else location=window.location.href;
} else {
swal({
title:"Execution error", html:true,
text:data.success, type:"error"
title:'Execution error', html:true,
text:data.success, type:'error'
},function(){
if (spin) setTimeout(spin+'()',500); else location=window.location.href;
});
@@ -151,17 +151,17 @@ function eventControl(params, spin) {
}
function startAll() {
$('input[type=button]').prop('disabled',true);
for (var i=0,ct; ct=docker[i]; i++) if (ct.state=='false') $('#'+ct.id).find('i').removeClass('fa-square').addClass('fa-refresh fa-spin');
for (var i=0,ct; ct=docker[i]; i++) if (ct.state==0) $('#'+ct.id).find('i').removeClass('fa-square').addClass('fa-refresh fa-spin');
$.post('/plugins/dynamix.docker.manager/include/ContainerManager.php',{action:'start'},function(){loadlist();});
}
function stopAll() {
$('input[type=button]').prop('disabled',true);
for (var i=0,ct; ct=docker[i]; i++) if (ct.state=='true') $('#'+ct.id).find('i').removeClass('fa-play').addClass('fa-refresh fa-spin');
for (var i=0,ct; ct=docker[i]; i++) if (ct.state==1) $('#'+ct.id).find('i').removeClass('fa-play').addClass('fa-refresh fa-spin');
$.post('/plugins/dynamix.docker.manager/include/ContainerManager.php',{action:'stop'},function(){loadlist();});
}
function checkAll() {
$('input[type=button]').prop('disabled',true);
$(".updatecolumn").html("<span style='color:#267CA8'><i class='fa fa-refresh fa-spin'></i> checking...</span>");
$('.updatecolumn').html('<span style="color:#267CA8"><i class="fa fa-refresh fa-spin"></i> checking...</span>');
$.post('/plugins/dynamix.docker.manager/include/DockerUpdate.php',{check:true},function(u){loadlist(u);});
}
function updateAll() {
@@ -169,7 +169,7 @@ function updateAll() {
$('div.spinner').show('slow');
var list = '';
for (var i=0,ct; ct=docker[i]; i++) if (ct.update=='false') list += '&ct[]='+ct.name;
var address = "/plugins/dynamix.docker.manager/include/CreateDocker.php?updateContainer=true"+list;
var address = '/plugins/dynamix.docker.manager/include/CreateDocker.php?updateContainer=true'+list;
popupWithIframe('Updating all Containers', address, true, 'loadlist');
}
function containerLogs(container, id) {