diff --git a/CHANGELOG.md b/CHANGELOG.md index e67cfa3..0d1d68b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index 76f21fc..39389b9 100644 --- a/README.md +++ b/README.md @@ -97,6 +97,15 @@ Ports (from `services..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..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 diff --git a/resources/extends.png b/resources/extends.png new file mode 100644 index 0000000..1657916 Binary files /dev/null and b/resources/extends.png differ diff --git a/src/application.php b/src/application.php index 3a61d69..754c6f8 100644 --- a/src/application.php +++ b/src/application.php @@ -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') ); diff --git a/src/functions.php b/src/functions.php index 02c72da..e4f32fa 100644 --- a/src/functions.php +++ b/src/functions.php @@ -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);