@@ -26,11 +26,14 @@ def boundaries(self, compose):
26
26
27
27
result += 'cloud system {\n '
28
28
for component in sorted (self .components (compose )):
29
- result += ' [{0}]\n ' .format (component )
29
+ if self .has_service_external_ports (compose , component ) or self .has_service_volumes (compose , component ):
30
+ result += ' [{0}]\n ' .format (component )
30
31
result += '}\n '
31
32
volume_registry = {}
32
33
33
34
for volume in sorted (self .volumes (compose )):
35
+ if not self .is_volume_used (compose , volume ):
36
+ continue
34
37
result += 'database {0}' .format (volume ) + ' {\n '
35
38
for path in sorted (self .volume_usage (compose , volume )):
36
39
id = self .volume_identifier (volume , path )
@@ -56,6 +59,57 @@ def boundaries(self, compose):
56
59
result += '[{0}] --> {1}\n ' .format (service , name )
57
60
return result .strip ()
58
61
62
+ @staticmethod
63
+ def is_volume_used (compose , volume ):
64
+ components = compose if 'version' not in compose else compose .get ('services' , {})
65
+
66
+ for _ , component in components .items ():
67
+ for volume_name in component .get ('volumes' , {}):
68
+ if volume_name .startswith ('{0}:' .format (volume )):
69
+ return True
70
+ return False
71
+
72
+ @staticmethod
73
+ def is_service_used (compose , service ):
74
+ components = compose if 'version' not in compose else compose .get ('services' , {})
75
+
76
+ for _ , component in components .items ():
77
+ for link in component .get ('links' , []):
78
+ link = link if ':' not in link else link .split (':' )[0 ]
79
+ if link == service :
80
+ return True
81
+
82
+ for dependency in component .get ('depends_on' , []):
83
+ if dependency == service :
84
+ return True
85
+ return False
86
+
87
+ @staticmethod
88
+ def has_service_external_ports (compose , service ):
89
+ components = compose if 'version' not in compose else compose .get ('services' , {})
90
+
91
+ for name , component in components .items ():
92
+ if service != name :
93
+ continue
94
+ return 'ports' in component
95
+ return False
96
+
97
+ @staticmethod
98
+ def has_service_volumes (compose , service ):
99
+ components = compose if 'version' not in compose else compose .get ('services' , {})
100
+
101
+ for name , component in components .items ():
102
+ if service != name :
103
+ continue
104
+ if 'volumes' not in component :
105
+ return False
106
+ for volume in component ['volumes' ]:
107
+ if volume .startswith ('/' ):
108
+ continue
109
+ if ':' in volume :
110
+ return True
111
+ return False
112
+
59
113
@staticmethod
60
114
def volume_identifier (volume , path ):
61
115
return '{0}.{1}' .format (volume , path )
0 commit comments