From 155f0e1fad3f6df7d68ae4211d84746134806b6f Mon Sep 17 00:00:00 2001 From: jubianchi Date: Fri, 17 Nov 2017 00:15:11 +0100 Subject: [PATCH 1/3] fix: Handle conditions in depends_on Closes #22 --- src/functions.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/functions.php b/src/functions.php index 3ac1fa8..ea031a9 100644 --- a/src/functions.php +++ b/src/functions.php @@ -256,10 +256,10 @@ function makeVerticesAndEdges(Graph $graph, array $services, array $volumes, arr ); } - foreach ($definition['depends_on'] ?? [] as $dependency) { + foreach ($definition['depends_on'] ?? [] as $key => $dependency) { addRelation( $graph->getVertex($service), - addService($graph, $dependency), + addService($graph, is_array($dependency) ? $key : $dependency), 'depends_on' ); } From 1eb3843a453e36a043db8f6cd5abcc37c44a0b37 Mon Sep 17 00:00:00 2001 From: jubianchi Date: Fri, 17 Nov 2017 00:36:54 +0100 Subject: [PATCH 2/3] feat: Display depends_on conditions See #22 --- src/functions.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/functions.php b/src/functions.php index ea031a9..8dbf7b2 100644 --- a/src/functions.php +++ b/src/functions.php @@ -174,6 +174,10 @@ function applyGraphvizStyle(Graph $graph, bool $horizontal) : Graph if (($alias = $edge->getAttribute('docker_compose.alias')) !== null) { $edge->setAttribute('graphviz.label', $alias); + + if ($edge->getAttribute('docker_compose.condition') !== null) { + $edge->setAttribute('graphviz.fontsize', '10'); + } } if ($edge->getAttribute('docker_compose.bidir')) { @@ -260,7 +264,10 @@ function makeVerticesAndEdges(Graph $graph, array $services, array $volumes, arr addRelation( $graph->getVertex($service), addService($graph, is_array($dependency) ? $key : $dependency), - 'depends_on' + 'depends_on', + is_array($dependency) && isset($dependency['condition']) ? $dependency['condition'] : null, + false, + is_array($dependency) && isset($dependency['condition']) ); } @@ -418,10 +425,11 @@ function addNetwork(Graph $graph, string $name, string $type = null) * @param string $type Type of the relation (one of "links", "volumes_from", "depends_on", "ports"); * @param string|null $alias Alias associated to the linked element * @param bool|null $bidirectional Biderectional or not + * @param bool|null $condition Wether the alias represents a condition or not * * @return Edge\Directed */ -function addRelation(Vertex $from, Vertex $to, string $type, string $alias = null, bool $bidirectional = false) : Edge\Directed +function addRelation(Vertex $from, Vertex $to, string $type, string $alias = null, bool $bidirectional = false, bool $condition = false) : Edge\Directed { $edge = null; @@ -445,6 +453,10 @@ function addRelation(Vertex $from, Vertex $to, string $type, string $alias = nul $edge->setAttribute('docker_compose.alias', $alias); } + if (true === $condition) { + $edge->setAttribute('docker_compose.condition', true); + } + $edge->setAttribute('docker_compose.bidir', $bidirectional); return $edge; From 9a87507a83840854c27119e4b278417131fa5d7e Mon Sep 17 00:00:00 2001 From: jubianchi Date: Fri, 17 Nov 2017 00:38:43 +0100 Subject: [PATCH 3/3] chore: Update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index faabed3..2dc92e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # `1.1.0` (unreleased) +* Display `depends_on` conditions +* Handle conditions in `depends_on` * Automatically load override file if it exists or ignore it using `--ignore-override` # `1.0.0`