diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 912e441..bcfde75 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,77 +20,21 @@ jobs: sudo apt-get update sudo apt-get install -y graphviz + - name: Validate Test Files + run: | + docker compose -f tests/ymls/builds/docker-compose.yml config -q + docker compose -f tests/ymls/depends_on/docker-compose.yml config -q + docker compose -f tests/ymls/extends/docker-compose.yml config -q + docker compose -f tests/ymls/links/docker-compose.yml config -q + docker compose -f tests/ymls/networks/docker-compose.yml config -q + docker compose -f tests/ymls/ports/docker-compose.yml config -q + docker compose -f tests/ymls/volumes/docker-compose.yml config -q + - name: Setup Python 3.10.4 uses: actions/setup-python@v3 with: python-version: '3.10.4' - - name: Validate Test Files - run: | - docker-compose -f tests/in/000001.yaml config -q - docker-compose -f tests/in/000010.yaml config -q - docker-compose -f tests/in/000011.yaml config -q - docker-compose -f tests/in/000100.yaml config -q - docker-compose -f tests/in/000101.yaml config -q - docker-compose -f tests/in/000110.yaml config -q - docker-compose -f tests/in/000111.yaml config -q - docker-compose -f tests/in/001000.yaml config -q - docker-compose -f tests/in/001001.yaml config -q - docker-compose -f tests/in/001010.yaml config -q - docker-compose -f tests/in/001011.yaml config -q - docker-compose -f tests/in/001100.yaml config -q - docker-compose -f tests/in/001101.yaml config -q - docker-compose -f tests/in/001110.yaml config -q - docker-compose -f tests/in/001111.yaml config -q - docker-compose -f tests/in/010000.yaml config -q - docker-compose -f tests/in/010001.yaml config -q - docker-compose -f tests/in/010010.yaml config -q - docker-compose -f tests/in/010011.yaml config -q - docker-compose -f tests/in/010100.yaml config -q - docker-compose -f tests/in/010101.yaml config -q - docker-compose -f tests/in/010110.yaml config -q - docker-compose -f tests/in/010111.yaml config -q - docker-compose -f tests/in/011000.yaml config -q - docker-compose -f tests/in/011001.yaml config -q - docker-compose -f tests/in/011010.yaml config -q - docker-compose -f tests/in/011011.yaml config -q - docker-compose -f tests/in/011100.yaml config -q - docker-compose -f tests/in/011101.yaml config -q - docker-compose -f tests/in/011110.yaml config -q - docker-compose -f tests/in/011111.yaml config -q - docker-compose -f tests/in/100000.yaml config -q - docker-compose -f tests/in/100001.yaml config -q - docker-compose -f tests/in/100010.yaml config -q - docker-compose -f tests/in/100011.yaml config -q - docker-compose -f tests/in/100100.yaml config -q - docker-compose -f tests/in/100101.yaml config -q - docker-compose -f tests/in/100110.yaml config -q - docker-compose -f tests/in/100111.yaml config -q - docker-compose -f tests/in/101000.yaml config -q - docker-compose -f tests/in/101001.yaml config -q - docker-compose -f tests/in/101010.yaml config -q - docker-compose -f tests/in/101011.yaml config -q - docker-compose -f tests/in/101100.yaml config -q - docker-compose -f tests/in/101101.yaml config -q - docker-compose -f tests/in/101110.yaml config -q - docker-compose -f tests/in/101111.yaml config -q - docker-compose -f tests/in/110000.yaml config -q - docker-compose -f tests/in/110001.yaml config -q - docker-compose -f tests/in/110010.yaml config -q - docker-compose -f tests/in/110011.yaml config -q - docker-compose -f tests/in/110100.yaml config -q - docker-compose -f tests/in/110101.yaml config -q - docker-compose -f tests/in/110110.yaml config -q - docker-compose -f tests/in/110111.yaml config -q - docker-compose -f tests/in/111000.yaml config -q - docker-compose -f tests/in/111001.yaml config -q - docker-compose -f tests/in/111010.yaml config -q - docker-compose -f tests/in/111011.yaml config -q - docker-compose -f tests/in/111100.yaml config -q - docker-compose -f tests/in/111101.yaml config -q - docker-compose -f tests/in/111110.yaml config -q - docker-compose -f tests/in/111111.yaml config -q - - name: Setup Poetry uses: Gr1N/setup-poetry@v7 with: diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 29b731d..4999367 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,7 +2,7 @@ exclude: | (?x)^( README.md| LICENSE| - tests/in/invalid.yaml + tests/ymls/ ) repos: - repo: https://github.com/pre-commit/pre-commit-hooks diff --git a/compose_viz/parser.py b/compose_viz/parser.py index 0f7a5a3..2440bce 100644 --- a/compose_viz/parser.py +++ b/compose_viz/parser.py @@ -6,7 +6,7 @@ from ruamel.yaml import YAML from compose_viz.compose import Compose, Service from compose_viz.extends import Extends from compose_viz.port import Port, Protocol -from compose_viz.volume import AccessMode, Volume, VolumeType +from compose_viz.volume import Volume, VolumeType class Parser: @@ -40,10 +40,14 @@ class Parser: for service, service_name in zip(services_yaml_data.values(), services_yaml_data.keys()): service_image: Optional[str] = None - if service.get("image"): + if service.get("build"): + if type(service["build"]) is str: + service_image = "build from " + service["build"] + elif type(service["build"]) is dict: + assert service["build"].get("context"), "Missing build context, aborting." + service_image = "build from " + str(service["build"]["context"]) + elif service.get("image"): service_image = service["image"] - elif service.get("build"): - service_image = "build from " + service["build"] service_networks: List[str] = [] if service.get("networks"): @@ -54,8 +58,16 @@ class Parser: service_extends: Optional[Extends] = None if service.get("extends"): - if service["extends"].get("service"): - service_extends = Extends(service_name=service["extends"]["service"]) + assert type(service["extends"]) is dict, "Invalid extends format, aborting." + assert service["extends"]["service"], "Missing extends service, aborting." + extend_service_name = str(service["extends"]["service"]) + + extend_from_file: Optional[str] = None + if service["extends"].get("file"): + assert service["extends"]["file"], "Missing extends file, aborting." + extend_from_file = str(service["extends"]["file"]) + + service_extends = Extends(service_name=extend_service_name, from_file=extend_from_file) service_ports: List[Port] = [] if service.get("ports"): @@ -69,7 +81,7 @@ class Parser: container_port: str = str(port_data["target"]) host_port: str = "" - protocol: Protocol = Protocol.tcp + protocol: Protocol = Protocol.any if port_data.get("published"): host_port = str(port_data["published"]) @@ -79,6 +91,8 @@ class Parser: if port_data.get("host_ip"): host_ip = str(port_data["host_ip"]) host_port = f"{host_ip}:{host_port}" + else: + host_port = f"0.0.0.0:{host_port}" if port_data.get("protocol"): protocol = Protocol[str(port_data["protocol"])] @@ -122,6 +136,8 @@ class Parser: if host_ip: host_port = f"{host_ip}{host_port}" + else: + host_port = f"0.0.0.0:{host_port}" assert host_port, "Error while parsing port, aborting." @@ -174,9 +190,7 @@ class Parser: service_volumes.append(Volume(source=spilt_data[0], target=spilt_data[1])) elif len(spilt_data) == 3: service_volumes.append( - Volume( - source=spilt_data[0], target=spilt_data[1], access_mode=AccessMode[spilt_data[2]] - ) + Volume(source=spilt_data[0], target=spilt_data[1], access_mode=spilt_data[2]) ) service_links: List[str] = [] diff --git a/compose_viz/port.py b/compose_viz/port.py index c2b1646..d64fb5c 100644 --- a/compose_viz/port.py +++ b/compose_viz/port.py @@ -4,10 +4,11 @@ from enum import Enum class Protocol(str, Enum): tcp = "tcp" udp = "udp" + any = "any" class Port: - def __init__(self, host_port: str, container_port: str, protocol: Protocol = Protocol.tcp): + def __init__(self, host_port: str, container_port: str, protocol: Protocol = Protocol.any): self._host_port = host_port self._container_port = container_port self._protocol = protocol diff --git a/compose_viz/service.py b/compose_viz/service.py index c238576..b1bf84b 100644 --- a/compose_viz/service.py +++ b/compose_viz/service.py @@ -18,13 +18,6 @@ class Service: extends: Optional[Extends] = None, ) -> None: self._name = name - - if image is None and extends is None: - raise AttributeError(f"Both image and extends are not defined in service '{name}', aborting.") - - if image is not None and extends is not None: - raise AttributeError(f"Only one of image and extends can be defined in service '{name}', aborting.") - self._image = image self._ports = ports self._networks = networks diff --git a/compose_viz/volume.py b/compose_viz/volume.py index f86d203..192ed97 100644 --- a/compose_viz/volume.py +++ b/compose_viz/volume.py @@ -8,17 +8,8 @@ class VolumeType(str, Enum): npipe = "npipe" -class AccessMode(str, Enum): - rw = "rw" - ro = "ro" - z = "z" - Z = "Z" - - class Volume: - def __init__( - self, source: str, target: str, type: VolumeType = VolumeType.volume, access_mode: AccessMode = AccessMode.rw - ): + def __init__(self, source: str, target: str, type: VolumeType = VolumeType.volume, access_mode: str = "rw"): self._source = source self._target = target self._type = type diff --git a/tests/in/000010.yaml b/tests/in/000010.yaml deleted file mode 100644 index 377b994..0000000 --- a/tests/in/000010.yaml +++ /dev/null @@ -1,10 +0,0 @@ -services: - base: - image: busybox - user: root - common: - extends: - service: base - cli: - extends: - service: common diff --git a/tests/in/000011.yaml b/tests/in/000011.yaml deleted file mode 100644 index d17efbe..0000000 --- a/tests/in/000011.yaml +++ /dev/null @@ -1,28 +0,0 @@ -services: - frontend: - image: awesome/webapp - networks: - - front-tier - - back-tier - - monitoring: - networks: - - admin - extends: - service: frontend - - backend: - networks: - back-tier: - aliases: - - database - admin: - aliases: - - mysql - extends: - service: frontend - -networks: - front-tier: - back-tier: - admin: diff --git a/tests/in/000100.yaml b/tests/in/000100.yaml deleted file mode 100644 index 058aa18..0000000 --- a/tests/in/000100.yaml +++ /dev/null @@ -1,8 +0,0 @@ -version: "3.9" -services: - web: - build: . - ports: - - "8080" - redis: - image: "redis:alpine" diff --git a/tests/in/000101.yaml b/tests/in/000101.yaml deleted file mode 100644 index a92a5f1..0000000 --- a/tests/in/000101.yaml +++ /dev/null @@ -1,35 +0,0 @@ -services: - frontend: - image: awesome/webapp - ports: - - target: 80 - host_ip: 127.0.0.1 - published: 8080 - protocol: udp - networks: - - front-tier - - back-tier - - monitoring: - image: awesome/monitoring - ports: - - "127.0.0.1:8081:5001" - networks: - - admin - - backend: - image: awesome/backend - ports: - - "8000:5010/udp" - networks: - back-tier: - aliases: - - database - admin: - aliases: - - mysql - -networks: - front-tier: - back-tier: - admin: diff --git a/tests/in/000110.yaml b/tests/in/000110.yaml deleted file mode 100644 index ff82c1c..0000000 --- a/tests/in/000110.yaml +++ /dev/null @@ -1,15 +0,0 @@ -services: - frontend: - image: awesome/webapp - ports: - - target: 80 - - monitoring: - extends: - service: frontend - - backend: - extends: - service: frontend - ports: - - "8000:5001" diff --git a/tests/in/000111.yaml b/tests/in/000111.yaml deleted file mode 100644 index c17fb18..0000000 --- a/tests/in/000111.yaml +++ /dev/null @@ -1,32 +0,0 @@ -services: - frontend: - image: awesome/webapp - networks: - - front-tier - - back-tier - ports: - - "8000:5000" - - monitoring: - networks: - - admin - extends: - service: frontend - - backend: - networks: - back-tier: - aliases: - - database - admin: - aliases: - - mysql - extends: - service: frontend - ports: - - "8000:5001" - -networks: - front-tier: - back-tier: - admin: diff --git a/tests/in/001000.yaml b/tests/in/001000.yaml deleted file mode 100644 index 36d2b3e..0000000 --- a/tests/in/001000.yaml +++ /dev/null @@ -1,12 +0,0 @@ -services: - web: - build: . - depends_on: - db: - condition: service_healthy - redis: - condition: service_started - redis: - image: redis - db: - image: postgres diff --git a/tests/in/001001.yaml b/tests/in/001001.yaml deleted file mode 100644 index 1e176a6..0000000 --- a/tests/in/001001.yaml +++ /dev/null @@ -1,29 +0,0 @@ -services: - frontend: - image: awesome/webapp - networks: - - front-tier - - back-tier - depends_on: - - monitoring - - backend - - monitoring: - image: awesome/monitoring - networks: - - admin - - backend: - image: awesome/backend - networks: - back-tier: - aliases: - - database - admin: - aliases: - - mysql - -networks: - front-tier: - back-tier: - admin: diff --git a/tests/in/001010.yaml b/tests/in/001010.yaml deleted file mode 100644 index 62f96e4..0000000 --- a/tests/in/001010.yaml +++ /dev/null @@ -1,11 +0,0 @@ -services: - web: - depends_on: - - db - - redis - extends: - service: redis - redis: - image: redis - db: - image: postgres diff --git a/tests/in/001011.yaml b/tests/in/001011.yaml deleted file mode 100644 index f91c6b5..0000000 --- a/tests/in/001011.yaml +++ /dev/null @@ -1,30 +0,0 @@ -services: - frontend: - networks: - - front-tier - - back-tier - depends_on: - - monitoring - - backend - extends: - service: backend - - monitoring: - image: awesome/monitoring - networks: - - admin - - backend: - image: awesome/backend - networks: - back-tier: - aliases: - - database - admin: - aliases: - - mysql - -networks: - front-tier: - back-tier: - admin: diff --git a/tests/in/001100.yaml b/tests/in/001100.yaml deleted file mode 100644 index ef3d14c..0000000 --- a/tests/in/001100.yaml +++ /dev/null @@ -1,17 +0,0 @@ -services: - frontend: - image: awesome/webapp - ports: - - "8000:5000" - - monitoring: - image: awesome/monitoring - depends_on: - - backend - ports: - - "8000:5010" - - backend: - image: awesome/backend - ports: - - "8000:5001" diff --git a/tests/in/001101.yaml b/tests/in/001101.yaml deleted file mode 100644 index 04483a2..0000000 --- a/tests/in/001101.yaml +++ /dev/null @@ -1,30 +0,0 @@ -services: - frontend: - image: awesome/webapp - networks: - - front-tier - - back-tier - - monitoring: - image: awesome/monitoring - networks: - - admin - depends_on: - - backend - ports: - - "8000:5010" - - backend: - image: awesome/backend - networks: - back-tier: - aliases: - - database - admin: - aliases: - - mysql - -networks: - front-tier: - back-tier: - admin: diff --git a/tests/in/001110.yaml b/tests/in/001110.yaml deleted file mode 100644 index 75981f6..0000000 --- a/tests/in/001110.yaml +++ /dev/null @@ -1,19 +0,0 @@ -services: - frontend: - image: awesome/webapp - ports: - - "8000:5000" - - monitoring: - depends_on: - - backend - extends: - service: frontend - ports: - - "8000:5010" - - backend: - extends: - service: frontend - ports: - - "8000:5001" diff --git a/tests/in/001111.yaml b/tests/in/001111.yaml deleted file mode 100644 index e328460..0000000 --- a/tests/in/001111.yaml +++ /dev/null @@ -1,31 +0,0 @@ -services: - frontend: - image: awesome/webapp - networks: - - front-tier - - back-tier - - monitoring: - networks: - - admin - depends_on: - - backend - extends: - service: frontend - ports: - - "8000:5010" - - backend: - image: awesome/backend - networks: - back-tier: - aliases: - - database - admin: - aliases: - - mysql - -networks: - front-tier: - back-tier: - admin: diff --git a/tests/in/010000.yaml b/tests/in/010000.yaml deleted file mode 100644 index 1040482..0000000 --- a/tests/in/010000.yaml +++ /dev/null @@ -1,11 +0,0 @@ -services: - backend: - image: awesome/backend - volumes: - - "db-data:/data" - - type: bind - source: /var/run/postgres/postgres.sock - target: /var/run/postgres/postgres.sock - -volumes: - db-data: diff --git a/tests/in/010001.yaml b/tests/in/010001.yaml deleted file mode 100644 index 4361504..0000000 --- a/tests/in/010001.yaml +++ /dev/null @@ -1,37 +0,0 @@ -services: - frontend: - image: awesome/webapp - networks: - - front-tier - - back-tier - - monitoring: - image: awesome/monitoring - networks: - - admin - - backend: - image: awesome/backend - networks: - back-tier: - aliases: - - database - admin: - aliases: - - mysql - volumes: - - type: volume - source: db-data - target: /data - volume: - nocopy: true - - type: bind - source: /var/run/postgres/postgres.sock - target: /var/run/postgres/postgres.sock - -networks: - front-tier: - back-tier: - admin: -volumes: - db-data: diff --git a/tests/in/010010.yaml b/tests/in/010010.yaml deleted file mode 100644 index 9294993..0000000 --- a/tests/in/010010.yaml +++ /dev/null @@ -1,13 +0,0 @@ -services: - common: - image: busybox - volumes: - - common-volume:/var/lib/backup/data:rw - cli: - extends: - service: common - volumes: - - cli-volume:/var/lib/backup/data:ro -volumes: - common-volume: - cli-volume: diff --git a/tests/in/010011.yaml b/tests/in/010011.yaml deleted file mode 100644 index 6337778..0000000 --- a/tests/in/010011.yaml +++ /dev/null @@ -1,38 +0,0 @@ -services: - frontend: - image: awesome/webapp - networks: - - front-tier - - back-tier - - monitoring: - image: awesome/monitoring - networks: - - admin - - backend: - networks: - back-tier: - aliases: - - database - admin: - aliases: - - mysql - volumes: - - type: volume - source: db-data - target: /data - volume: - nocopy: true - - type: bind - source: /var/run/postgres/postgres.sock - target: /var/run/postgres/postgres.sock - extends: - service: monitoring - -networks: - front-tier: - back-tier: - admin: -volumes: - db-data: diff --git a/tests/in/010100.yaml b/tests/in/010100.yaml deleted file mode 100644 index a601ccd..0000000 --- a/tests/in/010100.yaml +++ /dev/null @@ -1,16 +0,0 @@ -services: - backend: - image: awesome/backend - volumes: - - type: volume - source: db-data - target: /data - volume: - nocopy: true - - type: bind - source: /var/run/postgres/postgres.sock - target: /var/run/postgres/postgres.sock - ports: - - "8000:5000" -volumes: - db-data: diff --git a/tests/in/010101.yaml b/tests/in/010101.yaml deleted file mode 100644 index 098a6a9..0000000 --- a/tests/in/010101.yaml +++ /dev/null @@ -1,39 +0,0 @@ -services: - frontend: - image: awesome/webapp - networks: - - front-tier - - back-tier - - monitoring: - image: awesome/monitoring - networks: - - admin - - backend: - image: awesome/backend - networks: - back-tier: - aliases: - - database - admin: - aliases: - - mysql - volumes: - - type: volume - source: db-data - target: /data - volume: - nocopy: true - - type: bind - source: /var/run/postgres/postgres.sock - target: /var/run/postgres/postgres.sock - ports: - - "8000:5000" - -networks: - front-tier: - back-tier: - admin: -volumes: - db-data: diff --git a/tests/in/010110.yaml b/tests/in/010110.yaml deleted file mode 100644 index 2727cf4..0000000 --- a/tests/in/010110.yaml +++ /dev/null @@ -1,23 +0,0 @@ -services: - frontend: - image: awesome/webapp - - monitoring: - image: awesome/monitoring - - backend: - volumes: - - type: volume - source: db-data - target: /data - volume: - nocopy: true - - type: bind - source: /var/run/postgres/postgres.sock - target: /var/run/postgres/postgres.sock - extends: - service: monitoring - ports: - - "8000:5000" -volumes: - db-data: diff --git a/tests/in/010111.yaml b/tests/in/010111.yaml deleted file mode 100644 index 19fb865..0000000 --- a/tests/in/010111.yaml +++ /dev/null @@ -1,40 +0,0 @@ -services: - frontend: - image: awesome/webapp - networks: - - front-tier - - back-tier - - monitoring: - image: awesome/monitoring - networks: - - admin - - backend: - networks: - back-tier: - aliases: - - database - admin: - aliases: - - mysql - volumes: - - type: volume - source: db-data - target: /data - volume: - nocopy: true - - type: bind - source: /var/run/postgres/postgres.sock - target: /var/run/postgres/postgres.sock - extends: - service: monitoring - ports: - - "8000:5000" - -networks: - front-tier: - back-tier: - admin: -volumes: - db-data: diff --git a/tests/in/011000.yaml b/tests/in/011000.yaml deleted file mode 100644 index 0e31582..0000000 --- a/tests/in/011000.yaml +++ /dev/null @@ -1,22 +0,0 @@ -services: - frontend: - image: awesome/webapp - - monitoring: - image: awesome/monitoring - depends_on: - - backend - volumes: - - type: volume - source: db-data - target: /data - volume: - nocopy: true - - type: bind - source: /var/run/postgres/postgres.sock - target: /var/run/postgres/postgres.sock - - backend: - image: awesome/backend -volumes: - db-data: diff --git a/tests/in/011001.yaml b/tests/in/011001.yaml deleted file mode 100644 index 495facc..0000000 --- a/tests/in/011001.yaml +++ /dev/null @@ -1,40 +0,0 @@ -services: - frontend: - image: awesome/webapp - networks: - - front-tier - - back-tier - - monitoring: - image: awesome/monitoring - networks: - - admin - - - backend: - image: awesome/backend - networks: - back-tier: - aliases: - - database - admin: - aliases: - - mysql - volumes: - - type: volume - source: db-data - target: /data - volume: - nocopy: true - - type: bind - source: /var/run/postgres/postgres.sock - target: /var/run/postgres/postgres.sock - depends_on: - - monitoring - -networks: - front-tier: - back-tier: - admin: -volumes: - db-data: diff --git a/tests/in/011010.yaml b/tests/in/011010.yaml deleted file mode 100644 index 4578dc1..0000000 --- a/tests/in/011010.yaml +++ /dev/null @@ -1,25 +0,0 @@ -services: - frontend: - image: awesome/webapp - - monitoring: - image: awesome/monitoring - - - backend: - volumes: - - type: volume - source: db-data - target: /data - volume: - nocopy: true - - type: bind - source: /var/run/postgres/postgres.sock - target: /var/run/postgres/postgres.sock - depends_on: - - monitoring - extends: - service: frontend - -volumes: - db-data: diff --git a/tests/in/011011.yaml b/tests/in/011011.yaml deleted file mode 100644 index a263f0b..0000000 --- a/tests/in/011011.yaml +++ /dev/null @@ -1,41 +0,0 @@ -services: - frontend: - image: awesome/webapp - networks: - - front-tier - - back-tier - - monitoring: - image: awesome/monitoring - networks: - - admin - - - backend: - networks: - back-tier: - aliases: - - database - admin: - aliases: - - mysql - volumes: - - type: volume - source: db-data - target: /data - volume: - nocopy: true - - type: bind - source: /var/run/postgres/postgres.sock - target: /var/run/postgres/postgres.sock - depends_on: - - monitoring - extends: - service: frontend - -networks: - front-tier: - back-tier: - admin: -volumes: - db-data: diff --git a/tests/in/011100.yaml b/tests/in/011100.yaml deleted file mode 100644 index 2bb322e..0000000 --- a/tests/in/011100.yaml +++ /dev/null @@ -1,28 +0,0 @@ -services: - frontend: - image: awesome/webapp - ports: - - "8000:5000" - - monitoring: - image: awesome/monitoring - depends_on: - - backend - ports: - - "8000:5010" - volumes: - - type: volume - source: db-data - target: /data - volume: - nocopy: true - - type: bind - source: /var/run/postgres/postgres.sock - target: /var/run/postgres/postgres.sock - - backend: - image: awesome/backend - ports: - - "8000:5001" -volumes: - db-data: diff --git a/tests/in/011101.yaml b/tests/in/011101.yaml deleted file mode 100644 index 8f366a2..0000000 --- a/tests/in/011101.yaml +++ /dev/null @@ -1,42 +0,0 @@ -services: - frontend: - image: awesome/webapp - networks: - - front-tier - - back-tier - - monitoring: - image: awesome/monitoring - networks: - - admin - - - backend: - image: awesome/backend - networks: - back-tier: - aliases: - - database - admin: - aliases: - - mysql - volumes: - - type: volume - source: db-data - target: /data - volume: - nocopy: true - - type: bind - source: /var/run/postgres/postgres.sock - target: /var/run/postgres/postgres.sock - depends_on: - - monitoring - ports: - - "8000:5010" - -networks: - front-tier: - back-tier: - admin: -volumes: - db-data: diff --git a/tests/in/011110.yaml b/tests/in/011110.yaml deleted file mode 100644 index d0553d2..0000000 --- a/tests/in/011110.yaml +++ /dev/null @@ -1,29 +0,0 @@ -services: - frontend: - image: awesome/webapp - - - monitoring: - image: awesome/monitoring - - - - backend: - volumes: - - type: volume - source: db-data - target: /data - volume: - nocopy: true - - type: bind - source: /var/run/postgres/postgres.sock - target: /var/run/postgres/postgres.sock - depends_on: - - monitoring - extends: - service: frontend - ports: - - "8000:5010" - -volumes: - db-data: diff --git a/tests/in/011111.yaml b/tests/in/011111.yaml deleted file mode 100644 index 34389f4..0000000 --- a/tests/in/011111.yaml +++ /dev/null @@ -1,43 +0,0 @@ -services: - frontend: - image: awesome/webapp - networks: - - front-tier - - back-tier - - monitoring: - image: awesome/monitoring - networks: - - admin - - - backend: - networks: - back-tier: - aliases: - - database - admin: - aliases: - - mysql - volumes: - - type: volume - source: db-data - target: /data - volume: - nocopy: true - - type: bind - source: /var/run/postgres/postgres.sock - target: /var/run/postgres/postgres.sock - depends_on: - - monitoring - extends: - service: frontend - ports: - - "8000:5010" - -networks: - front-tier: - back-tier: - admin: -volumes: - db-data: diff --git a/tests/in/100001.yaml b/tests/in/100001.yaml deleted file mode 100644 index 2c130d1..0000000 --- a/tests/in/100001.yaml +++ /dev/null @@ -1,31 +0,0 @@ -services: - frontend: - image: awesome/webapp - networks: - - front-tier - - back-tier - - monitoring: - image: awesome/monitoring - networks: - - admin - - - backend: - image: awesome/backend - networks: - back-tier: - aliases: - - database - admin: - aliases: - - mysql - links: - - "db:database" - db: - image: postgres - -networks: - front-tier: - back-tier: - admin: diff --git a/tests/in/100010.yaml b/tests/in/100010.yaml deleted file mode 100644 index b7d9de1..0000000 --- a/tests/in/100010.yaml +++ /dev/null @@ -1,15 +0,0 @@ -services: - frontend: - image: awesome/webapp - - monitoring: - image: awesome/monitoring - - - backend: - extends: - service: frontend - links: - - "db:database" - db: - image: postgres diff --git a/tests/in/100011.yaml b/tests/in/100011.yaml deleted file mode 100644 index 7c4be01..0000000 --- a/tests/in/100011.yaml +++ /dev/null @@ -1,32 +0,0 @@ -services: - frontend: - image: awesome/webapp - networks: - - front-tier - - back-tier - - monitoring: - image: awesome/monitoring - networks: - - admin - - - backend: - networks: - back-tier: - aliases: - - database - admin: - aliases: - - mysql - extends: - service: frontend - links: - - "db:database" - db: - image: postgres - -networks: - front-tier: - back-tier: - admin: diff --git a/tests/in/100100.yaml b/tests/in/100100.yaml deleted file mode 100644 index e3b8a94..0000000 --- a/tests/in/100100.yaml +++ /dev/null @@ -1,16 +0,0 @@ -services: - frontend: - image: awesome/webapp - - monitoring: - image: awesome/monitoring - - - backend: - image: awesome/backend - ports: - - "8000:5010" - links: - - "db:database" - db: - image: postgres diff --git a/tests/in/100101.yaml b/tests/in/100101.yaml deleted file mode 100644 index a576314..0000000 --- a/tests/in/100101.yaml +++ /dev/null @@ -1,33 +0,0 @@ -services: - frontend: - image: awesome/webapp - networks: - - front-tier - - back-tier - - monitoring: - image: awesome/monitoring - networks: - - admin - - - backend: - image: awesome/backend - networks: - back-tier: - aliases: - - database - admin: - aliases: - - mysql - ports: - - "8000:5010" - links: - - "db:database" - db: - image: postgres - -networks: - front-tier: - back-tier: - admin: diff --git a/tests/in/100110.yaml b/tests/in/100110.yaml deleted file mode 100644 index 612d73f..0000000 --- a/tests/in/100110.yaml +++ /dev/null @@ -1,17 +0,0 @@ -services: - frontend: - image: awesome/webapp - - monitoring: - image: awesome/monitoring - - - backend: - extends: - service: frontend - ports: - - "8000:5010" - links: - - "db:database" - db: - image: postgres diff --git a/tests/in/100111.yaml b/tests/in/100111.yaml deleted file mode 100644 index 4e1ca01..0000000 --- a/tests/in/100111.yaml +++ /dev/null @@ -1,34 +0,0 @@ -services: - frontend: - image: awesome/webapp - networks: - - front-tier - - back-tier - - monitoring: - image: awesome/monitoring - networks: - - admin - - - backend: - networks: - back-tier: - aliases: - - database - admin: - aliases: - - mysql - extends: - service: frontend - ports: - - "8000:5010" - links: - - "db:database" - db: - image: postgres - -networks: - front-tier: - back-tier: - admin: diff --git a/tests/in/101000.yaml b/tests/in/101000.yaml deleted file mode 100644 index 8f52814..0000000 --- a/tests/in/101000.yaml +++ /dev/null @@ -1,16 +0,0 @@ -services: - frontend: - image: awesome/webapp - - monitoring: - image: awesome/monitoring - - - backend: - image: awesome/backend - depends_on: - - monitoring - links: - - "db:database" - db: - image: postgres diff --git a/tests/in/101001.yaml b/tests/in/101001.yaml deleted file mode 100644 index 5fbf3d9..0000000 --- a/tests/in/101001.yaml +++ /dev/null @@ -1,33 +0,0 @@ -services: - frontend: - image: awesome/webapp - networks: - - front-tier - - back-tier - - monitoring: - image: awesome/monitoring - networks: - - admin - - - backend: - image: awesome/backend - networks: - back-tier: - aliases: - - database - admin: - aliases: - - mysql - depends_on: - - monitoring - links: - - "db:database" - db: - image: postgres - -networks: - front-tier: - back-tier: - admin: diff --git a/tests/in/101010.yaml b/tests/in/101010.yaml deleted file mode 100644 index 1fe5809..0000000 --- a/tests/in/101010.yaml +++ /dev/null @@ -1,17 +0,0 @@ -services: - frontend: - image: awesome/webapp - - monitoring: - image: awesome/monitoring - - - backend: - depends_on: - - monitoring - links: - - "db:database" - extends: - service: frontend - db: - image: postgres diff --git a/tests/in/101011.yaml b/tests/in/101011.yaml deleted file mode 100644 index f882bcd..0000000 --- a/tests/in/101011.yaml +++ /dev/null @@ -1,34 +0,0 @@ -services: - frontend: - image: awesome/webapp - networks: - - front-tier - - back-tier - - monitoring: - image: awesome/monitoring - networks: - - admin - - - backend: - networks: - back-tier: - aliases: - - database - admin: - aliases: - - mysql - depends_on: - - monitoring - extends: - service: frontend - links: - - "db:database" - db: - image: postgres - -networks: - front-tier: - back-tier: - admin: diff --git a/tests/in/101100.yaml b/tests/in/101100.yaml deleted file mode 100644 index a7f17fe..0000000 --- a/tests/in/101100.yaml +++ /dev/null @@ -1,18 +0,0 @@ -services: - frontend: - image: awesome/webapp - - monitoring: - image: awesome/monitoring - - - backend: - image: awesome/backend - depends_on: - - monitoring - ports: - - "8000:5010" - links: - - "db:database" - db: - image: postgres diff --git a/tests/in/101101.yaml b/tests/in/101101.yaml deleted file mode 100644 index dc00820..0000000 --- a/tests/in/101101.yaml +++ /dev/null @@ -1,35 +0,0 @@ -services: - frontend: - image: awesome/webapp - networks: - - front-tier - - back-tier - - monitoring: - image: awesome/monitoring - networks: - - admin - - - backend: - image: awesome/backend - networks: - back-tier: - aliases: - - database - admin: - aliases: - - mysql - depends_on: - - monitoring - ports: - - "8000:5010" - links: - - "db:database" - db: - image: postgres - -networks: - front-tier: - back-tier: - admin: diff --git a/tests/in/101110.yaml b/tests/in/101110.yaml deleted file mode 100644 index e6cb223..0000000 --- a/tests/in/101110.yaml +++ /dev/null @@ -1,20 +0,0 @@ -services: - frontend: - image: awesome/webapp - - monitoring: - image: awesome/monitoring - - - - backend: - depends_on: - - monitoring - extends: - service: frontend - ports: - - "8000:5010" - links: - - "db:database" - db: - image: postgres diff --git a/tests/in/101111.yaml b/tests/in/101111.yaml deleted file mode 100644 index b17b0d4..0000000 --- a/tests/in/101111.yaml +++ /dev/null @@ -1,36 +0,0 @@ -services: - frontend: - image: awesome/webapp - networks: - - front-tier - - back-tier - - monitoring: - image: awesome/monitoring - networks: - - admin - - - backend: - networks: - back-tier: - aliases: - - database - admin: - aliases: - - mysql - depends_on: - - monitoring - extends: - service: frontend - ports: - - "8000:5010" - links: - - "db:database" - db: - image: postgres - -networks: - front-tier: - back-tier: - admin: diff --git a/tests/in/110000.yaml b/tests/in/110000.yaml deleted file mode 100644 index f79c07a..0000000 --- a/tests/in/110000.yaml +++ /dev/null @@ -1,24 +0,0 @@ -services: - frontend: - image: awesome/webapp - - monitoring: - image: awesome/monitoring - volumes: - - type: volume - source: db-data - target: /data - volume: - nocopy: true - - type: bind - source: /var/run/postgres/postgres.sock - target: /var/run/postgres/postgres.sock - links: - - "db:database" - - backend: - image: awesome/backend - db: - image: postgres -volumes: - db-data: diff --git a/tests/in/110001.yaml b/tests/in/110001.yaml deleted file mode 100644 index dab8541..0000000 --- a/tests/in/110001.yaml +++ /dev/null @@ -1,42 +0,0 @@ -services: - frontend: - image: awesome/webapp - networks: - - front-tier - - back-tier - - monitoring: - image: awesome/monitoring - networks: - - admin - - - backend: - image: awesome/backend - networks: - back-tier: - aliases: - - database - admin: - aliases: - - mysql - volumes: - - type: volume - source: db-data - target: /data - volume: - nocopy: true - - type: bind - source: /var/run/postgres/postgres.sock - target: /var/run/postgres/postgres.sock - links: - - "db:database" - db: - image: postgres - -networks: - front-tier: - back-tier: - admin: -volumes: - db-data: diff --git a/tests/in/110010.yaml b/tests/in/110010.yaml deleted file mode 100644 index 8dcf22e..0000000 --- a/tests/in/110010.yaml +++ /dev/null @@ -1,27 +0,0 @@ -services: - frontend: - image: awesome/webapp - - monitoring: - image: awesome/monitoring - - - backend: - volumes: - - type: volume - source: db-data - target: /data - volume: - nocopy: true - - type: bind - source: /var/run/postgres/postgres.sock - target: /var/run/postgres/postgres.sock - extends: - service: frontend - links: - - "db:database" - db: - image: postgres - -volumes: - db-data: diff --git a/tests/in/110011.yaml b/tests/in/110011.yaml deleted file mode 100644 index 2725ee8..0000000 --- a/tests/in/110011.yaml +++ /dev/null @@ -1,43 +0,0 @@ -services: - frontend: - image: awesome/webapp - networks: - - front-tier - - back-tier - - monitoring: - image: awesome/monitoring - networks: - - admin - - - backend: - networks: - back-tier: - aliases: - - database - admin: - aliases: - - mysql - volumes: - - type: volume - source: db-data - target: /data - volume: - nocopy: true - - type: bind - source: /var/run/postgres/postgres.sock - target: /var/run/postgres/postgres.sock - extends: - service: frontend - links: - - "db:database" - db: - image: postgres - -networks: - front-tier: - back-tier: - admin: -volumes: - db-data: diff --git a/tests/in/110100.yaml b/tests/in/110100.yaml deleted file mode 100644 index ac0fc6c..0000000 --- a/tests/in/110100.yaml +++ /dev/null @@ -1,28 +0,0 @@ -services: - frontend: - image: awesome/webapp - - monitoring: - image: awesome/monitoring - - - backend: - image: awesome/backend - volumes: - - type: volume - source: db-data - target: /data - volume: - nocopy: true - - type: bind - source: /var/run/postgres/postgres.sock - target: /var/run/postgres/postgres.sock - ports: - - "8000:5010" - links: - - "db:database" - db: - image: postgres - -volumes: - db-data: diff --git a/tests/in/110101.yaml b/tests/in/110101.yaml deleted file mode 100644 index 48b9d1d..0000000 --- a/tests/in/110101.yaml +++ /dev/null @@ -1,44 +0,0 @@ -services: - frontend: - image: awesome/webapp - networks: - - front-tier - - back-tier - - monitoring: - image: awesome/monitoring - networks: - - admin - - - backend: - image: awesome/backend - networks: - back-tier: - aliases: - - database - admin: - aliases: - - mysql - volumes: - - type: volume - source: db-data - target: /data - volume: - nocopy: true - - type: bind - source: /var/run/postgres/postgres.sock - target: /var/run/postgres/postgres.sock - ports: - - "8000:5010" - links: - - "db:database" - db: - image: postgres - -networks: - front-tier: - back-tier: - admin: -volumes: - db-data: diff --git a/tests/in/110110.yaml b/tests/in/110110.yaml deleted file mode 100644 index f9abebe..0000000 --- a/tests/in/110110.yaml +++ /dev/null @@ -1,29 +0,0 @@ -services: - frontend: - image: awesome/webapp - - monitoring: - image: awesome/monitoring - - - backend: - volumes: - - type: volume - source: db-data - target: /data - volume: - nocopy: true - - type: bind - source: /var/run/postgres/postgres.sock - target: /var/run/postgres/postgres.sock - extends: - service: frontend - ports: - - "8000:5010" - links: - - "db:database" - db: - image: postgres - -volumes: - db-data: diff --git a/tests/in/110111.yaml b/tests/in/110111.yaml deleted file mode 100644 index 76e6a4f..0000000 --- a/tests/in/110111.yaml +++ /dev/null @@ -1,45 +0,0 @@ -services: - frontend: - image: awesome/webapp - networks: - - front-tier - - back-tier - - monitoring: - image: awesome/monitoring - networks: - - admin - - - backend: - networks: - back-tier: - aliases: - - database - admin: - aliases: - - mysql - volumes: - - type: volume - source: db-data - target: /data - volume: - nocopy: true - - type: bind - source: /var/run/postgres/postgres.sock - target: /var/run/postgres/postgres.sock - extends: - service: frontend - ports: - - "8000:5010" - links: - - "db:database" - db: - image: postgres - -networks: - front-tier: - back-tier: - admin: -volumes: - db-data: diff --git a/tests/in/111000.yaml b/tests/in/111000.yaml deleted file mode 100644 index bdcd442..0000000 --- a/tests/in/111000.yaml +++ /dev/null @@ -1,26 +0,0 @@ -services: - frontend: - image: awesome/webapp - - monitoring: - image: awesome/monitoring - depends_on: - - backend - volumes: - - type: volume - source: db-data - target: /data - volume: - nocopy: true - - type: bind - source: /var/run/postgres/postgres.sock - target: /var/run/postgres/postgres.sock - links: - - "db:database" - - backend: - image: awesome/backend - db: - image: postgres -volumes: - db-data: diff --git a/tests/in/111001.yaml b/tests/in/111001.yaml deleted file mode 100644 index 7586730..0000000 --- a/tests/in/111001.yaml +++ /dev/null @@ -1,44 +0,0 @@ -services: - frontend: - image: awesome/webapp - networks: - - front-tier - - back-tier - - monitoring: - image: awesome/monitoring - networks: - - admin - - - backend: - image: awesome/backend - networks: - back-tier: - aliases: - - database - admin: - aliases: - - mysql - volumes: - - type: volume - source: db-data - target: /data - volume: - nocopy: true - - type: bind - source: /var/run/postgres/postgres.sock - target: /var/run/postgres/postgres.sock - depends_on: - - monitoring - links: - - "db:database" - db: - image: postgres - -networks: - front-tier: - back-tier: - admin: -volumes: - db-data: diff --git a/tests/in/111010.yaml b/tests/in/111010.yaml deleted file mode 100644 index 7591564..0000000 --- a/tests/in/111010.yaml +++ /dev/null @@ -1,29 +0,0 @@ -services: - frontend: - image: awesome/webapp - - monitoring: - image: awesome/monitoring - - - backend: - volumes: - - type: volume - source: db-data - target: /data - volume: - nocopy: true - - type: bind - source: /var/run/postgres/postgres.sock - target: /var/run/postgres/postgres.sock - depends_on: - - monitoring - extends: - service: frontend - links: - - "db:database" - db: - image: postgres - -volumes: - db-data: diff --git a/tests/in/111011.yaml b/tests/in/111011.yaml deleted file mode 100644 index 3714d62..0000000 --- a/tests/in/111011.yaml +++ /dev/null @@ -1,45 +0,0 @@ -services: - frontend: - image: awesome/webapp - networks: - - front-tier - - back-tier - - monitoring: - image: awesome/monitoring - networks: - - admin - - - backend: - networks: - back-tier: - aliases: - - database - admin: - aliases: - - mysql - volumes: - - type: volume - source: db-data - target: /data - volume: - nocopy: true - - type: bind - source: /var/run/postgres/postgres.sock - target: /var/run/postgres/postgres.sock - depends_on: - - monitoring - extends: - service: frontend - links: - - "db:database" - db: - image: postgres - -networks: - front-tier: - back-tier: - admin: -volumes: - db-data: diff --git a/tests/in/111100.yaml b/tests/in/111100.yaml deleted file mode 100644 index 9a52b90..0000000 --- a/tests/in/111100.yaml +++ /dev/null @@ -1,30 +0,0 @@ -services: - frontend: - image: awesome/webapp - - monitoring: - image: awesome/monitoring - - - backend: - image: awesome/backend - volumes: - - type: volume - source: db-data - target: /data - volume: - nocopy: true - - type: bind - source: /var/run/postgres/postgres.sock - target: /var/run/postgres/postgres.sock - depends_on: - - monitoring - ports: - - "8000:5010" - links: - - "db:database" - db: - image: postgres - -volumes: - db-data: diff --git a/tests/in/111101.yaml b/tests/in/111101.yaml deleted file mode 100644 index 4d6bead..0000000 --- a/tests/in/111101.yaml +++ /dev/null @@ -1,46 +0,0 @@ -services: - frontend: - image: awesome/webapp - networks: - - front-tier - - back-tier - - monitoring: - image: awesome/monitoring - networks: - - admin - - - backend: - image: awesome/backend - networks: - back-tier: - aliases: - - database - admin: - aliases: - - mysql - volumes: - - type: volume - source: db-data - target: /data - volume: - nocopy: true - - type: bind - source: /var/run/postgres/postgres.sock - target: /var/run/postgres/postgres.sock - depends_on: - - monitoring - ports: - - "8000:5010" - links: - - "db:database" - db: - image: postgres - -networks: - front-tier: - back-tier: - admin: -volumes: - db-data: diff --git a/tests/in/111110.yaml b/tests/in/111110.yaml deleted file mode 100644 index 540c9de..0000000 --- a/tests/in/111110.yaml +++ /dev/null @@ -1,30 +0,0 @@ -services: - frontend: - image: awesome/webapp - monitoring: - image: awesome/monitoring - - - backend: - volumes: - - type: volume - source: db-data - target: /data - volume: - nocopy: true - - type: bind - source: /var/run/postgres/postgres.sock - target: /var/run/postgres/postgres.sock - depends_on: - - monitoring - extends: - service: frontend - ports: - - "8000:5010" - links: - - "db:database" - db: - image: postgres - -volumes: - db-data: diff --git a/tests/in/111111.yaml b/tests/in/111111.yaml deleted file mode 100644 index 2ed41b9..0000000 --- a/tests/in/111111.yaml +++ /dev/null @@ -1,47 +0,0 @@ -services: - frontend: - image: awesome/webapp - networks: - - front-tier - - back-tier - - monitoring: - image: awesome/monitoring - networks: - - admin - - - backend: - networks: - back-tier: - aliases: - - database - admin: - aliases: - - mysql - volumes: - - type: volume - source: db-data - target: /data - volume: - nocopy: true - - type: bind - source: /var/run/postgres/postgres.sock - target: /var/run/postgres/postgres.sock - depends_on: - - monitoring - extends: - service: frontend - ports: - - "8000:5010" - links: - - "db:database" - db: - image: postgres - -networks: - front-tier: - back-tier: - admin: -volumes: - db-data: diff --git a/tests/test_cli.py b/tests/test_cli.py index 45a640d..5b1ae39 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -9,76 +9,20 @@ runner = CliRunner() @pytest.mark.parametrize( - "file_number", + "test_file_path", [ - "000001", - "000010", - "000011", - "000100", - "000101", - "000110", - "000111", - "001000", - "001001", - "001010", - "001011", - "001100", - "001101", - "001110", - "001111", - "010000", - "010001", - "010010", - "010011", - "010100", - "010101", - "010110", - "010111", - "011000", - "011001", - "011010", - "011011", - "011100", - "011101", - "011110", - "011111", - "100000", - "100001", - "100010", - "100011", - "100100", - "100101", - "100110", - "100111", - "101000", - "101001", - "101010", - "101011", - "101100", - "101101", - "101110", - "101111", - "110000", - "110001", - "110010", - "110011", - "110100", - "110101", - "110110", - "110111", - "111000", - "111001", - "111010", - "111011", - "111100", - "111101", - "111110", - "111111", + "builds/docker-compose", + "depends_on/docker-compose", + "extends/docker-compose", + "links/docker-compose", + "networks/docker-compose", + "ports/docker-compose", + "volumes/docker-compose", ], ) -def test_cli(file_number: str) -> None: - input_path = f"tests/in/{file_number}.yaml" - output_path = f"{file_number}.png" +def test_cli(test_file_path: str) -> None: + input_path = f"tests/ymls/{test_file_path}.yml" + output_path = "compose-viz-test.png" result = runner.invoke(cli.app, ["-o", output_path, input_path]) assert result.exit_code == 0 diff --git a/tests/test_extends.py b/tests/test_extends.py index 0bc6a0c..ad7e4c5 100644 --- a/tests/test_extends.py +++ b/tests/test_extends.py @@ -5,10 +5,10 @@ from compose_viz.extends import Extends def test_extend_init_normal() -> None: try: - e = Extends(service_name="frontend", from_file="tests/in/000001.yaml") + e = Extends(service_name="frontend", from_file="tests/ymls/others/empty.yaml") assert e.service_name == "frontend" - assert e.from_file == "tests/in/000001.yaml" + assert e.from_file == "tests/ymls/others/empty.yaml" except Exception as e: assert False, e @@ -25,4 +25,4 @@ def test_extend_init_without_from_file() -> None: def test_extend_init_without_service_name() -> None: with pytest.raises(TypeError): - Extends(from_file="tests/in/000001.yaml") # type: ignore + Extends(from_file="tests/ymls/others/empty.yaml") # type: ignore diff --git a/tests/test_parse_file.py b/tests/test_parse_file.py index e4fe9c7..d624a43 100644 --- a/tests/test_parse_file.py +++ b/tests/test_parse_file.py @@ -5,382 +5,194 @@ from compose_viz.extends import Extends from compose_viz.parser import Parser from compose_viz.port import Port, Protocol from compose_viz.service import Service -from compose_viz.volume import AccessMode, Volume, VolumeType +from compose_viz.volume import Volume, VolumeType @pytest.mark.parametrize( - "test_input, expected", + "test_file_path, expected", [ ( - "tests/in/000001.yaml", + "builds/docker-compose", Compose( - [ + services=[ Service( name="frontend", - image="awesome/webapp", - networks=["front-tier", "back-tier"], + image="build from ./frontend", ), Service( - name="monitoring", - image="awesome/monitoring", - networks=["admin"], + name="backend", + image="build from backend", + ), + ], + ), + ), + ( + "depends_on/docker-compose", + Compose( + services=[ + Service( + name="frontend", + image="awesome/frontend", + depends_on=[ + "db", + "redis", + ], ), Service( name="backend", image="awesome/backend", - networks=["back-tier", "admin"], + depends_on=[ + "db", + "redis", + ], ), - ] + Service( + name="db", + image="mysql", + ), + Service( + name="redis", + image="redis", + ), + ], ), ), ( - "tests/in/000010.yaml", + "extends/docker-compose", Compose( - [ + services=[ Service( name="base", - image="busybox", + image="alpine:latest", ), Service( - name="common", - extends=Extends(service_name="base"), + name="derive_from_base", + image="alpine:edge", + extends=Extends( + service_name="base", + ), ), Service( - name="cli", - extends=Extends(service_name="common"), + name="derive_from_file", + extends=Extends( + service_name="web", + from_file="web.yml", + ), ), - ] + ], ), ), ( - "tests/in/000011.yaml", + "links/docker-compose", Compose( - [ + services=[ Service( name="frontend", - image="awesome/webapp", - networks=["front-tier", "back-tier"], - ), - Service( - name="monitoring", - networks=["admin"], - extends=Extends(service_name="frontend"), - ), - Service( - name="backend", - networks=["back-tier", "admin"], - extends=Extends(service_name="frontend"), - ), - ] - ), - ), - ( - "tests/in/000100.yaml", - Compose( - [ - Service( - name="web", - image="build from .", - ports=[ - Port(host_port="8080", container_port="8080"), + image="awesome/frontend", + links=[ + "db:database", ], ), - Service( - name="redis", - image="redis:alpine", - ), - ] - ), - ), - ( - "tests/in/000101.yaml", - Compose( - [ - Service( - name="frontend", - image="awesome/webapp", - ports=[ - Port(host_port="127.0.0.1:8080", container_port="80", protocol=Protocol.udp), - ], - networks=["front-tier", "back-tier"], - ), - Service( - name="monitoring", - image="awesome/monitoring", - ports=[ - Port(host_port="127.0.0.1:8081", container_port="5001"), - ], - networks=["admin"], - ), - Service( - name="backend", - image="awesome/backend", - ports=[ - Port(host_port="8000", container_port="5010", protocol=Protocol.udp), - ], - networks=["back-tier", "admin"], - ), - ] - ), - ), - ( - "tests/in/000110.yaml", - Compose( - [ - Service( - name="frontend", - image="awesome/webapp", - ports=[ - Port(host_port="80", container_port="80"), - ], - ), - Service( - name="monitoring", - extends=Extends(service_name="frontend"), - ), - Service( - name="backend", - extends=Extends(service_name="frontend"), - ports=[ - Port(host_port="8000", container_port="5001"), - ], - ), - ] - ), - ), - ( - "tests/in/000111.yaml", - Compose( - [ - Service( - name="frontend", - image="awesome/webapp", - ports=[ - Port(host_port="8000", container_port="5000"), - ], - networks=["front-tier", "back-tier"], - ), - Service( - name="monitoring", - networks=["admin"], - extends=Extends(service_name="frontend"), - ), - Service( - name="backend", - ports=[ - Port(host_port="8000", container_port="5001"), - ], - networks=["back-tier", "admin"], - extends=Extends(service_name="frontend"), - ), - ] - ), - ), - ( - "tests/in/001000.yaml", - Compose( - [ - Service( - name="web", - image="build from .", - depends_on=["db", "redis"], - ), - Service( - name="redis", - image="redis", - ), Service( name="db", - image="postgres", + image="mysql", ), - ] + ], ), ), ( - "tests/in/001001.yaml", + "networks/docker-compose", Compose( - [ + services=[ Service( name="frontend", - image="awesome/webapp", - networks=["front-tier", "back-tier"], - depends_on=["monitoring", "backend"], - ), - Service( - name="monitoring", - image="awesome/monitoring", - networks=["admin"], - ), - Service( - name="backend", - image="awesome/backend", - networks=["back-tier", "admin"], - ), - ] - ), - ), - ( - "tests/in/001010.yaml", - Compose( - [ - Service( - name="web", - depends_on=["db", "redis"], - extends=Extends(service_name="redis"), - ), - Service( - name="redis", - image="redis", - ), - Service( - name="db", - image="postgres", - ), - ] - ), - ), - ( - "tests/in/001011.yaml", - Compose( - [ - Service( - name="frontend", - networks=["front-tier", "back-tier"], - depends_on=["monitoring", "backend"], - extends=Extends(service_name="backend"), - ), - Service( - name="monitoring", - image="awesome/monitoring", - networks=["admin"], - ), - Service( - name="backend", - image="awesome/backend", - networks=["back-tier", "admin"], - ), - ] - ), - ), - ( - "tests/in/001100.yaml", - Compose( - [ - Service( - name="frontend", - image="awesome/webapp", - ports=[ - Port(host_port="8000", container_port="5000"), + image="awesome/frontend", + networks=[ + "front-tier", + "back-tier", ], ), Service( name="monitoring", image="awesome/monitoring", - depends_on=["backend"], - ports=[ - Port(host_port="8000", container_port="5010"), + networks=[ + "admin", ], ), Service( name="backend", image="awesome/backend", - ports=[ - Port(host_port="8000", container_port="5001"), + networks=[ + "back-tier", + "admin", ], ), - ] + ], ), ), ( - "tests/in/001101.yaml", + "ports/docker-compose", Compose( - [ + services=[ Service( name="frontend", - image="awesome/webapp", - networks=["front-tier", "back-tier"], - ), - Service( - name="monitoring", - image="awesome/monitoring", - networks=["admin"], - depends_on=["backend"], + image="awesome/frontend", ports=[ - Port(host_port="8000", container_port="5010"), + Port( + host_port="0.0.0.0:3000", + container_port="3000", + ), + Port( + host_port="0.0.0.0:3000-3005", + container_port="3000-3005", + ), + Port( + host_port="0.0.0.0:9090-9091", + container_port="8080-8081", + ), + Port( + host_port="0.0.0.0:49100", + container_port="22", + ), + Port( + host_port="127.0.0.1:8001", + container_port="8001", + ), + Port( + host_port="127.0.0.1:5000-5010", + container_port="5000-5010", + ), + Port( + host_port="0.0.0.0:6060", + container_port="6060", + protocol=Protocol.udp, + ), + Port( + host_port="127.0.0.1:8080", + container_port="80", + protocol=Protocol.tcp, + ), + Port( + host_port="0.0.0.0:443", + container_port="443", + ), ], ), - Service( - name="backend", - image="awesome/backend", - networks=["back-tier", "admin"], - ), - ] + ], ), ), ( - "tests/in/001110.yaml", + "volumes/docker-compose", Compose( - [ - Service( - name="frontend", - image="awesome/webapp", - ports=[ - Port(host_port="8000", container_port="5000"), - ], - ), - Service( - name="monitoring", - depends_on=["backend"], - extends=Extends(service_name="frontend"), - ports=[ - Port(host_port="8000", container_port="5010"), - ], - ), - Service( - name="backend", - extends=Extends(service_name="frontend"), - ports=[ - Port(host_port="8000", container_port="5001"), - ], - ), - ] - ), - ), - ( - "tests/in/001111.yaml", - Compose( - [ - Service( - name="frontend", - image="awesome/webapp", - networks=["front-tier", "back-tier"], - ), - Service( - name="monitoring", - networks=["admin"], - depends_on=["backend"], - extends=Extends(service_name="frontend"), - ports=[ - Port(host_port="8000", container_port="5010"), - ], - ), - Service( - name="backend", - image="awesome/backend", - networks=["back-tier", "admin"], - ), - ] - ), - ), - ( - "tests/in/010000.yaml", - Compose( - [ + services=[ Service( name="backend", image="awesome/backend", volumes=[ - Volume(source="db-data", target="/data"), + Volume( + source="./data", + target="/data", + ), Volume( source="/var/run/postgres/postgres.sock", target="/var/run/postgres/postgres.sock", @@ -388,1465 +200,37 @@ from compose_viz.volume import AccessMode, Volume, VolumeType ), ], ), - ] - ), - ), - ( - "tests/in/010001.yaml", - Compose( - [ - Service( - name="frontend", - image="awesome/webapp", - networks=["front-tier", "back-tier"], - ), - Service( - name="monitoring", - image="awesome/monitoring", - networks=["admin"], - ), - Service( - name="backend", - image="awesome/backend", - networks=["back-tier", "admin"], - volumes=[ - Volume(source="db-data", target="/data"), - Volume( - source="/var/run/postgres/postgres.sock", - target="/var/run/postgres/postgres.sock", - type=VolumeType.bind, - ), - ], - ), - ] - ), - ), - ( - "tests/in/010010.yaml", - Compose( - [ Service( name="common", image="busybox", volumes=[ - Volume(source="common-volume", target="/var/lib/backup/data", access_mode=AccessMode.rw) + Volume( + source="common-volume", + target="/var/lib/backup/data", + ), ], ), Service( name="cli", - extends=Extends(service_name="common"), - volumes=[Volume(source="cli-volume", target="/var/lib/backup/data", access_mode=AccessMode.ro)], - ), - ] - ), - ), - ( - "tests/in/010011.yaml", - Compose( - [ - Service( - name="frontend", - image="awesome/webapp", - networks=["front-tier", "back-tier"], - ), - Service( - name="monitoring", - image="awesome/monitoring", - networks=["admin"], - ), - Service( - name="backend", - networks=["back-tier", "admin"], + extends=Extends( + service_name="common", + ), volumes=[ - Volume(source="db-data", target="/data"), Volume( - source="/var/run/postgres/postgres.sock", - target="/var/run/postgres/postgres.sock", - type=VolumeType.bind, - ), - ], - extends=Extends(service_name="monitoring"), - ), - ] - ), - ), - ( - "tests/in/010100.yaml", - Compose( - [ - Service( - name="backend", - image="awesome/backend", - volumes=[ - Volume(source="db-data", target="/data"), - Volume( - source="/var/run/postgres/postgres.sock", - target="/var/run/postgres/postgres.sock", - type=VolumeType.bind, - ), - ], - ports=[ - Port(host_port="8000", container_port="5000"), - ], - ), - ] - ), - ), - ( - "tests/in/010101.yaml", - Compose( - [ - Service( - name="frontend", - image="awesome/webapp", - networks=["front-tier", "back-tier"], - ), - Service( - name="monitoring", - image="awesome/monitoring", - networks=["admin"], - ), - Service( - name="backend", - image="awesome/backend", - networks=["back-tier", "admin"], - volumes=[ - Volume(source="db-data", target="/data"), - Volume( - source="/var/run/postgres/postgres.sock", - target="/var/run/postgres/postgres.sock", - type=VolumeType.bind, - ), - ], - ports=[ - Port(host_port="8000", container_port="5000"), - ], - ), - ] - ), - ), - ( - "tests/in/010110.yaml", - Compose( - [ - Service( - name="frontend", - image="awesome/webapp", - ), - Service( - name="monitoring", - image="awesome/monitoring", - ), - Service( - name="backend", - volumes=[ - Volume(source="db-data", target="/data"), - Volume( - source="/var/run/postgres/postgres.sock", - target="/var/run/postgres/postgres.sock", - type=VolumeType.bind, - ), - ], - extends=Extends(service_name="monitoring"), - ports=[ - Port(host_port="8000", container_port="5000"), - ], - ), - ] - ), - ), - ( - "tests/in/010111.yaml", - Compose( - [ - Service( - name="frontend", - image="awesome/webapp", - networks=["front-tier", "back-tier"], - ), - Service( - name="monitoring", - image="awesome/monitoring", - networks=["admin"], - ), - Service( - name="backend", - networks=["back-tier", "admin"], - volumes=[ - Volume(source="db-data", target="/data"), - Volume( - source="/var/run/postgres/postgres.sock", - target="/var/run/postgres/postgres.sock", - type=VolumeType.bind, - ), - ], - extends=Extends(service_name="monitoring"), - ports=[ - Port(host_port="8000", container_port="5000"), - ], - ), - ] - ), - ), - ( - "tests/in/011000.yaml", - Compose( - [ - Service( - name="frontend", - image="awesome/webapp", - ), - Service( - name="monitoring", - image="awesome/monitoring", - depends_on=["backend"], - volumes=[ - Volume(source="db-data", target="/data"), - Volume( - source="/var/run/postgres/postgres.sock", - target="/var/run/postgres/postgres.sock", - type=VolumeType.bind, + source="cli-volume", + target="/var/lib/backup/data", + access_mode="ro,z", ), ], ), - Service( - name="backend", - image="awesome/backend", - ), - ] - ), - ), - ( - "tests/in/011001.yaml", - Compose( - [ - Service( - name="frontend", - image="awesome/webapp", - networks=["front-tier", "back-tier"], - ), - Service( - name="monitoring", - image="awesome/monitoring", - networks=["admin"], - ), - Service( - name="backend", - image="awesome/backend", - networks=["back-tier", "admin"], - volumes=[ - Volume(source="db-data", target="/data"), - Volume( - source="/var/run/postgres/postgres.sock", - target="/var/run/postgres/postgres.sock", - type=VolumeType.bind, - ), - ], - depends_on=["monitoring"], - ), - ] - ), - ), - ( - "tests/in/011010.yaml", - Compose( - [ - Service( - name="frontend", - image="awesome/webapp", - ), - Service( - name="monitoring", - image="awesome/monitoring", - ), - Service( - name="backend", - volumes=[ - Volume(source="db-data", target="/data"), - Volume( - source="/var/run/postgres/postgres.sock", - target="/var/run/postgres/postgres.sock", - type=VolumeType.bind, - ), - ], - depends_on=["monitoring"], - extends=Extends(service_name="frontend"), - ), - ] - ), - ), - ( - "tests/in/011011.yaml", - Compose( - [ - Service( - name="frontend", - image="awesome/webapp", - networks=["front-tier", "back-tier"], - ), - Service( - name="monitoring", - image="awesome/monitoring", - networks=["admin"], - ), - Service( - name="backend", - networks=["back-tier", "admin"], - volumes=[ - Volume(source="db-data", target="/data"), - Volume( - source="/var/run/postgres/postgres.sock", - target="/var/run/postgres/postgres.sock", - type=VolumeType.bind, - ), - ], - depends_on=["monitoring"], - extends=Extends(service_name="frontend"), - ), - ] - ), - ), - ( - "tests/in/011100.yaml", - Compose( - [ - Service( - name="frontend", - image="awesome/webapp", - ports=[ - Port(host_port="8000", container_port="5000"), - ], - ), - Service( - name="monitoring", - image="awesome/monitoring", - ports=[ - Port(host_port="8000", container_port="5010"), - ], - volumes=[ - Volume(source="db-data", target="/data"), - Volume( - source="/var/run/postgres/postgres.sock", - target="/var/run/postgres/postgres.sock", - type=VolumeType.bind, - ), - ], - depends_on=["backend"], - ), - Service( - name="backend", - image="awesome/backend", - ports=[ - Port(host_port="8000", container_port="5001"), - ], - ), - ] - ), - ), - ( - "tests/in/011101.yaml", - Compose( - [ - Service( - name="frontend", - image="awesome/webapp", - networks=["front-tier", "back-tier"], - ), - Service( - name="monitoring", - image="awesome/monitoring", - networks=["admin"], - ), - Service( - name="backend", - image="awesome/backend", - networks=["back-tier", "admin"], - volumes=[ - Volume(source="db-data", target="/data"), - Volume( - source="/var/run/postgres/postgres.sock", - target="/var/run/postgres/postgres.sock", - type=VolumeType.bind, - ), - ], - depends_on=["monitoring"], - ports=[ - Port(host_port="8000", container_port="5010"), - ], - ), - ] - ), - ), - ( - "tests/in/011110.yaml", - Compose( - [ - Service( - name="frontend", - image="awesome/webapp", - ), - Service( - name="monitoring", - image="awesome/monitoring", - ), - Service( - name="backend", - volumes=[ - Volume(source="db-data", target="/data"), - Volume( - source="/var/run/postgres/postgres.sock", - target="/var/run/postgres/postgres.sock", - type=VolumeType.bind, - ), - ], - depends_on=["monitoring"], - extends=Extends(service_name="frontend"), - ports=[ - Port(host_port="8000", container_port="5010"), - ], - ), - ] - ), - ), - ( - "tests/in/011111.yaml", - Compose( - [ - Service( - name="frontend", - image="awesome/webapp", - networks=["front-tier", "back-tier"], - ), - Service( - name="monitoring", - image="awesome/monitoring", - networks=["admin"], - ), - Service( - name="backend", - networks=["back-tier", "admin"], - volumes=[ - Volume(source="db-data", target="/data"), - Volume( - source="/var/run/postgres/postgres.sock", - target="/var/run/postgres/postgres.sock", - type=VolumeType.bind, - ), - ], - depends_on=["monitoring"], - extends=Extends(service_name="frontend"), - ports=[ - Port(host_port="8000", container_port="5010"), - ], - ), - ] - ), - ), - ( - "tests/in/100000.yaml", - Compose( - [ - Service( - name="web", - image="build from .", - links=["db:database"], - ), - Service( - name="db", - image="postgres", - ), - ] - ), - ), - ( - "tests/in/100001.yaml", - Compose( - [ - Service( - name="frontend", - image="awesome/webapp", - networks=["front-tier", "back-tier"], - ), - Service( - name="monitoring", - image="awesome/monitoring", - networks=["admin"], - ), - Service( - name="backend", - image="awesome/backend", - networks=["back-tier", "admin"], - links=["db:database"], - ), - Service( - name="db", - image="postgres", - ), - ] - ), - ), - ( - "tests/in/100010.yaml", - Compose( - [ - Service( - name="frontend", - image="awesome/webapp", - ), - Service( - name="monitoring", - image="awesome/monitoring", - ), - Service( - name="backend", - extends=Extends(service_name="frontend"), - links=["db:database"], - ), - Service( - name="db", - image="postgres", - ), - ] - ), - ), - ( - "tests/in/100011.yaml", - Compose( - [ - Service( - name="frontend", - image="awesome/webapp", - networks=["front-tier", "back-tier"], - ), - Service( - name="monitoring", - image="awesome/monitoring", - networks=["admin"], - ), - Service( - name="backend", - networks=["back-tier", "admin"], - extends=Extends(service_name="frontend"), - links=["db:database"], - ), - Service( - name="db", - image="postgres", - ), - ] - ), - ), - ( - "tests/in/100100.yaml", - Compose( - [ - Service( - name="frontend", - image="awesome/webapp", - ), - Service( - name="monitoring", - image="awesome/monitoring", - ), - Service( - name="backend", - image="awesome/backend", - ports=[ - Port(host_port="8000", container_port="5010"), - ], - links=["db:database"], - ), - Service( - name="db", - image="postgres", - ), - ] - ), - ), - ( - "tests/in/100101.yaml", - Compose( - [ - Service( - name="frontend", - image="awesome/webapp", - networks=["front-tier", "back-tier"], - ), - Service( - name="monitoring", - image="awesome/monitoring", - networks=["admin"], - ), - Service( - name="backend", - image="awesome/backend", - networks=["back-tier", "admin"], - ports=[ - Port(host_port="8000", container_port="5010"), - ], - links=["db:database"], - ), - Service( - name="db", - image="postgres", - ), - ] - ), - ), - ( - "tests/in/100110.yaml", - Compose( - [ - Service( - name="frontend", - image="awesome/webapp", - ), - Service( - name="monitoring", - image="awesome/monitoring", - ), - Service( - name="backend", - extends=Extends(service_name="frontend"), - ports=[ - Port(host_port="8000", container_port="5010"), - ], - links=["db:database"], - ), - Service( - name="db", - image="postgres", - ), - ] - ), - ), - ( - "tests/in/100111.yaml", - Compose( - [ - Service( - name="frontend", - image="awesome/webapp", - networks=["front-tier", "back-tier"], - ), - Service( - name="monitoring", - image="awesome/monitoring", - networks=["admin"], - ), - Service( - name="backend", - networks=["back-tier", "admin"], - extends=Extends(service_name="frontend"), - ports=[ - Port(host_port="8000", container_port="5010"), - ], - links=["db:database"], - ), - Service( - name="db", - image="postgres", - ), - ] - ), - ), - ( - "tests/in/101000.yaml", - Compose( - [ - Service( - name="frontend", - image="awesome/webapp", - ), - Service( - name="monitoring", - image="awesome/monitoring", - ), - Service( - name="backend", - image="awesome/backend", - depends_on=["monitoring"], - links=["db:database"], - ), - Service( - name="db", - image="postgres", - ), - ] - ), - ), - ( - "tests/in/101001.yaml", - Compose( - [ - Service( - name="frontend", - image="awesome/webapp", - networks=["front-tier", "back-tier"], - ), - Service( - name="monitoring", - image="awesome/monitoring", - networks=["admin"], - ), - Service( - name="backend", - image="awesome/backend", - networks=["back-tier", "admin"], - depends_on=["monitoring"], - links=["db:database"], - ), - Service( - name="db", - image="postgres", - ), - ] - ), - ), - ( - "tests/in/101010.yaml", - Compose( - [ - Service( - name="frontend", - image="awesome/webapp", - ), - Service( - name="monitoring", - image="awesome/monitoring", - ), - Service( - name="backend", - depends_on=["monitoring"], - extends=Extends(service_name="frontend"), - links=["db:database"], - ), - Service( - name="db", - image="postgres", - ), - ] - ), - ), - ( - "tests/in/101011.yaml", - Compose( - [ - Service( - name="frontend", - image="awesome/webapp", - networks=["front-tier", "back-tier"], - ), - Service( - name="monitoring", - image="awesome/monitoring", - networks=["admin"], - ), - Service( - name="backend", - networks=["back-tier", "admin"], - depends_on=["monitoring"], - extends=Extends(service_name="frontend"), - links=["db:database"], - ), - Service( - name="db", - image="postgres", - ), - ] - ), - ), - ( - "tests/in/101100.yaml", - Compose( - [ - Service( - name="frontend", - image="awesome/webapp", - ), - Service( - name="monitoring", - image="awesome/monitoring", - ), - Service( - name="backend", - image="awesome/backend", - depends_on=["monitoring"], - ports=[ - Port(host_port="8000", container_port="5010"), - ], - links=["db:database"], - ), - Service( - name="db", - image="postgres", - ), - ] - ), - ), - ( - "tests/in/101101.yaml", - Compose( - [ - Service( - name="frontend", - image="awesome/webapp", - networks=["front-tier", "back-tier"], - ), - Service( - name="monitoring", - image="awesome/monitoring", - networks=["admin"], - ), - Service( - name="backend", - image="awesome/backend", - networks=["back-tier", "admin"], - depends_on=["monitoring"], - ports=[ - Port(host_port="8000", container_port="5010"), - ], - links=["db:database"], - ), - Service( - name="db", - image="postgres", - ), - ] - ), - ), - ( - "tests/in/101110.yaml", - Compose( - [ - Service( - name="frontend", - image="awesome/webapp", - ), - Service( - name="monitoring", - image="awesome/monitoring", - ), - Service( - name="backend", - depends_on=["monitoring"], - extends=Extends(service_name="frontend"), - ports=[ - Port(host_port="8000", container_port="5010"), - ], - links=["db:database"], - ), - Service( - name="db", - image="postgres", - ), - ] - ), - ), - ( - "tests/in/101111.yaml", - Compose( - [ - Service( - name="frontend", - image="awesome/webapp", - networks=["front-tier", "back-tier"], - ), - Service( - name="monitoring", - image="awesome/monitoring", - networks=["admin"], - ), - Service( - name="backend", - networks=["back-tier", "admin"], - depends_on=["monitoring"], - extends=Extends(service_name="frontend"), - ports=[ - Port(host_port="8000", container_port="5010"), - ], - links=["db:database"], - ), - Service( - name="db", - image="postgres", - ), - ] - ), - ), - ( - "tests/in/110000.yaml", - Compose( - [ - Service( - name="frontend", - image="awesome/webapp", - ), - Service( - name="monitoring", - image="awesome/monitoring", - volumes=[ - Volume(source="db-data", target="/data"), - Volume( - source="/var/run/postgres/postgres.sock", - target="/var/run/postgres/postgres.sock", - type=VolumeType.bind, - ), - ], - links=["db:database"], - ), - Service( - name="backend", - image="awesome/backend", - ), - Service( - name="db", - image="postgres", - ), - ] - ), - ), - ( - "tests/in/110001.yaml", - Compose( - [ - Service( - name="frontend", - image="awesome/webapp", - networks=["front-tier", "back-tier"], - ), - Service( - name="monitoring", - image="awesome/monitoring", - networks=["admin"], - ), - Service( - name="backend", - image="awesome/backend", - networks=["back-tier", "admin"], - volumes=[ - Volume(source="db-data", target="/data"), - Volume( - source="/var/run/postgres/postgres.sock", - target="/var/run/postgres/postgres.sock", - type=VolumeType.bind, - ), - ], - links=["db:database"], - ), - Service( - name="db", - image="postgres", - ), - ] - ), - ), - ( - "tests/in/110010.yaml", - Compose( - [ - Service( - name="frontend", - image="awesome/webapp", - ), - Service( - name="monitoring", - image="awesome/monitoring", - ), - Service( - name="backend", - volumes=[ - Volume(source="db-data", target="/data"), - Volume( - source="/var/run/postgres/postgres.sock", - target="/var/run/postgres/postgres.sock", - type=VolumeType.bind, - ), - ], - extends=Extends(service_name="frontend"), - links=["db:database"], - ), - Service( - name="db", - image="postgres", - ), - ] - ), - ), - ( - "tests/in/110011.yaml", - Compose( - [ - Service( - name="frontend", - image="awesome/webapp", - networks=["front-tier", "back-tier"], - ), - Service( - name="monitoring", - image="awesome/monitoring", - networks=["admin"], - ), - Service( - name="backend", - networks=["back-tier", "admin"], - volumes=[ - Volume(source="db-data", target="/data"), - Volume( - source="/var/run/postgres/postgres.sock", - target="/var/run/postgres/postgres.sock", - type=VolumeType.bind, - ), - ], - extends=Extends(service_name="frontend"), - links=["db:database"], - ), - Service( - name="db", - image="postgres", - ), - ] - ), - ), - ( - "tests/in/110100.yaml", - Compose( - [ - Service( - name="frontend", - image="awesome/webapp", - ), - Service( - name="monitoring", - image="awesome/monitoring", - ), - Service( - name="backend", - image="awesome/backend", - volumes=[ - Volume(source="db-data", target="/data"), - Volume( - source="/var/run/postgres/postgres.sock", - target="/var/run/postgres/postgres.sock", - type=VolumeType.bind, - ), - ], - ports=[ - Port(host_port="8000", container_port="5010"), - ], - links=["db:database"], - ), - Service( - name="db", - image="postgres", - ), - ] - ), - ), - ( - "tests/in/110101.yaml", - Compose( - [ - Service( - name="frontend", - image="awesome/webapp", - networks=["front-tier", "back-tier"], - ), - Service( - name="monitoring", - image="awesome/monitoring", - networks=["admin"], - ), - Service( - name="backend", - image="awesome/backend", - networks=["back-tier", "admin"], - volumes=[ - Volume(source="db-data", target="/data"), - Volume( - source="/var/run/postgres/postgres.sock", - target="/var/run/postgres/postgres.sock", - type=VolumeType.bind, - ), - ], - ports=[ - Port(host_port="8000", container_port="5010"), - ], - links=["db:database"], - ), - Service( - name="db", - image="postgres", - ), - ] - ), - ), - ( - "tests/in/110110.yaml", - Compose( - [ - Service( - name="frontend", - image="awesome/webapp", - ), - Service( - name="monitoring", - image="awesome/monitoring", - ), - Service( - name="backend", - volumes=[ - Volume(source="db-data", target="/data"), - Volume( - source="/var/run/postgres/postgres.sock", - target="/var/run/postgres/postgres.sock", - type=VolumeType.bind, - ), - ], - extends=Extends(service_name="frontend"), - ports=[ - Port(host_port="8000", container_port="5010"), - ], - links=["db:database"], - ), - Service( - name="db", - image="postgres", - ), - ] - ), - ), - ( - "tests/in/110111.yaml", - Compose( - [ - Service( - name="frontend", - image="awesome/webapp", - networks=["front-tier", "back-tier"], - ), - Service( - name="monitoring", - image="awesome/monitoring", - networks=["admin"], - ), - Service( - name="backend", - networks=["back-tier", "admin"], - volumes=[ - Volume(source="db-data", target="/data"), - Volume( - source="/var/run/postgres/postgres.sock", - target="/var/run/postgres/postgres.sock", - type=VolumeType.bind, - ), - ], - extends=Extends(service_name="frontend"), - ports=[ - Port(host_port="8000", container_port="5010"), - ], - links=["db:database"], - ), - Service( - name="db", - image="postgres", - ), - ] - ), - ), - ( - "tests/in/111000.yaml", - Compose( - [ - Service( - name="frontend", - image="awesome/webapp", - ), - Service( - name="monitoring", - image="awesome/monitoring", - depends_on=["backend"], - volumes=[ - Volume(source="db-data", target="/data"), - Volume( - source="/var/run/postgres/postgres.sock", - target="/var/run/postgres/postgres.sock", - type=VolumeType.bind, - ), - ], - links=["db:database"], - ), - Service( - name="backend", - image="awesome/backend", - ), - Service( - name="db", - image="postgres", - ), - ] - ), - ), - ( - "tests/in/111001.yaml", - Compose( - [ - Service( - name="frontend", - image="awesome/webapp", - networks=["front-tier", "back-tier"], - ), - Service( - name="monitoring", - image="awesome/monitoring", - networks=["admin"], - ), - Service( - name="backend", - image="awesome/backend", - networks=["back-tier", "admin"], - volumes=[ - Volume(source="db-data", target="/data"), - Volume( - source="/var/run/postgres/postgres.sock", - target="/var/run/postgres/postgres.sock", - type=VolumeType.bind, - ), - ], - depends_on=["monitoring"], - links=["db:database"], - ), - Service( - name="db", - image="postgres", - ), - ] - ), - ), - ( - "tests/in/111010.yaml", - Compose( - [ - Service( - name="frontend", - image="awesome/webapp", - ), - Service( - name="monitoring", - image="awesome/monitoring", - ), - Service( - name="backend", - volumes=[ - Volume(source="db-data", target="/data"), - Volume( - source="/var/run/postgres/postgres.sock", - target="/var/run/postgres/postgres.sock", - type=VolumeType.bind, - ), - ], - depends_on=["monitoring"], - extends=Extends(service_name="frontend"), - links=["db:database"], - ), - Service( - name="db", - image="postgres", - ), - ] - ), - ), - ( - "tests/in/111011.yaml", - Compose( - [ - Service( - name="frontend", - image="awesome/webapp", - networks=["front-tier", "back-tier"], - ), - Service( - name="monitoring", - image="awesome/monitoring", - networks=["admin"], - ), - Service( - name="backend", - networks=["back-tier", "admin"], - volumes=[ - Volume(source="db-data", target="/data"), - Volume( - source="/var/run/postgres/postgres.sock", - target="/var/run/postgres/postgres.sock", - type=VolumeType.bind, - ), - ], - depends_on=["monitoring"], - extends=Extends(service_name="frontend"), - links=["db:database"], - ), - Service( - name="db", - image="postgres", - ), - ] - ), - ), - ( - "tests/in/111100.yaml", - Compose( - [ - Service( - name="frontend", - image="awesome/webapp", - ), - Service( - name="monitoring", - image="awesome/monitoring", - ), - Service( - name="backend", - image="awesome/backend", - volumes=[ - Volume(source="db-data", target="/data"), - Volume( - source="/var/run/postgres/postgres.sock", - target="/var/run/postgres/postgres.sock", - type=VolumeType.bind, - ), - ], - depends_on=["monitoring"], - ports=[ - Port(host_port="8000", container_port="5010"), - ], - links=["db:database"], - ), - Service( - name="db", - image="postgres", - ), - ] - ), - ), - ( - "tests/in/111101.yaml", - Compose( - [ - Service( - name="frontend", - image="awesome/webapp", - networks=["front-tier", "back-tier"], - ), - Service( - name="monitoring", - image="awesome/monitoring", - networks=["admin"], - ), - Service( - name="backend", - image="awesome/backend", - networks=["back-tier", "admin"], - volumes=[ - Volume(source="db-data", target="/data"), - Volume( - source="/var/run/postgres/postgres.sock", - target="/var/run/postgres/postgres.sock", - type=VolumeType.bind, - ), - ], - depends_on=["monitoring"], - ports=[ - Port(host_port="8000", container_port="5010"), - ], - links=["db:database"], - ), - Service( - name="db", - image="postgres", - ), - ] - ), - ), - ( - "tests/in/111110.yaml", - Compose( - [ - Service( - name="frontend", - image="awesome/webapp", - ), - Service( - name="monitoring", - image="awesome/monitoring", - ), - Service( - name="backend", - volumes=[ - Volume(source="db-data", target="/data"), - Volume( - source="/var/run/postgres/postgres.sock", - target="/var/run/postgres/postgres.sock", - type=VolumeType.bind, - ), - ], - depends_on=["monitoring"], - extends=Extends(service_name="frontend"), - ports=[ - Port(host_port="8000", container_port="5010"), - ], - links=["db:database"], - ), - Service( - name="db", - image="postgres", - ), - ] - ), - ), - ( - "tests/in/111111.yaml", - Compose( - [ - Service( - name="frontend", - image="awesome/webapp", - networks=["front-tier", "back-tier"], - ), - Service( - name="monitoring", - image="awesome/monitoring", - networks=["admin"], - ), - Service( - name="backend", - networks=["back-tier", "admin"], - volumes=[ - Volume(source="db-data", target="/data"), - Volume( - source="/var/run/postgres/postgres.sock", - target="/var/run/postgres/postgres.sock", - type=VolumeType.bind, - ), - ], - depends_on=["monitoring"], - extends=Extends(service_name="frontend"), - ports=[ - Port(host_port="8000", container_port="5010"), - ], - links=["db:database"], - ), - Service( - name="db", - image="postgres", - ), - ] + ], ), ), ], ) -def test_parse_file(test_input: str, expected: Compose) -> None: +def test_parse_file(test_file_path: str, expected: Compose) -> None: parser = Parser() - actual = parser.parse(test_input) + actual = parser.parse(f"tests/ymls/{test_file_path}.yml") assert len(actual.services) == len(expected.services) diff --git a/tests/test_parser.py b/tests/test_parser.py index e541a70..0e3d33f 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -4,15 +4,15 @@ from compose_viz.parser import Parser def test_parser_error_parsing_file() -> None: - with pytest.raises(RuntimeError, match=r"Error parsing file 'tests/in/invalid.yaml'.*"): - Parser().parse("tests/in/invalid.yaml") + with pytest.raises(RuntimeError, match=r"Error parsing file 'tests/ymls/others/invalid.yml'.*"): + Parser().parse("tests/ymls/others/invalid.yml") def test_parser_invalid_yaml() -> None: with pytest.raises(RuntimeError, match=r"Empty yaml file, aborting."): - Parser().parse("tests/in/000000.yaml") + Parser().parse("tests/ymls/others/empty.yml") def test_parser_no_services_found() -> None: with pytest.raises(RuntimeError, match=r"No services found, aborting."): - Parser().parse("tests/in/no-services.yaml") + Parser().parse("tests/ymls/others/no-services.yml") diff --git a/tests/test_port.py b/tests/test_port.py index c7baf39..159c92c 100644 --- a/tests/test_port.py +++ b/tests/test_port.py @@ -7,7 +7,7 @@ def test_port_init_normal() -> None: assert p.host_port == "8080" assert p.container_port == "80" - assert p.protocol == Protocol.tcp + assert p.protocol == Protocol.any except Exception as e: assert False, e diff --git a/tests/test_service.py b/tests/test_service.py deleted file mode 100644 index 1f56b33..0000000 --- a/tests/test_service.py +++ /dev/null @@ -1,18 +0,0 @@ -import pytest - -from compose_viz.extends import Extends -from compose_viz.service import Service - - -def test_service_init() -> None: - with pytest.raises( - AttributeError, match=r"Both image and extends are not defined in service 'frontend', aborting." - ): - Service(name="frontend") - - with pytest.raises( - AttributeError, match=r"Only one of image and extends can be defined in service 'frontend', aborting." - ): - Service( - name="frontend", image="image", extends=Extends(service_name="frontend", from_file="tests/in/000001.yaml") - ) diff --git a/tests/test_volume.py b/tests/test_volume.py index d1d4cac..b3651ec 100644 --- a/tests/test_volume.py +++ b/tests/test_volume.py @@ -1,4 +1,4 @@ -from compose_viz.volume import AccessMode, Volume, VolumeType +from compose_viz.volume import Volume, VolumeType def test_volume_init_normal() -> None: @@ -8,7 +8,7 @@ def test_volume_init_normal() -> None: assert v.source == "./foo" assert v.target == "./bar" assert v.type == VolumeType.volume - assert v.access_mode == AccessMode.rw + assert v.access_mode == "rw" except Exception as e: assert False, e @@ -20,18 +20,18 @@ def test_volume_with_type() -> None: assert v.source == "./foo" assert v.target == "./bar" assert v.type == VolumeType.bind - assert v.access_mode == AccessMode.rw + assert v.access_mode == "rw" except Exception as e: assert False, e def test_volume_with_access_mode() -> None: try: - v = Volume(source="./foo", target="./bar", access_mode=AccessMode.ro) + v = Volume(source="./foo", target="./bar", access_mode="ro,z") assert v.source == "./foo" assert v.target == "./bar" assert v.type == VolumeType.volume - assert v.access_mode == AccessMode.ro + assert v.access_mode == "ro,z" except Exception as e: assert False, e diff --git a/tests/ymls/builds/docker-compose.yml b/tests/ymls/builds/docker-compose.yml new file mode 100644 index 0000000..e55248f --- /dev/null +++ b/tests/ymls/builds/docker-compose.yml @@ -0,0 +1,12 @@ +version: "3.9" + +services: + frontend: + image: awesome/frontend + build: ./frontend + + backend: + image: awesome/backend + build: + context: backend + dockerfile: ../backend.Dockerfile \ No newline at end of file diff --git a/tests/ymls/depends_on/docker-compose.yml b/tests/ymls/depends_on/docker-compose.yml new file mode 100644 index 0000000..e949719 --- /dev/null +++ b/tests/ymls/depends_on/docker-compose.yml @@ -0,0 +1,19 @@ +version: "3.9" + +services: + frontend: + image: awesome/frontend + depends_on: + db: + condition: service_healthy + redis: + condition: service_started + backend: + image: awesome/backend + depends_on: + - db + - redis + db: + image: mysql + redis: + image: redis diff --git a/tests/ymls/extends/docker-compose.yml b/tests/ymls/extends/docker-compose.yml new file mode 100644 index 0000000..149b396 --- /dev/null +++ b/tests/ymls/extends/docker-compose.yml @@ -0,0 +1,14 @@ +version: "3.9" + +services: + base: + image: alpine:latest + tty: true + derive_from_base: + image: alpine:edge + extends: + service: base + derive_from_file: + extends: + file: web.yml + service: web \ No newline at end of file diff --git a/tests/ymls/extends/web.yml b/tests/ymls/extends/web.yml new file mode 100644 index 0000000..1452125 --- /dev/null +++ b/tests/ymls/extends/web.yml @@ -0,0 +1,5 @@ +version: "3.9" + +services: + web: + image: awesome/web \ No newline at end of file diff --git a/tests/in/100000.yaml b/tests/ymls/links/docker-compose.yml similarity index 53% rename from tests/in/100000.yaml rename to tests/ymls/links/docker-compose.yml index 7ea23ec..56fcc07 100644 --- a/tests/in/100000.yaml +++ b/tests/ymls/links/docker-compose.yml @@ -1,9 +1,9 @@ version: "3.9" -services: - web: - build: . +services: + frontend: + image: awesome/frontend links: - "db:database" db: - image: postgres + image: mysql \ No newline at end of file diff --git a/tests/in/000001.yaml b/tests/ymls/networks/docker-compose.yml similarity index 88% rename from tests/in/000001.yaml rename to tests/ymls/networks/docker-compose.yml index b6e30ec..9210e39 100644 --- a/tests/in/000001.yaml +++ b/tests/ymls/networks/docker-compose.yml @@ -1,6 +1,8 @@ +version: "3.9" + services: frontend: - image: awesome/webapp + image: awesome/frontend networks: - front-tier - back-tier diff --git a/tests/in/000000.yaml b/tests/ymls/others/empty.yml similarity index 100% rename from tests/in/000000.yaml rename to tests/ymls/others/empty.yml diff --git a/tests/in/invalid.yaml b/tests/ymls/others/invalid.yml similarity index 100% rename from tests/in/invalid.yaml rename to tests/ymls/others/invalid.yml diff --git a/tests/in/no-services.yaml b/tests/ymls/others/no-services.yml similarity index 100% rename from tests/in/no-services.yaml rename to tests/ymls/others/no-services.yml diff --git a/tests/ymls/ports/docker-compose.yml b/tests/ymls/ports/docker-compose.yml new file mode 100644 index 0000000..642a975 --- /dev/null +++ b/tests/ymls/ports/docker-compose.yml @@ -0,0 +1,18 @@ +version: "3.9" + +services: + frontend: + image: awesome/frontend + ports: + - "3000" + - "3000-3005" + - "9090-9091:8080-8081" + - "49100:22" + - "127.0.0.1:8001:8001" + - "127.0.0.1:5000-5010:5000-5010" + - "6060:6060/udp" + - target: 80 + host_ip: 127.0.0.1 + published: 8080 + protocol: tcp + - target: 443 diff --git a/tests/ymls/volumes/docker-compose.yml b/tests/ymls/volumes/docker-compose.yml new file mode 100644 index 0000000..4edb77c --- /dev/null +++ b/tests/ymls/volumes/docker-compose.yml @@ -0,0 +1,23 @@ +version: "3.9" + +services: + backend: + image: awesome/backend + volumes: + - "./data:/data" + - type: bind + source: /var/run/postgres/postgres.sock + target: /var/run/postgres/postgres.sock + common: + image: busybox + volumes: + - common-volume:/var/lib/backup/data:rw,z + cli: + extends: + service: common + volumes: + - cli-volume:/var/lib/backup/data:ro + +volumes: + common-volume: + cli-volume: