Skip to content

Commit 621c7dc

Browse files
committed
group ports and volumes if requested
1 parent 8983b9e commit 621c7dc

File tree

4 files changed

+60
-7
lines changed

4 files changed

+60
-7
lines changed

bin/compose_plantuml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ if __name__ == '__main__':
1616
help='prints the system boundaries',
1717
default=False,
1818
)
19+
parser.add_argument(
20+
'--group', action='store_const', const=True,
21+
help='group similar properties together',
22+
default=False,
23+
)
1924
parser.add_argument('files', nargs=argparse.REMAINDER)
2025
args = parser.parse_args()
2126
plantuml = ComposePlantuml()
@@ -30,7 +35,7 @@ if __name__ == '__main__':
3035
if args.link_graph:
3136
print(plantuml.link_graph(parsed))
3237
if args.boundaries:
33-
print(plantuml.boundaries(parsed))
38+
print(plantuml.boundaries(parsed, args.group))
3439

3540
if len(args.files) == 0:
3641
execute(sys.stdin.read())

compose_plantuml/__init__.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def link_graph(self, compose):
2121
result += '[{0}] ..> [{1}] : depends on\n'.format(source, destination)
2222
return result.strip()
2323

24-
def boundaries(self, compose):
24+
def boundaries(self, compose, group=False):
2525
result = 'skinparam componentStyle uml2\n'
2626

2727
result += 'cloud system {\n'
@@ -31,25 +31,32 @@ def boundaries(self, compose):
3131
result += '}\n'
3232
volume_registry = {}
3333

34+
volume_uml = ''
3435
for volume in sorted(self.volumes(compose)):
3536
if not self.is_volume_used(compose, volume):
3637
continue
37-
result += 'database {0}'.format(volume) + ' {\n'
38+
volume_uml += 'database {0}'.format(volume) + ' {\n'
3839
for path in sorted(self.volume_usage(compose, volume)):
3940
id = self.volume_identifier(volume, path)
4041

4142
if id in volume_registry:
4243
continue
4344
volume_registry[id] = 'volume_{0}'.format(len(volume_registry.keys()) + 1)
44-
result += ' [{0}] as {1}\n'.format(path, volume_registry[id])
45+
volume_uml += ' [{0}] as {1}\n'.format(path, volume_registry[id])
4546

46-
result += '}\n'
47+
volume_uml += '}\n'
48+
result += self.group('volumes', volume_uml) if group else volume_uml
4749

50+
port_uml = ''
51+
port_links = ''
4852
for service, host, container in sorted(self.ports(compose)):
4953
port = host
5054
if container is not None:
5155
port = '{0} : {1}'.format(host, container)
52-
result += '[{0}] --> {1}\n'.format(service, port)
56+
port_links += '[{0}] --> {1}\n'.format(service, port)
57+
port_uml += 'interface {0}\n'.format(port)
58+
result += self.group('ports', port_uml) if group else ''
59+
result += port_links
5360

5461
for volume in sorted(self.volumes(compose)):
5562
for service, volume_path in sorted(self.service_using_path(compose, volume)):
@@ -59,6 +66,12 @@ def boundaries(self, compose):
5966
result += '[{0}] --> {1}\n'.format(service, name)
6067
return result.strip()
6168

69+
@staticmethod
70+
def group(name, content):
71+
if len(content) == 0:
72+
return ''
73+
return 'package {0} '.format(name) + '{\n ' + '\n '.join(content.split('\n')).strip() + '\n}\n'
74+
6275
@staticmethod
6376
def is_volume_used(compose, volume):
6477
components = compose if 'version' not in compose else compose.get('services', {})

features/boundaries.feature

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,41 @@ Feature: Boundaries
9595
9696
"""
9797

98+
Scenario: Group Volumes and Ports
99+
Given a file named "compose.yml" with:
100+
"""
101+
version: "2"
102+
services:
103+
service:
104+
volumes:
105+
- service_log:/log
106+
ports:
107+
- 8080
108+
unused_service: {}
109+
volumes:
110+
service_log: {}
111+
unused_volume: {}
112+
"""
113+
When I run `bin/compose_plantuml --boundaries --group compose.yml`
114+
Then it should pass with exactly:
115+
"""
116+
skinparam componentStyle uml2
117+
cloud system {
118+
[service]
119+
}
120+
package volumes {
121+
database service_log {
122+
[/log] as volume_1
123+
}
124+
}
125+
package ports {
126+
interface 8080
127+
}
128+
[service] --> 8080
129+
[service] --> volume_1
130+
131+
"""
132+
98133
Scenario: Suppport for legacy docker-compose format
99134
Given a file named "compose.yml" with:
100135
"""

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def readme():
77

88
setup(
99
name='compose_plantuml',
10-
version='0.0.8',
10+
version='0.0.9',
1111
description='converts docker-compose into plantuml',
1212
long_description=readme(),
1313
url='http://github.com/funkwerk/compose_plantuml',

0 commit comments

Comments
 (0)