Skip to content

Commit 84fa113

Browse files
authored
compose - depends_on as object (#757)
1 parent 6ecb774 commit 84fa113

File tree

7 files changed

+25
-14
lines changed

7 files changed

+25
-14
lines changed

ecs_composex/compose/compose_services/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,12 @@ def __init__(
133133
self.cfn_environment = (
134134
import_env_variables(self.environment) if self.environment else NoValue
135135
)
136-
self.depends_on = set_else_none("depends_on", self.definition, [], False)
136+
self.depends_on: dict = set_else_none("depends_on", self.definition, {}, False)
137+
if isinstance(self.depends_on, list):
138+
services_names = [_s_name for _s_name in self.depends_on]
139+
self.depends_on: dict = {}
140+
for service_name in services_names:
141+
self.depends_on[service_name] = {"condition": "service_started"}
137142
self.docker_labels: dict = {}
138143
self.import_docker_labels(self._definition)
139144

ecs_composex/ecs/ecs_family/__init__.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def __init__(self, services: list[ComposeService], family_name):
7878
self.managed_sidecars = []
7979
self.name = family_name
8080
self.family_hostname = self.name.replace("_", "-").lower()
81-
self.services_depends_on = []
81+
self.services_depends_on: dict = {}
8282
self.template = set_template(self)
8383
self.stack: ServiceStack = ServiceStack(
8484
self.logical_name,
@@ -585,9 +585,15 @@ def set_services_to_services_dependencies(self):
585585
"""
586586
for service in self.services:
587587
if service.depends_on:
588-
for service_depends_on in service.depends_on:
589-
if service_depends_on not in self.services_depends_on:
590-
self.services_depends_on.append(service_depends_on)
588+
if not isinstance(service.depends_on, dict):
589+
raise TypeError(
590+
"Service depends_on not a dict",
591+
service.name,
592+
service.depends_on,
593+
)
594+
for service_name, condition_def in service.depends_on.items():
595+
if service_name not in self.services_depends_on:
596+
self.services_depends_on[service_name] = {}
591597

592598
@property
593599
def task_ephemeral_storage(self) -> int:

ecs_composex/ecs/ecs_firelens/ecs_firelens_advanced/firelens_config_sidecar.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,4 @@ def __init__(
102102
patch_fluent_service(
103103
fluent_service, shared_volume, name, shared_volume.name, mount_path
104104
)
105-
fluent_service.depends_on.append(self.name)
105+
fluent_service.depends_on[self.name] = {"condition": "service_started"}

ecs_composex/ecs/ecs_firelens/firelens_managed_sidecar_service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ def set_as_dependency_to_family_services(self, is_dependency: bool = True) -> No
186186
if service is self:
187187
continue
188188
if self.name not in service.depends_on:
189-
service.depends_on.append(self.name)
189+
service.depends_on[self.name] = {"condition": "service_healthy"}
190190
LOG.info(
191191
f"{self.family.name}.{service.name} - Added {self.name} as startup dependency"
192192
)

ecs_composex/ecs/ecs_stack.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def handle_families_dependencies(
7676
"""
7777
for family_def in families_post:
7878
_family_title, _family_name = family_def
79-
for family_name in settings.families[_family_title].services_depends_on:
79+
for family_name in settings.families[_family_title].services_depends_on.keys():
8080
for __family_title, __family_def in settings.families.items():
8181
if __family_def.name == family_name:
8282
family_title = __family_title

ecs_composex/ecs/managed_sidecars/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,13 @@ def set_as_dependency_to_family_services(self, is_dependency: bool = False) -> N
6565
for service in self.family.ordered_services:
6666
if is_dependency:
6767
if self.name not in service.depends_on:
68-
service.depends_on.append(self.name)
68+
service.depends_on[self.name] = {"condition": "service_started"}
6969
LOG.info(
7070
f"{self.family.name}.{service.name} - Added {self.name} as startup dependency"
7171
)
7272
else:
7373
if service.name not in self.depends_on:
74-
self.depends_on.append(service.name)
74+
self.depends_on[service.name] = {"condition": "service_started"}
7575
LOG.info(
7676
f"{self.family.name}.{self.name} - Added {service.name} as startup dependency"
7777
)

use-cases/dynamodb/create_lookup_services_mappings_cloudmap.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ x-dynamodb:
8282
tableC:
8383
Lookup:
8484
Tags:
85-
- name: tableC
86-
- createdbycomposex: 'True'
85+
name: tableC
86+
createdbycomposex: 'True'
8787
Services:
8888
app03:
8989
Access: RW
@@ -101,8 +101,8 @@ x-dynamodb:
101101
tableD:
102102
Lookup:
103103
Tags:
104-
- name: tableC
105-
- createdbycomposex: 'False'
104+
name: tableC
105+
createdbycomposex: 'False'
106106
Services:
107107
app03:
108108
Access: RW

0 commit comments

Comments
 (0)