Skip to content

Commit 866b6a0

Browse files
committed
Start container without any servers running
* If SERVER_TYPE environment variable is set 'none' for the docker container, it will run without starting any server
1 parent 7426907 commit 866b6a0

7 files changed

Lines changed: 54 additions & 18 deletions

File tree

.github/workflows/deploy-data-replica.yml

Whitespace-only changes.

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: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,17 @@ 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+
default = null
17+
nullable = true
18+
}
19+
1320
variable "minimum_replica_count" {
1421
type = number
1522
description = "Minimum amount of allowed replicas for the service. Also the replica count when creating th service."
@@ -26,13 +33,6 @@ variable "maximum_replica_count" {
2633
}
2734
}
2835

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-
3636
variable "autoscaling_policies" {
3737
type = map(object({
3838
predefined_metric_type = string
@@ -116,4 +116,5 @@ variable "container_name" {
116116

117117
locals {
118118
autoscaling_enabled = var.maximum_replica_count > var.minimum_replica_count
119+
server_type_name = var.server_type_name != null ? var.server_type_name : var.server_type
119120
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
## Setup
13+
14+
This module is managed via a GitHub Actions workflow. To separate it from the rest of the infrastructure, the workflow uses a dedicated IAM role. To set up everything from scratch, manually create the role
15+
`GithubDeployDataReplicationInfrastructure` based on the policy template `github_data_replication_actions_policy.json` and the trust policy `github_role_<ENVIRONMENT>_trust_policy.json`.
16+
17+
## Usage
18+
19+
### Manage the database replication infrastructure
20+
21+
To create the infrastructure, run the `data-replication-pipeline.yml` workflow and select the 'Recreate' option.
22+
This will destroy any existing replication infrastructure and create a new replicated database from the latest snapshot.
23+
24+
To destroy the resources, run the `data-replication-pipeline.yml` with the 'Destroy' option.
25+
26+
### Connect to the dedicated ECS task
27+
28+
To connect to the dedicated ECS task, run
29+
30+
```
31+
./script/shell.sh <ENV>-data-replication
32+
```

terraform/data_replication/ecs.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ resource "aws_ecs_cluster" "cluster" {
1010

1111
resource "aws_cloudwatch_log_group" "ecs_log_group" {
1212
name = "${local.name_prefix}-ecs"
13-
retention_in_days = 1
13+
retention_in_days = 14
1414
skip_destroy = false
1515
}
1616

@@ -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)