Skip to content

Commit

Permalink
Bugfix ecs_composex.ecs.ecs_family.ComposeFamily.task_ephemeral_storage
Browse files Browse the repository at this point in the history
  • Loading branch information
thorfi committed Nov 29, 2023
1 parent 89f8292 commit ea734af
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
11 changes: 5 additions & 6 deletions ecs_composex/compose/compose_services/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,10 +504,10 @@ def container_start_condition(self, value):
@property
def ephemeral_storage(self):
storage_key = "ecs.ephemeral.storage"
storage_value = set_else_none(
storage_key, set_else_none("labels", self.deploy, alt_value={}), alt_value=0
)
if isinstance(storage_value, (int, float)):
storage_value = set_else_none(storage_key, self.deploy_labels)
if storage_value is None:
return 0
elif isinstance(storage_value, (int, float)):
ephemeral_storage = int(storage_value)
elif isinstance(storage_value, str):
ephemeral_storage = int(set_memory_to_mb(storage_value) / 1024)
Expand All @@ -518,13 +518,12 @@ def ephemeral_storage(self):
"Expected one of",
[int, float, str],
)
LOG.info(f"{self.name} - {storage_key} set to {ephemeral_storage}")
if ephemeral_storage <= 21:
return 0

elif ephemeral_storage > 200:
return 200
else:
LOG.info(f"{self.name} - {storage_key} set to {ephemeral_storage}")
return int(ephemeral_storage)

@property
Expand Down
11 changes: 5 additions & 6 deletions ecs_composex/ecs/ecs_family/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def __init__(self, services: list[ComposeService], family_name):
self.xray_service = None
self.task_definition = None
self.service_tags = None
self.task_ephemeral_storage = 0
# self.task_ephemeral_storage = 0
self.enable_execute_command = False
self.ecs_service = None
self.runtime_cpu_arch = None
Expand Down Expand Up @@ -201,7 +201,7 @@ def set_task_definition(self):
EphemeralStorage(SizeInGiB=self.task_ephemeral_storage),
NoValue,
)
if 0 < self.task_ephemeral_storage >= 21
if self.task_ephemeral_storage >= 21
else NoValue,
InferenceAccelerators=NoValue,
IpcMode=If(
Expand Down Expand Up @@ -370,7 +370,6 @@ def add_service(self, service: ComposeService):
service.container_definition
)
self.set_secrets_access()
self.set_task_ephemeral_storage()
set_enable_execute_command(self)
set_family_hostname(self)

Expand Down Expand Up @@ -596,13 +595,13 @@ def set_services_to_services_dependencies(self):
if service_depends_on not in self.services_depends_on:
self.services_depends_on.append(service_depends_on)

def set_task_ephemeral_storage(self):
@property
def task_ephemeral_storage(self):
"""
If any service ephemeral storage is defined above, sets the ephemeral storage to the maximum of them.
"""
max_storage = max(service.ephemeral_storage for service in self.services)
if max_storage >= 21:
self.task_ephemeral_storage = max_storage
return max_storage if max_storage >= 21 else 0

def set_enable_execute_command(self) -> None:
"""
Expand Down

0 comments on commit ea734af

Please sign in to comment.