Skip to content

Commit 1545d8a

Browse files
committed
Start container without any servers running
1 parent e933dcf commit 1545d8a

File tree

6 files changed

+47
-17
lines changed

6 files changed

+47
-17
lines changed

bin/docker-start

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ if [ "$SERVER_TYPE" == "web" ]; then
88
elif [ "$SERVER_TYPE" == "good-job" ]; then
99
echo "Starting good-job server..."
1010
exec "$BIN_DIR"/good_job start
11+
elif [ "$SERVER_TYPE" == "none" ]; then
12+
echo "No server started"
13+
exec tail -f /dev/null # Keep container running
1114
else
12-
echo "SERVER_TYPE variable: '$SERVER_TYPE' unknown. Allowed values ['web','good-job']"
15+
echo "SERVER_TYPE variable: '$SERVER_TYPE' unknown. Allowed values ['web','good-job', 'none']"
1316
exit 1
1417
fi

terraform/app/modules/ecs_service/autoscaling.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ resource "aws_appautoscaling_target" "this" {
1010

1111
resource "aws_appautoscaling_policy" "this" {
1212
for_each = local.autoscaling_enabled ? var.autoscaling_policies : {}
13-
name = "${var.server_type}-${each.key}-scaling-${var.environment}"
13+
name = "${local.server_type_name}-${each.key}-scaling-${var.environment}"
1414
policy_type = "TargetTrackingScaling"
1515
resource_id = aws_appautoscaling_target.this[0].resource_id
1616
scalable_dimension = aws_appautoscaling_target.this[0].scalable_dimension

terraform/app/modules/ecs_service/main.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ terraform {
99
}
1010

1111
resource "aws_security_group" "this" {
12-
name = "${var.server_type}-service-${var.environment}"
12+
name = "${local.server_type_name}-service-${var.environment}"
1313
description = "Security Group for communication with ECS Service"
1414
vpc_id = var.network_params.vpc_id
1515
lifecycle {
@@ -27,7 +27,7 @@ resource "aws_security_group_rule" "egress_all" {
2727
}
2828

2929
resource "aws_ecs_service" "this" {
30-
name = "${var.naming_prefix}${var.environment}-${var.server_type}"
30+
name = "mavis-${var.environment}-${local.server_type_name}"
3131
cluster = var.cluster_id
3232
task_definition = aws_ecs_task_definition.this.arn
3333
desired_count = var.minimum_replica_count
@@ -70,7 +70,7 @@ resource "aws_ecs_service" "this" {
7070
}
7171

7272
resource "aws_ecs_task_definition" "this" {
73-
family = "${var.naming_prefix}${var.server_type}-task-definition-${var.environment}"
73+
family = "mavis-${local.server_type_name}-task-definition-${var.environment}"
7474
requires_compatibilities = ["FARGATE"]
7575
network_mode = "awsvpc"
7676
cpu = var.task_config.cpu
@@ -95,7 +95,7 @@ resource "aws_ecs_task_definition" "this" {
9595
options = {
9696
awslogs-group = var.task_config.log_group_name
9797
awslogs-region = var.task_config.region
98-
awslogs-stream-prefix = "${var.environment}-${var.server_type}-logs"
98+
awslogs-stream-prefix = "${var.environment}-${local.server_type_name}-logs"
9999
}
100100
}
101101
healthCheck = {

terraform/app/modules/ecs_service/variables.tf

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,16 @@ variable "environment" {
66

77
variable "server_type" {
88
type = string
9-
description = "Type of server to be deployed. This is set as an environment variable in the main container, and is used to determine how the application is launched"
9+
description = "Type of server to be deployed. This is set as an environment variable in the main container, and is used to determine how the application is launched."
1010
nullable = false
1111
}
1212

13+
variable "server_type_name" {
14+
type = string
15+
description = "Name of the server type to be deployed."
16+
nullable = true
17+
}
18+
1319
variable "minimum_replica_count" {
1420
type = number
1521
description = "Minimum amount of allowed replicas for the service. Also the replica count when creating th service."
@@ -26,13 +32,6 @@ variable "maximum_replica_count" {
2632
}
2733
}
2834

29-
variable "naming_prefix" {
30-
type = string
31-
description = "Prefix to be used for naming the ECS service and task definition"
32-
default = "mavis-"
33-
nullable = false
34-
}
35-
3635
variable "autoscaling_policies" {
3736
type = map(object({
3837
predefined_metric_type = string
@@ -116,4 +115,5 @@ variable "container_name" {
116115

117116
locals {
118117
autoscaling_enabled = var.maximum_replica_count > var.minimum_replica_count
118+
server_type_name = var.server_type_name != null ? var.server_type_name : var.server_type
119119
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Data replication module
2+
3+
## Overview
4+
5+
This module can be used to verify data migration tasks on a copy of actual production data before running them on production.
6+
7+
It creates
8+
9+
- A replication of a given database based on a provided snapshot
10+
- A dedicated ECS service connected to the database
11+
12+
## Usage
13+
14+
### Manage the database replication infrastructure
15+
16+
To create the infrastructure, run the `data-replication-pipeline.yml` workflow and select the 'Recreate' option.
17+
This will destroy any existing replication infrastructure and create a new replicated database from the latest snapshot.
18+
19+
To destroy the resources, run the `data-replication-pipeline.yml` with the 'Destroy' option.
20+
21+
### Connect to the dedicated ECS task
22+
23+
To connect to the dedicated ECS task, run
24+
25+
```
26+
./script/shell.sh <ENV>-data-replication
27+
```

terraform/data_replication/ecs.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ module "db_access_service" {
2020
cluster_id = aws_ecs_cluster.cluster.id
2121
cluster_name = aws_ecs_cluster.cluster.name
2222
environment = var.environment
23-
naming_prefix = "mavis-data-replication-"
2423
maximum_replica_count = 1
2524
minimum_replica_count = 1
2625
network_params = {
2726
subnets = local.subnet_list
2827
vpc_id = aws_vpc.vpc.id
2928
}
30-
server_type = "good-job"
29+
server_type = "none"
30+
server_type_name = "data-replication"
3131
task_config = {
3232
environment = local.task_envs
3333
secrets = local.task_secrets
@@ -38,7 +38,7 @@ module "db_access_service" {
3838
task_role_arn = aws_iam_role.ecs_task_role.arn
3939
log_group_name = aws_cloudwatch_log_group.ecs_log_group.name
4040
region = var.region
41-
health_check_command = ["CMD-SHELL", "curl -f http://localhost:4000 || exit 1"]
41+
health_check_command = ["CMD-SHELL", "echo 'alive' || exit 1"]
4242
}
4343
depends_on = [aws_rds_cluster_instance.instance]
4444
}

0 commit comments

Comments
 (0)