diff --git a/compose_viz/models/service.py b/compose_viz/models/service.py index 89740ba..abd94f6 100644 --- a/compose_viz/models/service.py +++ b/compose_viz/models/service.py @@ -16,6 +16,12 @@ class Service: depends_on: List[str] = [], links: List[str] = [], extends: Optional[Extends] = None, + cgroup_parent: Optional[str] = None, + container_name: Optional[str] = None, + devices: List[str] = [], + env_file: List[str] = [], + expose: List[str] = [], + profiles: List[str] = [], ) -> None: self._name = name self._image = image @@ -25,6 +31,12 @@ class Service: self._depends_on = depends_on self._links = links self._extends = extends + self.cgroup_parent = cgroup_parent + self.container_name = container_name + self.devices = devices + self.env_file = env_file + self.expose = expose + self.profiles = profiles @property def name(self): diff --git a/compose_viz/parser.py b/compose_viz/parser.py index 63139d4..6f296d4 100644 --- a/compose_viz/parser.py +++ b/compose_viz/parser.py @@ -176,6 +176,32 @@ class Parser: if service_data.links is not None: service_links = service_data.links + cgroup_parent: Optional[str] = None + if service_data.cgroup_parent is not None: + cgroup_parent = service_data.cgroup_parent + + container_name: Optional[str] = None + if service_data.container_name is not None: + container_name = service_data.container_name + + env_file: List[str] = [] + if service_data.env_file is not None: + if type(service_data.env_file) is spec.StringOrList: + if type(service_data.env_file.__root__) is spec.ListOfStrings: + env_file = service_data.env_file.__root__.__root__ + elif type(service_data.env_file.__root__) is str: + env_file.append(service_data.env_file.__root__) + + expose: List[str] = [] + if service_data.expose is not None: + for port in service_data.expose: + expose.append(str(port)) + + profiles: List[str] = [] + if service_data.profiles is not None: + if type(service_data.profiles) is spec.ListOfStrings: + profiles = service_data.profiles.__root__ + services.append( Service( name=service_name, @@ -186,6 +212,11 @@ class Parser: depends_on=service_depends_on, volumes=service_volumes, links=service_links, + cgroup_parent=cgroup_parent, + container_name=container_name, + env_file=env_file, + expose=expose, + profiles=profiles, ) ) diff --git a/tests/test_parse_file.py b/tests/test_parse_file.py index 7bf3cdc..226d755 100644 --- a/tests/test_parse_file.py +++ b/tests/test_parse_file.py @@ -241,6 +241,91 @@ from compose_viz.parser import Parser ], ), ), + ( + "cgroup_parent/docker-compose", + Compose( + services=[ + Service( + name="frontend", + image="awesome/frontend", + cgroup_parent="system", + ), + ], + ), + ), + ( + "container_name/docker-compose", + Compose( + services=[ + Service( + name="frontend", + image="awesome/frontend", + container_name="myfrontend", + ), + ], + ), + ), + ( + "env_file/docker-compose", + Compose( + services=[ + Service( + name="frontend", + image="awesome/frontend", + env_file=["a.env"], + ), + Service( + name="backend", + image="awesome/backend", + env_file=["b.env"], + ), + Service( + name="db", + image="awesome/db", + env_file=["c.env", "d.env"], + ), + ], + ), + ), + ( + "expose/docker-compose", + Compose( + services=[ + Service( + name="frontend", + image="awesome/frontend", + expose=["27118"], + ), + Service( + name="backend", + image="awesome/backend", + expose=["27017", "27018"], + ), + ], + ), + ), + ( + "profiles/docker-compose", + Compose( + services=[ + Service( + name="frontend", + image="awesome/frontend", + profiles=["frontend"], + ), + Service( + name="phpmyadmin", + image="phpmyadmin", + profiles=["debug"], + ), + Service( + name="db", + image="awesome/db", + profiles=["db", "sql"], + ), + ], + ), + ), ], ) def test_parse_file(test_file_path: str, expected: Compose) -> None: @@ -275,3 +360,10 @@ def test_parse_file(test_file_path: str, expected: Compose) -> None: if (actual_service.extends is not None) and (expected_service.extends is not None): assert actual_service.extends.service_name == expected_service.extends.service_name assert actual_service.extends.from_file == expected_service.extends.from_file + + assert actual_service.cgroup_parent == expected_service.cgroup_parent + assert actual_service.container_name == expected_service.container_name + + assert actual_service.expose == expected_service.expose + assert actual_service.env_file == expected_service.env_file + assert actual_service.profiles == expected_service.profiles diff --git a/tests/ymls/cgroup_parent/docker-compose.yml b/tests/ymls/cgroup_parent/docker-compose.yml new file mode 100644 index 0000000..6d41ad4 --- /dev/null +++ b/tests/ymls/cgroup_parent/docker-compose.yml @@ -0,0 +1,6 @@ +version: "3.9" + +services: + frontend: + image: awesome/frontend + cgroup_parent: "system" diff --git a/tests/ymls/container_name/docker-compose.yml b/tests/ymls/container_name/docker-compose.yml new file mode 100644 index 0000000..08047c2 --- /dev/null +++ b/tests/ymls/container_name/docker-compose.yml @@ -0,0 +1,6 @@ +version: "3.9" + +services: + frontend: + image: awesome/frontend + container_name: "myfrontend" diff --git a/tests/ymls/devices/docker-compose.yml b/tests/ymls/devices/docker-compose.yml new file mode 100644 index 0000000..f3fa6f8 --- /dev/null +++ b/tests/ymls/devices/docker-compose.yml @@ -0,0 +1,12 @@ +version: "3.9" + +services: + frontend: + image: awesome/frontend + devices: + - "/dev/ttyUSB0:/dev/ttyUSB0" + backend: + image: awesome/backend + devices: + - "/dev/ttyUSB1:/dev/ttyUSB1" + - "/dev/ttyUSB2:/dev/ttyUSB2" diff --git a/tests/ymls/env_file/docker-compose.yml b/tests/ymls/env_file/docker-compose.yml new file mode 100644 index 0000000..d687153 --- /dev/null +++ b/tests/ymls/env_file/docker-compose.yml @@ -0,0 +1,15 @@ +version: "3.9" + +services: + frontend: + image: awesome/frontend + env_file: a.env + backend: + image: awesome/backend + env_file: + - b.env + db: + image: awesome/db + env_file: + - c.env + - d.env diff --git a/tests/ymls/expose/docker-compose.yml b/tests/ymls/expose/docker-compose.yml new file mode 100644 index 0000000..1e1bdee --- /dev/null +++ b/tests/ymls/expose/docker-compose.yml @@ -0,0 +1,12 @@ +version: "3.9" + +services: + frontend: + image: awesome/frontend + expose: + - "27118" + backend: + image: awesome/backend + expose: + - "27017" + - "27018" diff --git a/tests/ymls/profiles/docker-compose.yml b/tests/ymls/profiles/docker-compose.yml new file mode 100644 index 0000000..39282af --- /dev/null +++ b/tests/ymls/profiles/docker-compose.yml @@ -0,0 +1,14 @@ +version: "3.9" +services: + frontend: + image: awesome/frontend + profiles: ["frontend"] + phpmyadmin: + image: phpmyadmin + profiles: + - debug + db: + image: awesome/db + profiles: + - db + - sql