Skip to content

Commit

Permalink
create migrations structure
Browse files Browse the repository at this point in the history
  • Loading branch information
ships committed Feb 19, 2024
1 parent 04af748 commit 478942f
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 6 deletions.
12 changes: 10 additions & 2 deletions infrastructure/terraform/aws/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,21 @@ module "core_dependency_services" {
}

module "service_core" {
source = "./modules/ecs-service"
source = "./modules/container-generic"

service_name = "core"
cluster_info = module.cluster.cluster_info

repository_url = module.cluster.ecr_repository_urls.core

set_lb_target = true

init_containers = [{
name = "migrations"
image = "${module.cluster.ecr_repository_urls.root}:latest"
command = ["npx", "prisma", "migrate", "deploy"]
}]

configuration = {
container_port = 3000
environment = [
Expand All @@ -67,7 +75,7 @@ module "service_core" {
}

module "service_flock" {
source = "./modules/ecs-service"
source = "./modules/container-generic"

service_name = "jobs"
cluster_info = module.cluster.cluster_info
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module "ecs_service" {
# task_role_arn = aws_iam_role.ecs_task_role.arn

# TEMPLATE Container definition(s).
container_definitions = {
container_definitions = merge({

"${var.service_name}" = {
essential = true
Expand All @@ -30,6 +30,11 @@ module "ecs_service" {
secrets = var.configuration.secrets

readonly_root_filesystem = false
dependencies = [for ic in var.init_containers: {
containerName = ic.name
condition = "SUCCESS"
}]


log_configuration = {
logDriver = "awslogs",
Expand All @@ -41,15 +46,36 @@ module "ecs_service" {
}
# memory_reservation = 100
}
}
},
{
for ic in var.init_containers: ic.name => {
essential = false
image = ic.image
command = ic.command

environment = var.configuration.environment
secrets = var.configuration.secrets

readonly_root_filesystem = false

load_balancer = {
log_configuration = {
logDriver = "awslogs",
options = {
awslogs-group = var.cluster_info.cloudwatch_log_group_name,
awslogs-region = var.cluster_info.region,
awslogs-stream-prefix = "ecs"
}
}
}
})

load_balancer = var.set_lb_target ? {
service = {
target_group_arn = var.cluster_info.lb_target_group_arn
container_name = var.service_name
container_port = var.configuration.container_port
}
}
} : {}

subnet_ids = var.cluster_info.private_subnet_ids
security_group_ids = var.cluster_info.container_security_group_ids
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,22 @@ variable "resources" {
}
}

variable "set_lb_target" {
description = "whether this service is addressible from the main Load Balancer"
type = bool
default = false
}

variable "init_containers" {
description = "list of init container specs to run before starting"
type = list(object({
name = string
image = string
command = list(string)
}))
default = []
}

variable "configuration" {
description = "Container configuration options"

Expand Down

0 comments on commit 478942f

Please sign in to comment.