Skip to content

Commit e89d030

Browse files
authored
feat: Added consumer container. (#26)
1 parent 5a2fdfa commit e89d030

File tree

16 files changed

+350
-11
lines changed

16 files changed

+350
-11
lines changed

.github/workflows/deploy.yaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ jobs:
4141
AWS_REGION: ${{ secrets.AWS_REGION }}
4242
AWS_ROLE_ARN: ${{ secrets.AWS_ROLE_ARN }}
4343
TF_VAR_APPLY_DATABASE_UPDATES_IMMEDIATELY: ${{ secrets.TF_VAR_APPLY_DATABASE_UPDATES_IMMEDIATELY }}
44+
TF_VAR_CONSUMER_CONTAINER_COUNT: ${{ secrets.TF_VAR_CONSUMER_CONTAINER_COUNT }}
45+
TF_VAR_CONSUMER_CPU: ${{ secrets.TF_VAR_CONSUMER_CPU }}
46+
TF_VAR_CONSUMER_MEMORY: ${{ secrets.TF_VAR_CONSUMER_MEMORY }}
4447
TF_VAR_DATABASE_SKIP_FINAL_SNAPSHOT: ${{ secrets.TF_VAR_DATABASE_SKIP_FINAL_SNAPSHOT }}
4548
TF_VAR_DELETION_PROTECTION: ${{ secrets.TF_VAR_DELETION_PROTECTION }}
4649
TF_VAR_DEPLOYMENT_ENVIRONMENTS: ${{ secrets.TF_VAR_DEPLOYMENT_ENVIRONMENTS }}
@@ -88,6 +91,9 @@ jobs:
8891
# For any of these that have a value, the corresponding TF_VAR_*
8992
# environment variable will be set.
9093
APPLY_DATABASE_UPDATES_IMMEDIATELY: ${{ secrets.TF_VAR_APPLY_DATABASE_UPDATES_IMMEDIATELY }}
94+
TF_VAR_CONSUMER_CONTAINER_COUNT: ${{ secrets.TF_VAR_CONSUMER_CONTAINER_COUNT }}
95+
CONSUMER_CPU: ${{ secrets.TF_VAR_CONSUMER_CPU }}
96+
CONSUMER_MEMORY: ${{ secrets.TF_VAR_CONSUMER_MEMORY }}
9197
DATABASE_SKIP_FINAL_SNAPSHOT: ${{ secrets.TF_VAR_DATABASE_SKIP_FINAL_SNAPSHOT }}
9298
DELETION_PROTECTION: ${{ secrets.TF_VAR_DELETION_PROTECTION }}
9399
DEPLOYMENT_ENVIRONMENTS: ${{ secrets.TF_VAR_DEPLOYMENT_ENVIRONMENTS }}
@@ -100,7 +106,8 @@ jobs:
100106
REPOSITORY: ${{ secrets.TF_VAR_REPOSITORY }}
101107
run: |
102108
variables=(
103-
"apply_database_updates_immediately" "database_skip_final_snapshot"
109+
"apply_database_updates_immediately" "consumer_container_count"
110+
"consumer_cpu" "consumer_memory" "database_skip_final_snapshot"
104111
"deletion_protection" "deployment_environments" "environment"
105112
"export_expiration" "image_tags_mutable" "key_recovery_period"
106113
"program" "project" "repository"

.github/workflows/plan.yaml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ on:
2222
AWS_ROLE_ARN:
2323
TF_VAR_APPLY_DATABASE_UPDATES_IMMEDIATELY:
2424
required: false
25+
TF_VAR_CONSUMER_CONTAINER_COUNT:
26+
required: false
27+
TF_VAR_CONSUMER_CPU:
28+
required: false
29+
TF_VAR_CONSUMER_MEMORY:
30+
required: false
2531
TF_VAR_DATABASE_SKIP_FINAL_SNAPSHOT:
2632
required: false
2733
TF_VAR_DELETION_PROTECTION:
@@ -99,6 +105,9 @@ jobs:
99105
# For any of these that have a value, the corresponding TF_VAR_*
100106
# environment variable will be set.
101107
APPLY_DATABASE_UPDATES_IMMEDIATELY: ${{ secrets.TF_VAR_APPLY_DATABASE_UPDATES_IMMEDIATELY }}
108+
TF_VAR_CONSUMER_CONTAINER_COUNT: ${{ secrets.TF_VAR_CONSUMER_CONTAINER_COUNT }}
109+
CONSUMER_CPU: ${{ secrets.TF_VAR_CONSUMER_CPU }}
110+
CONSUMER_MEMORY: ${{ secrets.TF_VAR_CONSUMER_MEMORY }}
102111
DATABASE_SKIP_FINAL_SNAPSHOT: ${{ secrets.TF_VAR_DATABASE_SKIP_FINAL_SNAPSHOT }}
103112
DELETION_PROTECTION: ${{ secrets.TF_VAR_DELETION_PROTECTION }}
104113
DEPLOYMENT_ENVIRONMENTS: ${{ secrets.TF_VAR_DEPLOYMENT_ENVIRONMENTS }}
@@ -111,7 +120,8 @@ jobs:
111120
REPOSITORY: ${{ secrets.TF_VAR_REPOSITORY }}
112121
run: |
113122
variables=(
114-
"apply_database_updates_immediately" "database_skip_final_snapshot"
123+
"apply_database_updates_immediately" "consumer_container_count"
124+
"consumer_cpu" "consumer_memory" "database_skip_final_snapshot"
115125
"deletion_protection" "deployment_environments" "environment"
116126
"export_expiration" "image_tags_mutable" "key_recovery_period"
117127
"program" "project" "repository"

.github/workflows/pull-request.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ jobs:
6767
AWS_ROLE_ARN: ${{ secrets.AWS_ROLE_ARN }}
6868
TF_VAR_APPLY_DATABASE_UPDATES_IMMEDIATELY: ${{ secrets.TF_VAR_APPLY_DATABASE_UPDATES_IMMEDIATELY }}
6969
TF_VAR_DATABASE_SKIP_FINAL_SNAPSHOT: ${{ secrets.TF_VAR_DATABASE_SKIP_FINAL_SNAPSHOT }}
70+
TF_VAR_CONSUMER_CONTAINER_COUNT: ${{ secrets.TF_VAR_CONSUMER_CONTAINER_COUNT }}
71+
TF_VAR_CONSUMER_CPU: ${{ secrets.TF_VAR_CONSUMER_CPU }}
72+
TF_VAR_CONSUMER_MEMORY: ${{ secrets.TF_VAR_CONSUMER_MEMORY }}
7073
TF_VAR_DELETION_PROTECTION: ${{ secrets.TF_VAR_DELETION_PROTECTION }}
7174
TF_VAR_DEPLOYMENT_ENVIRONMENTS: ${{ secrets.TF_VAR_DEPLOYMENT_ENVIRONMENTS }}
7275
TF_VAR_EXPORT_EXPIRATION: ${{ secrets.TF_VAR_EXPORT_EXPIRATION }}

Dockerfile.consumer

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,8 @@ ENV PYTHONPATH=/opt/senzing/er/sdk/python:/app
1919
# Flush buffer - helps with print statements.
2020
ENV PYTHONUNBUFFERED=1
2121

22+
# Define volumes necessary to support a read-only root filesystem on ECS
23+
# Fargate.
24+
VOLUME ["/home/senzing", "/var/lib/amazon", "/var/log"]
25+
2226
CMD ["python3", "consumer.py"]

tofu/config/service/main.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,8 @@ module "system" {
3434
deletion_protection = var.deletion_protection
3535
image_tag = var.image_tag != null ? var.image_tag : sha256(timestamp())
3636
image_tags_mutable = var.image_tags_mutable
37+
38+
consumer_container_count = var.consumer_container_count
39+
consumer_cpu = var.consumer_cpu
40+
consumer_memory = var.consumer_memory
3741
}

tofu/config/service/variables.tf

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,24 @@ variable "apply_database_updates_immediately" {
44
default = false
55
}
66

7+
variable "consumer_container_count" {
8+
type = number
9+
description = "Desired number of consumer containers to run."
10+
default = 1
11+
}
12+
13+
variable "consumer_cpu" {
14+
type = number
15+
description = "Number of virtual CPUs to allocate to each consumer container."
16+
default = 1
17+
}
18+
19+
variable "consumer_memory" {
20+
type = number
21+
description = "Amount of memory (in MiB) to allocate to each consumer container."
22+
default = 4096
23+
}
24+
725
variable "database_skip_final_snapshot" {
826
type = bool
927
description = "Whether to skip the final snapshot when the database cluster is deleted."

tofu/modules/ephemeral_service/main.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ module "ecs_task" {
2424
version = "~> 5.3"
2525

2626
name = local.prefix
27-
cpu = var.cpu
27+
cpu = (var.cpu * 1024)
2828
memory = var.memory
2929
# TODO: These roles?
3030
daemon_role = aws_iam_role.execution.arn
@@ -37,8 +37,8 @@ module "ecs_task" {
3737
container_definitions = jsonencode(yamldecode(templatefile(
3838
"${path.module}/templates/container-definitions.yaml.tftpl", {
3939
name = local.prefix
40-
cpu = var.cpu - 256
41-
memory = var.memory - 512
40+
cpu = (var.cpu * 1024)
41+
memory = var.memory
4242
image = "${module.ecr.repository_url}:${var.image_tag}"
4343
container_command = var.container_command
4444
container_port = var.container_port

tofu/modules/ephemeral_service/variables.tf

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ variable "container_port" {
1717

1818
variable "cpu" {
1919
type = number
20-
description = "CPU unit for this task."
21-
default = 512
20+
description = "Number of virtual CPUs to allocate to the container."
21+
default = 1
2222
}
2323

2424
variable "docker_context" {
@@ -55,6 +55,7 @@ variable "ephemeral_volumes" {
5555
type = map(string)
5656
description = "Map of ephemeral volume names to mount paths."
5757
default = {
58+
logs = "/var/log"
5859
senzing-home = "/home/senzing"
5960
}
6061
}
@@ -91,7 +92,7 @@ variable "logging_key_id" {
9192
variable "memory" {
9293
type = number
9394
description = "Memory for this task."
94-
default = 1024
95+
default = 4096
9596
}
9697

9798
variable "otel_ssm_parameter_arn" {
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
module "task" {
2+
source = "../ephemeral_service"
3+
4+
project = var.project
5+
service = var.service
6+
image_tag = var.image_tag
7+
image_tags_mutable = var.image_tags_mutable
8+
force_delete = var.force_delete
9+
memory = var.memory
10+
otel_ssm_parameter_arn = var.otel_ssm_parameter_arn
11+
otel_log_level = var.otel_log_level
12+
logging_key_id = var.logging_key_id
13+
task_policies = var.task_policies
14+
untagged_image_retention = var.untagged_image_retention
15+
execution_policies = var.execution_policies
16+
container_key_arn = var.container_key_arn
17+
container_command = var.container_command
18+
docker_context = var.docker_context
19+
dockerfile = var.dockerfile
20+
environment_secrets = var.environment_secrets
21+
environment_variables = var.environment_variables
22+
ephemeral_volumes = var.ephemeral_volumes
23+
cpu = var.cpu
24+
25+
tags = var.tags
26+
}
27+
28+
module "service" {
29+
source = "HENNGE/ecs/aws//modules/core/service"
30+
version = "5.3.0"
31+
32+
cluster = var.cluster_arn
33+
name = join("-", compact([var.project, var.environment, var.service]))
34+
create_task_definition = false
35+
task_definition_arn = module.task.task_definition_arn
36+
desired_count = var.desired_containers
37+
38+
launch_type = "FARGATE"
39+
task_requires_compatibilities = ["FARGATE"]
40+
enable_execute_command = var.enable_execute_command
41+
propagate_tags = "SERVICE"
42+
43+
network_configuration = {
44+
subnets = var.container_subnets
45+
security_groups = var.security_groups
46+
assign_public_ip = false
47+
}
48+
49+
tags = var.tags
50+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
output "container_name" {
2+
description = "Name of the container in the ECS task definition."
3+
value = module.task.container_name
4+
}
5+
6+
output "docker_push" {
7+
description = "Commands to push a Docker image to the container repository."
8+
value = module.task.docker_push
9+
}
10+
11+
output "service_name" {
12+
description = "Name of the ECS service."
13+
value = module.service.name
14+
}
15+
16+
output "task_definition_arn" {
17+
description = "ARN of the ECS task definition."
18+
value = module.task.task_definition_arn
19+
}

0 commit comments

Comments
 (0)