Skip to content

Commit

Permalink
.review_apps: enable Traefik to handle a new ECS task coming online d…
Browse files Browse the repository at this point in the history
…uring a deployment

Previously we had to limit the number of deployed tasks for a review app to
exactly one, because Traefik would complain about duplicate service names for
the duration of the cross over.

To avoid that, we add a timestamp to the service name, so they're always
unique.
  • Loading branch information
AP-Hunt committed Feb 11, 2025
1 parent 4bd243e commit b399441
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
10 changes: 7 additions & 3 deletions .review_apps/ecs_service.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,19 @@ resource "aws_ecs_service" "app" {
task_definition = aws_ecs_task_definition.task.arn

desired_count = 1
deployment_maximum_percent = "100"
deployment_minimum_healthy_percent = "0"
deployment_maximum_percent = "200"
deployment_minimum_healthy_percent = "100"
force_new_deployment = true


launch_type = "FARGATE"
platform_version = "1.4.0"

network_configuration {
subnets = data.terraform_remote_state.review.outputs.private_subnet_ids
security_groups = [data.terraform_remote_state.review.outputs.review_apps_security_group_id]
security_groups = [data.terraform_remote_state.review.outputs.review_apps_security_group_id]
assign_public_ip = false
}

depends_on = [aws_ecs_task_definition.task]
}
3 changes: 3 additions & 0 deletions .review_apps/ecs_task_definition.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
locals {
logs_stream_prefix = "${data.terraform_remote_state.review.outputs.review_apps_log_group_name}/pr-${var.pull_request_number}"

service_timestamp = provider::time::rfc3339_parse(plantimestamp())

forms_admin_startup_commands = [
"bundle config unset --local without",
"bundle install",
Expand Down Expand Up @@ -63,6 +65,7 @@ resource "aws_ecs_task_definition" "task" {

dockerLabels = {
"traefik.http.routers.forms-admin-pr-${var.pull_request_number}.rule" : "Host(`pr-${var.pull_request_number}.review.forms.service.gov.uk`)",
"traefik.http.routers.forms-admin-pr-${var.pull_request_number}.service" : "forms-admin-pr-${var.pull_request_number}",
"traefik.http.services.forms-admin-pr-${var.pull_request_number}.loadbalancer.server.port" : "3000",
"traefik.http.services.forms-admin-pr-${var.pull_request_number}.loadbalancer.healthcheck.path" : "/up",
"traefik.enable" : "true"
Expand Down
5 changes: 5 additions & 0 deletions .review_apps/site.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ terraform {
source = "hashicorp/aws"
version = "~> 5.72.1"
}

time = {
source = "hashicorp/time"
version = "0.11.1"
}
}

backend "s3" {
Expand Down

0 comments on commit b399441

Please sign in to comment.