Skip to content

Commit

Permalink
ci(infra): Optimize ECS (#627)
Browse files Browse the repository at this point in the history
  • Loading branch information
topher-lo committed Dec 19, 2024
1 parent 4dba340 commit c14229f
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 2 deletions.
12 changes: 12 additions & 0 deletions deployments/aws/ecs/ecs-api.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ resource "aws_ecs_task_definition" "api_task_definition" {
execution_role_arn = aws_iam_role.api_execution.arn
task_role_arn = aws_iam_role.api_worker_task.arn

runtime_platform {
operating_system_family = "LINUX"
cpu_architecture = "ARM64"
}

container_definitions = jsonencode([
{
name = "TracecatApiContainer"
Expand All @@ -34,6 +39,13 @@ resource "aws_ecs_task_definition" "api_task_definition" {
maxAttempts = 3
backoffTime = 10
}
healthCheck = {
command = ["CMD", "python", "-c", "import httpx; httpx.get('http://localhost:8000/').raise_for_status()"]
interval = 30
timeout = 5
retries = 3
startPeriod = 60
}
}
])
}
Expand Down
5 changes: 5 additions & 0 deletions deployments/aws/ecs/ecs-caddy.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ resource "aws_ecs_task_definition" "caddy_task_definition" {
execution_role_arn = aws_iam_role.caddy_execution.arn
task_role_arn = aws_iam_role.caddy_task.arn

runtime_platform {
operating_system_family = "LINUX"
cpu_architecture = "ARM64"
}

container_definitions = jsonencode([
{
name = "TracecatCaddyContainer"
Expand Down
12 changes: 12 additions & 0 deletions deployments/aws/ecs/ecs-executor.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ resource "aws_ecs_task_definition" "executor_task_definition" {
execution_role_arn = aws_iam_role.worker_execution.arn
task_role_arn = aws_iam_role.api_worker_task.arn

runtime_platform {
operating_system_family = "LINUX"
cpu_architecture = "ARM64"
}

container_definitions = jsonencode([
{
name = "TracecatExecutorContainer"
Expand Down Expand Up @@ -44,6 +49,13 @@ resource "aws_ecs_task_definition" "executor_task_definition" {
maxAttempts = 3
backoffTime = 10
}
healthCheck = {
command = ["CMD", "python", "-c", "import httpx; httpx.get('http://localhost:8002/').raise_for_status()"]
interval = 30
timeout = 5
retries = 3
startPeriod = 60
}
}
])
}
Expand Down
5 changes: 5 additions & 0 deletions deployments/aws/ecs/ecs-temporal-ui.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ resource "aws_ecs_task_definition" "temporal_ui_task_definition" {
execution_role_arn = aws_iam_role.temporal_ui_execution.arn
task_role_arn = aws_iam_role.temporal_ui_task.arn

runtime_platform {
operating_system_family = "LINUX"
cpu_architecture = "ARM64"
}

container_definitions = jsonencode([
{
name = "TemporalUiContainer"
Expand Down
5 changes: 5 additions & 0 deletions deployments/aws/ecs/ecs-temporal.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ resource "aws_ecs_task_definition" "temporal_task_definition" {
execution_role_arn = aws_iam_role.temporal_execution.arn
task_role_arn = aws_iam_role.temporal_task.arn

runtime_platform {
operating_system_family = "LINUX"
cpu_architecture = "ARM64"
}

container_definitions = jsonencode([
{
name = "TemporalContainer"
Expand Down
5 changes: 5 additions & 0 deletions deployments/aws/ecs/ecs-ui.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ resource "aws_ecs_task_definition" "ui_task_definition" {
memory = var.ui_memory
execution_role_arn = aws_iam_role.ui_execution.arn

runtime_platform {
operating_system_family = "LINUX"
cpu_architecture = "ARM64"
}

container_definitions = jsonencode([
{
name = "TracecatUiContainer"
Expand Down
20 changes: 18 additions & 2 deletions deployments/aws/ecs/ecs-worker.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ resource "aws_ecs_task_definition" "worker_task_definition" {
execution_role_arn = aws_iam_role.worker_execution.arn
task_role_arn = aws_iam_role.api_worker_task.arn

runtime_platform {
operating_system_family = "LINUX"
cpu_architecture = "ARM64"
}

container_definitions = jsonencode([
{
name = "TracecatWorkerContainer"
Expand Down Expand Up @@ -43,8 +48,7 @@ resource "aws_ecs_service" "tracecat_worker" {
name = "tracecat-worker"
cluster = aws_ecs_cluster.tracecat_cluster.id
task_definition = aws_ecs_task_definition.worker_task_definition.arn
launch_type = "FARGATE"
desired_count = 1
desired_count = 2
force_new_deployment = var.force_new_deployment

network_configuration {
Expand Down Expand Up @@ -80,6 +84,18 @@ resource "aws_ecs_service" "tracecat_worker" {
}
}

capacity_provider_strategy {
capacity_provider = "FARGATE"
weight = 1
base = 1
}

capacity_provider_strategy {
capacity_provider = "FARGATE_SPOT"
weight = 1
base = 0
}

depends_on = [
aws_ecs_service.temporal_service,
aws_ecs_service.tracecat_executor
Expand Down

0 comments on commit c14229f

Please sign in to comment.