started ecs tasks

This commit is contained in:
Michaela 2021-10-11 18:52:37 +11:00
parent 010bed2658
commit f261530d83
2 changed files with 489 additions and 4 deletions

View File

@ -203,3 +203,217 @@ resource "aws_lambda_permission" "reverse_predictions" {
source_arn = "arn:aws:execute-api:us-east-1:${data.aws_caller_identity.current.account_id}:${aws_apigatewayv2_api.main.id}/*/*/predictions/reverse"
}
resource "aws_ecs_task_definition" "tawhiri" {
family = "tawhiri"
container_definitions = jsonencode(
[
{
command = []
cpu = 0
environment = []
essential = true
image = "${data.aws_caller_identity.current.account_id}.dkr.ecr.us-east-1.amazonaws.com/tawhiri:latest"
logConfiguration = {
logDriver = "awslogs"
options = {
awslogs-group = "/ecs/tawhiri"
awslogs-region = "us-east-1"
awslogs-stream-prefix = "ecs"
}
}
mountPoints = [
{
containerPath = "/srv"
sourceVolume = "srv"
},
]
name = "tawhiri"
portMappings = [
{
containerPort = 8000
hostPort = 8000
protocol = "tcp"
},
]
volumesFrom = []
},
]
)
cpu = "512"
execution_role_arn = "arn:aws:iam::143841941773:role/ecsTaskExecutionRole"
memory = "1024"
network_mode = "awsvpc"
requires_compatibilities = [
"FARGATE",
]
tags = {}
task_role_arn = "arn:aws:iam::143841941773:role/ecsTaskExecutionRole"
volume {
name = "srv"
efs_volume_configuration {
file_system_id = aws_efs_file_system.tawhiri.id
root_directory = "srv"
transit_encryption = "DISABLED"
authorization_config {
iam = "DISABLED"
}
}
}
}
resource "aws_ecs_task_definition" "tawhiri_downloader" {
family = "tawhiri-downloader"
container_definitions = jsonencode(
[
{
command = [
"daemon",
]
cpu = 0
environment = [
{
name = "TZ"
value = "UTC"
},
]
essential = true
image = "${data.aws_caller_identity.current.account_id}.dkr.ecr.us-east-1.amazonaws.com/tawhiri-downloader:latest"
logConfiguration = {
logDriver = "awslogs"
options = {
awslogs-group = "/ecs/tawhiri-downloader"
awslogs-region = "us-east-1"
awslogs-stream-prefix = "ecs"
}
}
mountPoints = [
{
containerPath = "/srv"
sourceVolume = "srv"
},
]
name = "tawhiri-downloader"
portMappings = []
volumesFrom = []
},
]
)
cpu = "256"
execution_role_arn = "arn:aws:iam::143841941773:role/ecsTaskExecutionRole"
memory = "512"
network_mode = "awsvpc"
requires_compatibilities = [
"FARGATE",
]
tags = {}
task_role_arn = "arn:aws:iam::143841941773:role/ecsTaskExecutionRole"
volume {
name = "srv"
efs_volume_configuration {
file_system_id = aws_efs_file_system.tawhiri.id
root_directory = "srv"
transit_encryption = "DISABLED"
authorization_config {
iam = "DISABLED"
}
}
}
}
resource "aws_ecs_task_definition" "tawhiri_ruaumoko" {
family = "tawhiri-ruaumoko"
container_definitions = jsonencode(
[
{
cpu = 0
entryPoint = [
"/root/.local/bin/ruaumoko-download",
]
environment = []
essential = true
image = "${data.aws_caller_identity.current.account_id}.dkr.ecr.us-east-1.amazonaws.com/tawhiri:latest"
logConfiguration = {
logDriver = "awslogs"
options = {
awslogs-group = "/ecs/tawhiri-ruaumoko"
awslogs-region = "us-east-1"
awslogs-stream-prefix = "ecs"
}
}
mountPoints = [
{
containerPath = "/srv"
sourceVolume = "srv"
},
]
name = "ruaumoko"
portMappings = []
volumesFrom = []
},
]
)
cpu = "1024"
execution_role_arn = "arn:aws:iam::143841941773:role/ecsTaskExecutionRole"
memory = "2048"
network_mode = "awsvpc"
requires_compatibilities = [
"FARGATE",
]
tags = {}
task_role_arn = "arn:aws:iam::143841941773:role/ecsTaskExecutionRole"
volume {
name = "srv"
efs_volume_configuration {
file_system_id = aws_efs_file_system.tawhiri.id
root_directory = "srv"
transit_encryption = "DISABLED"
authorization_config {
iam = "DISABLED"
}
}
}
}
resource "aws_efs_file_system" "tawhiri" {
tags = {
Name = "Tawhiri"
}
lifecycle_policy {
transition_to_ia = "AFTER_7_DAYS"
}
}
resource "aws_ecr_repository" "tawhiri" {
name = "tawhiri"
image_tag_mutability = "MUTABLE"
image_scanning_configuration {
scan_on_push = true
}
}
resource "aws_ecr_repository" "tawhiri_downloader" {
name = "tawhiri-downloader"
image_tag_mutability = "MUTABLE"
image_scanning_configuration {
scan_on_push = true
}
}

View File

