|
| 1 | +# ECS Task Definition for Caddy Service |
| 2 | +resource "aws_ecs_task_definition" "caddy_task_definition" { |
| 3 | + family = "TracecatCaddyTaskDefinition" |
| 4 | + network_mode = "awsvpc" |
| 5 | + requires_compatibilities = ["FARGATE"] |
| 6 | + cpu = "256" |
| 7 | + memory = "512" |
| 8 | + execution_role_arn = aws_iam_role.caddy_execution.arn |
| 9 | + task_role_arn = aws_iam_role.caddy_task.arn |
| 10 | + |
| 11 | + container_definitions = jsonencode([ |
| 12 | + { |
| 13 | + name = "TracecatCaddyContainer" |
| 14 | + image = "caddy:2.8.4-alpine" |
| 15 | + portMappings = [ |
| 16 | + { |
| 17 | + containerPort = 80 |
| 18 | + hostPort = 80 |
| 19 | + name = "caddy" |
| 20 | + appProtocol = "http" |
| 21 | + } |
| 22 | + ] |
| 23 | + command = [ |
| 24 | + "/bin/sh", |
| 25 | + "-c", |
| 26 | + <<EOT |
| 27 | +cat <<EOF > /etc/caddy/Caddyfile |
| 28 | +:80 { |
| 29 | + handle_path /api* { |
| 30 | + reverse_proxy http://api-service:8000 |
| 31 | + } |
| 32 | + reverse_proxy http://ui-service:3000 |
| 33 | +} |
| 34 | +EOF |
| 35 | +caddy run --config /etc/caddy/Caddyfile |
| 36 | +EOT |
| 37 | + ] |
| 38 | + |
| 39 | + logConfiguration = { |
| 40 | + logDriver = "awslogs" |
| 41 | + options = { |
| 42 | + awslogs-group = aws_cloudwatch_log_group.tracecat_log_group.name |
| 43 | + awslogs-region = var.aws_region |
| 44 | + awslogs-stream-prefix = "caddy" |
| 45 | + } |
| 46 | + } |
| 47 | + dockerPullConfig = { |
| 48 | + maxAttempts = 3 |
| 49 | + backoffTime = 10 |
| 50 | + } |
| 51 | + } |
| 52 | + ]) |
| 53 | +} |
| 54 | + |
| 55 | +resource "aws_ecs_service" "tracecat_caddy" { |
| 56 | + name = "tracecat-caddy" |
| 57 | + cluster = aws_ecs_cluster.tracecat_cluster.id |
| 58 | + task_definition = aws_ecs_task_definition.caddy_task_definition.arn |
| 59 | + launch_type = "FARGATE" |
| 60 | + desired_count = 1 |
| 61 | + |
| 62 | + network_configuration { |
| 63 | + subnets = aws_subnet.private[*].id |
| 64 | + security_groups = [ |
| 65 | + aws_security_group.caddy.id, |
| 66 | + aws_security_group.core.id |
| 67 | + ] |
| 68 | + } |
| 69 | + |
| 70 | + service_connect_configuration { |
| 71 | + enabled = true |
| 72 | + namespace = local.local_dns_namespace |
| 73 | + |
| 74 | + service { |
| 75 | + port_name = "caddy" |
| 76 | + discovery_name = "caddy-service" |
| 77 | + client_alias { |
| 78 | + port = 80 |
| 79 | + dns_name = "caddy-service" |
| 80 | + } |
| 81 | + } |
| 82 | + |
| 83 | + log_configuration { |
| 84 | + log_driver = "awslogs" |
| 85 | + options = { |
| 86 | + awslogs-group = aws_cloudwatch_log_group.tracecat_log_group.name |
| 87 | + awslogs-region = var.aws_region |
| 88 | + awslogs-stream-prefix = "service-connect-caddy" |
| 89 | + } |
| 90 | + } |
| 91 | + } |
| 92 | + |
| 93 | + load_balancer { |
| 94 | + target_group_arn = aws_alb_target_group.caddy.id |
| 95 | + container_name = "TracecatCaddyContainer" |
| 96 | + container_port = 80 |
| 97 | + } |
| 98 | + |
| 99 | + depends_on = [ |
| 100 | + aws_ecs_service.tracecat_api, |
| 101 | + aws_ecs_service.tracecat_ui |
| 102 | + ] |
| 103 | +} |
0 commit comments