Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,10 @@ when creating a `ServiceProp` object. You'll be creating a list of `ServiceSecre
from src.service_props import ServiceProps, ServiceSecret

app_service_props = ServiceProps(
ecs_task_cpu=256,
ecs_task_memory=512,
container_name="app",
container_port=443,
container_memory=1024,
container_location="ghcr.io/sage-bionetworks/app:v1.0",
container_secrets=[
ServiceSecret(
Expand Down
3 changes: 2 additions & 1 deletion app.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,11 @@
)

app_props = ServiceProps(
ecs_task_cpu=256,
ecs_task_memory=512,
container_name="my-app",
container_location=f"ghcr.io/sage-bionetworks/my-app:{app_version}",
container_port=80,
container_memory=200,
container_env_vars={
"APP_VERSION": f"{app_version}",
},
Expand Down
9 changes: 6 additions & 3 deletions src/service_props.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ class ServiceProps:
supports "path://" for building container from local (i.e. path://docker/MyContainer)
supports docker registry references (i.e. ghcr.io/sage-bionetworks/app:latest)
container_port: the container application port
container_memory: the container application memory
ecs_task_cpu: the ECS task CPU in millicores (i.e. 1024 = 1 vCPU)
ecs_task_memory: the ECS task memory
container_env_vars: a json dictionary of environment variables to pass into the container
i.e. {"EnvA": "EnvValueA", "EnvB": "EnvValueB"}
container_secrets: List of `ServiceSecret` resources to pull from AWS secrets manager
Expand All @@ -69,18 +70,20 @@ def __init__(
container_name: str,
container_location: str,
container_port: int,
container_memory: int = 512,
container_env_vars: dict = None,
container_secrets: List[ServiceSecret] = None,
container_volumes: List[ContainerVolume] = None,
ecs_task_cpu: int = 256,
ecs_task_memory: int = 512,
auto_scale_min_capacity: int = 1,
auto_scale_max_capacity: int = 1,
container_command: Optional[Sequence[str]] = None,
container_healthcheck: Optional[ecs.HealthCheck] = None,
) -> None:
self.container_name = container_name
self.container_port = container_port
self.container_memory = container_memory
self.ecs_task_cpu = ecs_task_cpu
self.ecs_task_memory = ecs_task_memory
if CONTAINER_LOCATION_PATH_ID in container_location:
container_location = container_location.removeprefix(
CONTAINER_LOCATION_PATH_ID
Expand Down
5 changes: 2 additions & 3 deletions src/service_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ def __init__(
self.task_definition = ecs.FargateTaskDefinition(
self,
"TaskDef",
cpu=1024,
memory_limit_mib=4096,
cpu=props.ecs_task_cpu,
memory_limit_mib=props.ecs_task_memory,
task_role=task_role,
execution_role=execution_role,
)
Expand All @@ -109,7 +109,6 @@ def _get_secret(scope: Construct, id: str, name: str) -> sm.Secret:
self.container = self.task_definition.add_container(
props.container_name,
image=image,
memory_limit_mib=props.container_memory,
environment=props.container_env_vars,
secrets=secrets,
port_mappings=[
Expand Down
8 changes: 5 additions & 3 deletions tests/unit/test_service_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ def test_service_stack_created():
container_name="app",
container_location="ghcr.io/sage-bionetworks/app:1.0",
container_port=8010,
container_memory=200,
ecs_task_cpu=256,
ecs_task_memory=512,
container_secrets=[
ServiceSecret(
secret_name="/app/secret",
Expand All @@ -45,12 +46,13 @@ def test_service_stack_created():
"ContainerDefinitions": [
{
"Image": "ghcr.io/sage-bionetworks/app:1.0",
"Memory": 200,
"MountPoints": [{"ContainerPath": "/work"}],
"Secrets": [{"Name": "APP_SECRET"}],
"Command": ["test"],
"HealthCheck": {"Command": ["CMD", "/healthcheck"]},
}
]
],
"Cpu": "256",
"Memory": "512",
},
)