diff --git a/bin/compose_plantuml b/bin/compose_plantuml index 310394e..79ee54c 100755 --- a/bin/compose_plantuml +++ b/bin/compose_plantuml @@ -16,6 +16,11 @@ if __name__ == '__main__': help='prints the system boundaries', default=False, ) + parser.add_argument( + '--group', action='store_const', const=True, + help='group similar properties together', + default=False, + ) parser.add_argument('files', nargs=argparse.REMAINDER) args = parser.parse_args() plantuml = ComposePlantuml() @@ -30,7 +35,7 @@ if __name__ == '__main__': if args.link_graph: print(plantuml.link_graph(parsed)) if args.boundaries: - print(plantuml.boundaries(parsed)) + print(plantuml.boundaries(parsed, args.group)) if len(args.files) == 0: execute(sys.stdin.read()) diff --git a/compose_plantuml/__init__.py b/compose_plantuml/__init__.py index b2681cb..24f8086 100755 --- a/compose_plantuml/__init__.py +++ b/compose_plantuml/__init__.py @@ -21,7 +21,7 @@ def link_graph(self, compose): result += '[{0}] ..> [{1}] : depends on\n'.format(source, destination) return result.strip() - def boundaries(self, compose): + def boundaries(self, compose, group=False): result = 'skinparam componentStyle uml2\n' result += 'cloud system {\n' @@ -31,25 +31,32 @@ def boundaries(self, compose): result += '}\n' volume_registry = {} + volume_uml = '' for volume in sorted(self.volumes(compose)): if not self.is_volume_used(compose, volume): continue - result += 'database {0}'.format(volume) + ' {\n' + volume_uml += 'database {0}'.format(volume) + ' {\n' for path in sorted(self.volume_usage(compose, volume)): id = self.volume_identifier(volume, path) if id in volume_registry: continue volume_registry[id] = 'volume_{0}'.format(len(volume_registry.keys()) + 1) - result += ' [{0}] as {1}\n'.format(path, volume_registry[id]) + volume_uml += ' [{0}] as {1}\n'.format(path, volume_registry[id]) - result += '}\n' + volume_uml += '}\n' + result += self.group('volumes', volume_uml) if group else volume_uml + port_uml = '' + port_links = '' for service, host, container in sorted(self.ports(compose)): port = host if container is not None: port = '{0} : {1}'.format(host, container) - result += '[{0}] --> {1}\n'.format(service, port) + port_links += '[{0}] --> {1}\n'.format(service, port) + port_uml += 'interface {0}\n'.format(port) + result += self.group('ports', port_uml) if group else '' + result += port_links for volume in sorted(self.volumes(compose)): for service, volume_path in sorted(self.service_using_path(compose, volume)): @@ -59,6 +66,12 @@ def boundaries(self, compose): result += '[{0}] --> {1}\n'.format(service, name) return result.strip() + @staticmethod + def group(name, content): + if len(content) == 0: + return '' + return 'package {0} '.format(name) + '{\n ' + '\n '.join(content.split('\n')).strip() + '\n}\n' + @staticmethod def is_volume_used(compose, volume): components = compose if 'version' not in compose else compose.get('services', {}) diff --git a/features/boundaries.feature b/features/boundaries.feature index 5abae81..6958fc9 100644 --- a/features/boundaries.feature +++ b/features/boundaries.feature @@ -95,6 +95,41 @@ Feature: Boundaries """ + Scenario: Group Volumes and Ports + Given a file named "compose.yml" with: + """ + version: "2" + services: + service: + volumes: + - service_log:/log + ports: + - 8080 + unused_service: {} + volumes: + service_log: {} + unused_volume: {} + """ + When I run `bin/compose_plantuml --boundaries --group compose.yml` + Then it should pass with exactly: + """ + skinparam componentStyle uml2 + cloud system { + [service] + } + package volumes { + database service_log { + [/log] as volume_1 + } + } + package ports { + interface 8080 + } + [service] --> 8080 + [service] --> volume_1 + + """ + Scenario: Suppport for legacy docker-compose format Given a file named "compose.yml" with: """ diff --git a/setup.py b/setup.py index e78156d..b5f06d3 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ def readme(): setup( name='compose_plantuml', - version='0.0.8', + version='0.0.9', description='converts docker-compose into plantuml', long_description=readme(), url='http://github.com/funkwerk/compose_plantuml',