Skip to content

Commit

Permalink
Fix single-container unset settings on family__init__ (#721)
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnPreston authored Nov 29, 2023
1 parent 476bad5 commit 9cd964c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
13 changes: 10 additions & 3 deletions ecs_composex/compose/compose_services/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,9 +502,11 @@ def container_start_condition(self, value):
self.deploy: dict = {"labels": {depends_key: value}}

@property
def ephemeral_storage(self):
def ephemeral_storage(self) -> int:
storage_key = "ecs.ephemeral.storage"
storage_value = set_else_none(storage_key, self.deploy_labels, 0)
if not storage_value:
return 0
if isinstance(storage_value, (int, float)):
ephemeral_storage = int(storage_value)
elif isinstance(storage_value, str):
Expand All @@ -517,12 +519,17 @@ def ephemeral_storage(self):
[int, float, str],
)
if ephemeral_storage <= 21:
LOG.debug(
f"{self.name} - {storage_key} - defined value is <= 21. Leaving to default"
)
return 0
elif ephemeral_storage > 200:
LOG.warning(f"{self.name} - {storage_key} set to maximum 200 ({ephemeral_storage} > 200)")
LOG.warning(
f"{self.name} - {storage_key} set to maximum 200 ({ephemeral_storage} > 200)"
)
return 200
else:
LOG.info(f"{self.name} - {storage_key} set to {ephemeral_storage}")
LOG.debug(f"{self.name} - {storage_key} set to {ephemeral_storage}")
return int(ephemeral_storage)

@property
Expand Down
19 changes: 10 additions & 9 deletions ecs_composex/ecs/ecs_family/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

from ecs_composex.common.logging import LOG
from ecs_composex.common.stacks import ComposeXStack
from ecs_composex.common.troposphere_tools import Parameter
from ecs_composex.common.troposphere_tools import Parameter, add_outputs, add_parameters
from ecs_composex.compose.compose_services import ComposeService
from ecs_composex.ecs import ecs_conditions, ecs_params
from ecs_composex.ecs.ecs_family.family_helpers import (
Expand All @@ -41,12 +41,14 @@
from ecs_composex.ecs.managed_sidecars.aws_xray import set_xray
from ecs_composex.ecs.service_compute import ServiceCompute
from ecs_composex.ecs.service_networking import ServiceNetworking
from ecs_composex.ecs.service_networking.helpers import update_family_subnets
from ecs_composex.ecs.service_networking.helpers import (
set_family_hostname,
update_family_subnets,
)
from ecs_composex.ecs.service_scaling import ServiceScaling
from ecs_composex.ecs.task_compute import TaskCompute
from ecs_composex.ecs.task_iam import TaskIam

from ...common.troposphere_tools import add_outputs, add_parameters
from .family_helpers import assign_secrets_to_roles, ensure_essential_containers
from .family_template import set_template
from .task_runtime import define_family_runtime_parameters
Expand Down Expand Up @@ -89,7 +91,6 @@ 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.enable_execute_command = False
self.ecs_service = None
self.runtime_cpu_arch = None
Expand All @@ -105,6 +106,8 @@ def __init__(self, services: list[ComposeService], family_name):
self.service_networking = None
self.task_compute = None
self.service_compute = ServiceCompute(self)
self.set_enable_execute_command()
set_family_hostname(self)

@property
def logical_name(self) -> str:
Expand Down Expand Up @@ -355,9 +358,6 @@ def add_service(self, service: ComposeService):
Function to add new services (defined in the compose files). Not to use for managed sidecars
:param ComposeService service:
"""
from ecs_composex.ecs.service_networking.helpers import set_family_hostname

from .task_execute_command import set_enable_execute_command

self._compose_services.append(service)

Expand All @@ -370,7 +370,7 @@ def add_service(self, service: ComposeService):
service.container_definition
)
self.set_secrets_access()
set_enable_execute_command(self)
self.set_enable_execute_command()
set_family_hostname(self)

def add_managed_sidecar(self, service: ComposeService):
Expand Down Expand Up @@ -596,9 +596,10 @@ def set_services_to_services_dependencies(self):
self.services_depends_on.append(service_depends_on)

@property
def task_ephemeral_storage(self):
def task_ephemeral_storage(self) -> int:
"""
If any service ephemeral storage is defined above, sets the ephemeral storage to the maximum of them.
Return 0 if below 21 which is the default "free" Fargate storage space.
"""
max_storage = max(service.ephemeral_storage for service in self.services)
return max_storage if max_storage >= 21 else 0
Expand Down

0 comments on commit 9cd964c

Please sign in to comment.