Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Volume labels are correct #49

Merged
merged 1 commit into from
Jul 23, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ function makeVerticesAndEdges(Graph $graph, array $services, array $volumes, arr
$container = $volume['target'];
$attr = !empty($volume['read-only']) ? 'ro' : '';
} else {
list($host, $container, $attr) = explodeMapping($volume);
list($host, $container, $attr) = explodeVolumeMapping($volume);
}

$serviceVolumes[$container] = [$host, $attr];
Expand Down Expand Up @@ -506,13 +506,23 @@ function explodeMapping($mapping): array
$parts = explode(':', $mapping);
$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];
}
/**
* @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], $subparts[0], $subparts[1] ?? null];
return [$parts[0], $parts[1], $parts[2] ?? null];
}

/**
Expand Down