@ -60,12 +60,283 @@ resource "aws_apigatewayv2_integration" "sign_socket" {
}
resource "aws_ecr_repository" "wsproxy" {
name = "wsproxy"
image_tag_mutability = "MUTABLE"
image_scanning_configuration {
scan_on_push = true
}
}
// Subnet that is used to make discovery simple for the main ws server
resource "aws_subnet" "ws_main" {
map_public_ip_on_launch = false
vpc_id = aws_vpc.main.id
cidr_block = "172.31.134.0/28"
tags = {
Name = "wsmain"
}
}
resource "aws_route_table_association" "ws_main" {
subnet_id = aws_subnet.ws_main.id
route_table_id = aws_route_table.main.id
}
// so we need to ensure there is only as handful of IP addresses avaliable in the subnet, so we assign all the IPs to ENIs
resource "aws_network_interface" "ws_pad" {
count = 9
subnet_id = aws_subnet.ws_main.id
description = "Do not delete. Padding to limit addresses"
}
resource "aws_ecs_task_definition" "ws_reader" {
family = "ws-reader"
container_definitions = jsonencode(
[
{
command = [
"s3",
"sync",
"s3://sondehub-ws-config/",
"/config/",
]
cpu = 0
environment = []
essential = false
image = "amazon/aws-cli"
logConfiguration = {
logDriver = "awslogs"
options = {
awslogs-group = "/ecs/ws"
awslogs-region = "us-east-1"
awslogs-stream-prefix = "ecs"
}
}
mountPoints = [
{
containerPath = "/config"
sourceVolume = "config"
},
]
name = "config"
portMappings = []
volumesFrom = []
},
{
command = []
cpu = 0
dependsOn = [
{
condition = "SUCCESS"
containerName = "config"
},
{
condition = "SUCCESS"
containerName = "config-move"
},
]
environment = []
essential = true
image = "${data.aws_caller_identity.current.account_id}.dkr.ecr.us-east-1.amazonaws.com/wsproxy:latest"
logConfiguration = {
logDriver = "awslogs"
options = {
awslogs-group = "/ecs/ws"
awslogs-region = "us-east-1"
awslogs-stream-prefix = "ecs"
}
}
mountPoints = [
{
containerPath = "/mosquitto/config"
sourceVolume = "config"
},
]
name = "mqtt"
portMappings = [
{
containerPort = 8080
hostPort = 8080
protocol = "tcp"
},
{
containerPort = 8883
hostPort = 8883
protocol = "tcp"
},
]
ulimits = [
{
hardLimit = 50000
name = "nofile"
softLimit = 30000
},
]
volumesFrom = []
},
{
command = [
"cp",
"/config/mosquitto-reader.conf",
"/config/mosquitto.conf",
]
cpu = 0
dependsOn = [
{
condition = "SUCCESS"
containerName = "config"
},
]
environment = []
essential = false
image = "alpine"
logConfiguration = {
logDriver = "awslogs"
options = {
awslogs-group = "/ecs/ws-reader"
awslogs-region = "us-east-1"
awslogs-stream-prefix = "ecs"
}
}
mountPoints = [
{
containerPath = "/config"
sourceVolume = "config"
},
]
name = "config-move"
portMappings = []
volumesFrom = []
},
]
)
cpu = "256"
execution_role_arn = "arn:aws:iam::143841941773:role/ecsTaskExecutionRole"
memory = "512"
network_mode = "awsvpc"
requires_compatibilities = [
"FARGATE",
]
tags = {}
task_role_arn = "arn:aws:iam::143841941773:role/ws"
volume {
name = "config"
}
}
resource "aws_ecs_task_definition" "ws" {
family = "ws"
container_definitions = jsonencode(
[
{
command = [
"s3",
"sync",
"s3://sondehub-ws-config/",
"/config/",
]
cpu = 0
environment = []
essential = false
image = "amazon/aws-cli"
logConfiguration = {
logDriver = "awslogs"
options = {
awslogs-group = "/ecs/ws"
awslogs-region = "us-east-1"
awslogs-stream-prefix = "ecs"
}
}
mountPoints = [
{
containerPath = "/config"
sourceVolume = "config"
},
]
name = "config"
portMappings = []
volumesFrom = []
},
{
cpu = 0
dependsOn = [
{
condition = "SUCCESS"
containerName = "config"
},
]
environment = []
essential = true
image = "eclipse-mosquitto:2-openssl"
logConfiguration = {
logDriver = "awslogs"
options = {
awslogs-group = "/ecs/ws"
awslogs-region = "us-east-1"
awslogs-stream-prefix = "ecs"
}
}
mountPoints = [
{
containerPath = "/mosquitto/config"
sourceVolume = "config"
},
]
name = "mqtt"
portMappings = [
{
containerPort = 8080
hostPort = 8080
protocol = "tcp"
},
{
containerPort = 8883
hostPort = 8883
protocol = "tcp"
},
{
containerPort = 1883
hostPort = 1883
protocol = "tcp"
},
]
ulimits = [
{
hardLimit = 50000
name = "nofile"
softLimit = 30000
},
]
volumesFrom = []
},
]
)
cpu = "256"
execution_role_arn = "arn:aws:iam::143841941773:role/ws"
memory = "512"
network_mode = "awsvpc"
requires_compatibilities = [
"FARGATE",
]
tags = {}
task_role_arn = "arn:aws:iam::143841941773:role/ws"
volume {
name = "config"
}
}
# TODO subnet for reader
# ecr
# padding interfaces
# service, reader, writer
# task definition
# s3 config bucket
# iam roles
# security group
# reader autoscaling