Merge pull request #8 from pmsipilot/extends

Display extended services
This commit is contained in:
Julien BIANCHI 2016-08-06 14:33:52 +02:00 committed by GitHub
commit ec3071e2d6
5 changed files with 42 additions and 11 deletions

View file

@ -1,5 +1,6 @@
# `1.0.0` (unreleased)
* Display extended services as components with inverted arrows
* Display services as components
* Display volumes as folders
* Display ports as circles

View file

@ -97,6 +97,15 @@ Ports (from `services.<service>.ports`) are displayed as circle and are linked t
If we look at the link between port `2480` and `orientdb`, it reads as follow: "traffic coming to host port `2480` will be routed to port `2480` of `orientdb`."
If we look at the link between port `2580` and `elk`, it reads as follow: "traffix coming to host port `2580` will be routed to port `80` of `elk`."
### Extends
Extended services (from `services.<service>.extends`) are displayed as components (just like normal services). The link between them and the extending services are
displayed as inverted arrows:
![ports](resources/extends.png)
If we look at the link between `mysql` and `db`, it reads as follow: "`mysql` extends service `db`".
## Examples
### `dot` renderer

BIN
resources/extends.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View file

@ -66,7 +66,7 @@ $application->register('render')
}
$graph = applyGraphvizStyle(
createGraph($services, $volumes, $networks, $input->getOption('no-volumes') === false),
createGraph($services, $volumes, $networks, $input->getOption('no-volumes') === false, $inputFile),
$input->getOption('horizontal')
);

View file

@ -79,16 +79,17 @@ function fetchNetworks(array $configuration) : array
/**
* @public
*
* @param array $services Docker compose service definitions
* @param array $volumes Docker compose volume definitions
* @param array $networks Docker compose network definitions
* @param bool $withVolumes Create vertices and edges for volumes
* @param array $services Docker compose service definitions
* @param array $volumes Docker compose volume definitions
* @param array $networks Docker compose network definitions
* @param bool $withVolumes Create vertices and edges for volumes
* @param string $path Path of the current docker-compose configuration file
*
* @return Graph The complete graph for the given list of services
*/
function createGraph(array $services, array $volumes, array $networks, bool $withVolumes = true) : Graph
function createGraph(array $services, array $volumes, array $networks, bool $withVolumes, string $path) : Graph
{
return makeVerticesAndEdges(new Graph(), $services, $volumes, $networks, $withVolumes);
return makeVerticesAndEdges(new Graph(), $services, $volumes, $networks, $withVolumes, $path);
}
/**
@ -103,6 +104,7 @@ function applyGraphvizStyle(Graph $graph, bool $horizontal) : Graph
{
$graph = $graph->createGraphClone();
$graph->setAttribute('graphviz.graph.pad', '0.5');
$graph->setAttribute('graphviz.graph.ratio', 'fill');
if ($horizontal === true) {
$graph->setAttribute('graphviz.graph.rankdir', 'LR');
@ -162,6 +164,12 @@ function applyGraphvizStyle(Graph $graph, bool $horizontal) : Graph
case 'depends_on':
$edge->setAttribute('graphviz.style', 'dotted');
break;
case 'extends':
$edge->setAttribute('graphviz.dir', 'both');
$edge->setAttribute('graphviz.arrowhead', 'inv');
$edge->setAttribute('graphviz.arrowtail', 'dot');
break;
}
if (($alias = $edge->getAttribute('docker_compose.alias')) !== null) {
@ -187,10 +195,8 @@ function applyGraphvizStyle(Graph $graph, bool $horizontal) : Graph
*
* @return Graph A copy of the input graph with vertices and edges for services
*/
function makeVerticesAndEdges(Graph $graph, array $services, array $volumes, array $networks, bool $withVolumes) : Graph
function makeVerticesAndEdges(Graph $graph, array $services, array $volumes, array $networks, bool $withVolumes, $path) : Graph
{
$graph = $graph->createGraphClone();
if ($withVolumes === true) {
foreach (array_keys($volumes) as $volume) {
addVolume($graph, 'named: '.$volume);
@ -205,7 +211,22 @@ function makeVerticesAndEdges(Graph $graph, array $services, array $volumes, arr
}
foreach ($services as $service => $definition) {
$vertices[$service] = addService($graph, $service);
addService($graph, $service);
if (isset($definition['extends'])) {
$configuration = readConfiguration(dirname($path).DIRECTORY_SEPARATOR.$definition['extends']['file']);
$extendedServices = fetchServices($configuration);
$extendedVolumes = fetchVolumes($configuration);
$extendedNetworks = fetchVolumes($configuration);
$graph = makeVerticesAndEdges($graph, $extendedServices, $extendedVolumes, $extendedNetworks, $withVolumes, dirname($path).DIRECTORY_SEPARATOR.$definition['extends']['file']);
addRelation(
addService($graph, $definition['extends']['service']),
$graph->getVertex($service),
'extends'
);
}
foreach ($definition['links'] ?? [] as $link) {
list($target, $alias) = explodeMapping($link);