From 32067e89b41db0c8a407ad7625975c920b49d37f Mon Sep 17 00:00:00 2001 From: Shayne Sweeney Date: Sun, 6 May 2018 21:55:51 -0700 Subject: [PATCH 1/2] Add support for Docker Labels to Docker plugin Docker object labels: https://docs.docker.com/config/labels-custom-metadata/ More and more containers are taking advantage of container metadata where environment variables are not necessary. Traefik is a good example: https://docs.traefik.io/configuration/backends/docker/#on-containers --- .../include/CreateDocker.php | 39 +++++++++++++++++-- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/plugins/dynamix.docker.manager/include/CreateDocker.php b/plugins/dynamix.docker.manager/include/CreateDocker.php index ebe910932..0d205ad82 100644 --- a/plugins/dynamix.docker.manager/include/CreateDocker.php +++ b/plugins/dynamix.docker.manager/include/CreateDocker.php @@ -192,6 +192,7 @@ function postToXML($post, $setOwnership=false) { $xml->Networking->addChild("Publish"); $xml->addChild("Data"); $xml->addChild("Environment"); + $xml->addChild("Labels"); $size = is_array($post['confName']) ? count($post['confName']) : 0; for ($i = 0; $i < $size; $i++) { @@ -222,6 +223,11 @@ function postToXML($post, $setOwnership=false) { $variable->Value = $post['confValue'][$i]; $variable->Name = $post['confTarget'][$i]; $variable->Mode = $post['confMode'][$i]; + } elseif ($Type == 'Label') { + $label = $xml->Labels->addChild("Label"); + $label->Value = $post['confValue'][$i]; + $label->Name = $post['confTarget'][$i]; + $label->Mode = $post['confMode'][$i]; } } $dom = new DOMDocument('1.0'); @@ -346,6 +352,25 @@ function xmlToVar($xml) { ]; } } + if (isset($xml->Labels->Variable)) { + $varNum = 0; + foreach ($xml->Labels->Variable as $varitem) { + if (empty(xml_decode($varitem->Name))) continue; + $varNum += 1; + $out['Config'][] = [ + 'Name' => "Label ${varNum}", + 'Target' => xml_decode($varitem->Name), + 'Default' => xml_decode($varitem->Value), + 'Value' => xml_decode($varitem->Value), + 'Mode' => '', + 'Description' => 'Container Label: '.xml_decode($varitem->Name), + 'Type' => 'Label', + 'Display' => 'always', + 'Required' => 'false', + 'Mask' => 'false' + ]; + } + } } xmlSecurity($out); return $out; @@ -378,6 +403,7 @@ function xmlToCommand($xml, $create_paths=false) { $Volumes = ['']; $Ports = ['']; $Variables = ['']; + $Labels = ['']; $Devices = ['']; // Bind Time $Variables[] = 'TZ="' . $var['timeZone'] . '"'; @@ -411,6 +437,8 @@ function xmlToCommand($xml, $create_paths=false) { case 'none': // No export of ports if network is set to none } + } elseif ($confType == "label") { + $Labels[] = escapeshellarg($containerConfig).'='.escapeshellarg($hostConfig); } elseif ($confType == "variable") { $Variables[] = escapeshellarg($containerConfig).'='.escapeshellarg($hostConfig); } elseif ($confType == "device") { @@ -419,7 +447,7 @@ function xmlToCommand($xml, $create_paths=false) { } $postArgs = explode(";",$xml['PostArgs']); $cmd = sprintf($docroot.'/plugins/dynamix.docker.manager/scripts/docker create %s %s %s %s %s %s %s %s %s %s %s', - $cmdName, $cmdNetwork, $cmdMyIP, $cmdPrivileged, implode(' -e ', $Variables), implode(' -p ', $Ports), implode(' -v ', $Volumes), implode(' --device=', $Devices), $xml['ExtraParams'], escapeshellarg($xml['Repository']), $postArgs[0]); + $cmdName, $cmdNetwork, $cmdMyIP, $cmdPrivileged, implode(' -e ', $Variables), implode(' -l ', $Labels), implode(' -p ', $Ports), implode(' -v ', $Volumes), implode(' --device=', $Devices), $xml['ExtraParams'], escapeshellarg($xml['Repository']), $postArgs[0]); return [preg_replace('/\s+/', ' ', $cmd), $xml['Name'], $xml['Repository']]; } @@ -1033,7 +1061,11 @@ optgroup.title{background-color:#625D5D;color:#FFFFFF;text-align:center;margin-t targetDiv.find('#dt1').text('Key:'); valueDiv.find('#dt2').text('Value:'); break; - case 3: // Device + case 3: // Label + targetDiv.find('#dt1').text('Key:'); + valueDiv.find('#dt2').text('Value:'); + break; + case 4: // Device targetDiv.hide(); defaultDiv.hide(); valueDiv.find('#dt2').text('Value:'); @@ -1450,7 +1482,7 @@ optgroup.title{background-color:#625D5D;color:#FFFFFF;text-align:center;margin-t - +
Add another Path, Port, Variable or Device Add another Path, Port, Variable, Label or Device

@@ -1483,6 +1515,7 @@ optgroup.title{background-color:#625D5D;color:#FFFFFF;text-align:center;margin-t + From c1c99f69e1b8347e2598ce6c32e1d96b587df3de Mon Sep 17 00:00:00 2001 From: Shayne Sweeney Date: Mon, 7 May 2018 08:53:13 -0700 Subject: [PATCH 2/2] Add additional %s --- plugins/dynamix.docker.manager/include/CreateDocker.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/dynamix.docker.manager/include/CreateDocker.php b/plugins/dynamix.docker.manager/include/CreateDocker.php index 0d205ad82..468c5324e 100644 --- a/plugins/dynamix.docker.manager/include/CreateDocker.php +++ b/plugins/dynamix.docker.manager/include/CreateDocker.php @@ -446,7 +446,7 @@ function xmlToCommand($xml, $create_paths=false) { } } $postArgs = explode(";",$xml['PostArgs']); - $cmd = sprintf($docroot.'/plugins/dynamix.docker.manager/scripts/docker create %s %s %s %s %s %s %s %s %s %s %s', + $cmd = sprintf($docroot.'/plugins/dynamix.docker.manager/scripts/docker create %s %s %s %s %s %s %s %s %s %s %s %s', $cmdName, $cmdNetwork, $cmdMyIP, $cmdPrivileged, implode(' -e ', $Variables), implode(' -l ', $Labels), implode(' -p ', $Ports), implode(' -v ', $Volumes), implode(' --device=', $Devices), $xml['ExtraParams'], escapeshellarg($xml['Repository']), $postArgs[0]); return [preg_replace('/\s+/', ' ', $cmd), $xml['Name'], $xml['Repository']]; }