fix: Volume labels are correct (#49)

Closes #45
This commit is contained in:
Julien BIANCHI 2020-07-23 22:35:06 +02:00 committed by GitHub
parent e1ad47ee9e
commit 03ab873e22
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -309,7 +309,7 @@ function makeVerticesAndEdges(Graph $graph, array $services, array $volumes, arr
$container = $volume['target']; $container = $volume['target'];
$attr = !empty($volume['read-only']) ? 'ro' : ''; $attr = !empty($volume['read-only']) ? 'ro' : '';
} else { } else {
list($host, $container, $attr) = explodeMapping($volume); list($host, $container, $attr) = explodeVolumeMapping($volume);
} }
$serviceVolumes[$container] = [$host, $attr]; $serviceVolumes[$container] = [$host, $attr];
@ -506,13 +506,23 @@ function explodeMapping($mapping): array
$parts = explode(':', $mapping); $parts = explode(':', $mapping);
$parts[1] = $parts[1] ?? $parts[0]; $parts[1] = $parts[1] ?? $parts[0];
$subparts = array_values(array_filter(explode('/', $parts[1]))); return [$parts[0], $parts[1]];
if (count($subparts) > 2) {
$subparts = [$parts[1], $parts[2] ?? null];
} }
return [$parts[0], $subparts[0], $subparts[1] ?? null]; /**
* @internal
*
* @param string $mapping A docker mapping (<from>[:<to>])
*
* @return array An 2 or 3 items array containing the parts of the mapping.
* If the mapping does not specify a second part, the first one will be repeated
*/
function explodeVolumeMapping($mapping): array
{
$parts = explode(':', $mapping);
$parts[1] = $parts[1] ?? $parts[0];
return [$parts[0], $parts[1], $parts[2] ?? null];
} }
/** /**