Display extended services
This commit is contained in:
parent
3b49e7102a
commit
83ac062763
5 changed files with 42 additions and 11 deletions
|
@ -1,5 +1,6 @@
|
||||||
# `1.0.0` (unreleased)
|
# `1.0.0` (unreleased)
|
||||||
|
|
||||||
|
* Display extended services as components with inverted arrows
|
||||||
* Display services as components
|
* Display services as components
|
||||||
* Display volumes as folders
|
* Display volumes as folders
|
||||||
* Display ports as circles
|
* Display ports as circles
|
||||||
|
|
|
@ -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 `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`."
|
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
|
## Examples
|
||||||
|
|
||||||
### `dot` renderer
|
### `dot` renderer
|
||||||
|
|
BIN
resources/extends.png
Normal file
BIN
resources/extends.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 15 KiB |
|
@ -66,7 +66,7 @@ $application->register('render')
|
||||||
}
|
}
|
||||||
|
|
||||||
$graph = applyGraphvizStyle(
|
$graph = applyGraphvizStyle(
|
||||||
createGraph($services, $volumes, $networks, $input->getOption('no-volumes') === false),
|
createGraph($services, $volumes, $networks, $input->getOption('no-volumes') === false, $inputFile),
|
||||||
$input->getOption('horizontal')
|
$input->getOption('horizontal')
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -79,16 +79,17 @@ function fetchNetworks(array $configuration) : array
|
||||||
/**
|
/**
|
||||||
* @public
|
* @public
|
||||||
*
|
*
|
||||||
* @param array $services Docker compose service definitions
|
* @param array $services Docker compose service definitions
|
||||||
* @param array $volumes Docker compose volume definitions
|
* @param array $volumes Docker compose volume definitions
|
||||||
* @param array $networks Docker compose network definitions
|
* @param array $networks Docker compose network definitions
|
||||||
* @param bool $withVolumes Create vertices and edges for volumes
|
* @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
|
* @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 = $graph->createGraphClone();
|
||||||
$graph->setAttribute('graphviz.graph.pad', '0.5');
|
$graph->setAttribute('graphviz.graph.pad', '0.5');
|
||||||
|
$graph->setAttribute('graphviz.graph.ratio', 'fill');
|
||||||
|
|
||||||
if ($horizontal === true) {
|
if ($horizontal === true) {
|
||||||
$graph->setAttribute('graphviz.graph.rankdir', 'LR');
|
$graph->setAttribute('graphviz.graph.rankdir', 'LR');
|
||||||
|
@ -162,6 +164,12 @@ function applyGraphvizStyle(Graph $graph, bool $horizontal) : Graph
|
||||||
case 'depends_on':
|
case 'depends_on':
|
||||||
$edge->setAttribute('graphviz.style', 'dotted');
|
$edge->setAttribute('graphviz.style', 'dotted');
|
||||||
break;
|
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) {
|
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
|
* @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) {
|
if ($withVolumes === true) {
|
||||||
foreach (array_keys($volumes) as $volume) {
|
foreach (array_keys($volumes) as $volume) {
|
||||||
addVolume($graph, 'named: '.$volume);
|
addVolume($graph, 'named: '.$volume);
|
||||||
|
@ -205,7 +211,22 @@ function makeVerticesAndEdges(Graph $graph, array $services, array $volumes, arr
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($services as $service => $definition) {
|
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) {
|
foreach ($definition['links'] ?? [] as $link) {
|
||||||
list($target, $alias) = explodeMapping($link);
|
list($target, $alias) = explodeMapping($link);
|
||||||
|
|
Loading…
Reference in a new issue