Merge pull request #339 from shayne/master

Add support for Docker Labels to Docker plugin
This commit is contained in:
tom mortensen
2018-05-07 12:05:47 -07:00
committed by GitHub

View File

@@ -190,6 +190,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++) {
@@ -220,6 +221,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');
@@ -344,6 +350,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;
@@ -376,6 +401,7 @@ function xmlToCommand($xml, $create_paths=false) {
$Volumes = [''];
$Ports = [''];
$Variables = [''];
$Labels = [''];
$Devices = [''];
// Bind Time
$Variables[] = 'TZ="' . $var['timeZone'] . '"';
@@ -409,6 +435,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") {
@@ -416,8 +444,8 @@ 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]);
$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']];
}
@@ -1029,7 +1057,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:');
@@ -1446,7 +1478,7 @@ optgroup.title{background-color:#625D5D;color:#FFFFFF;text-align:center;margin-t
<table class="settings wide">
<tr>
<td></td>
<td><a href="javascript:addConfigPopup()"><i class="fa fa-plus"></i> Add another Path, Port, Variable or Device</a></td>
<td><a href="javascript:addConfigPopup()"><i class="fa fa-plus"></i> Add another Path, Port, Variable, Label or Device</a></td>
</tr>
</table>
<br>
@@ -1479,6 +1511,7 @@ optgroup.title{background-color:#625D5D;color:#FFFFFF;text-align:center;margin-t
<option value="Path">Path</option>
<option value="Port">Port</option>
<option value="Variable">Variable</option>
<option value="Label">Label</option>
<option value="Device">Device</option>
</select>
</dd>