From 904b730362d40db132caf01161e2e6c141bf10a3 Mon Sep 17 00:00:00 2001 From: shockrah Date: Fri, 10 Feb 2023 22:07:26 -0800 Subject: [PATCH] blog.shockrah.xyz working at an infrastructure level now Also updated the image so that it has the right baseURL which gets configured during the service build ( Hugo ) --- docker/beta/nginx.conf | 1 - infra/load-balancer.tf | 3 ++ infra/nginx.tf | 67 +++++++++++++++++++++++++++++++++++ infra/route53-shockrah-xyz.tf | 5 +++ 4 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 infra/nginx.tf diff --git a/docker/beta/nginx.conf b/docker/beta/nginx.conf index c21939c..1eb8d93 100644 --- a/docker/beta/nginx.conf +++ b/docker/beta/nginx.conf @@ -33,7 +33,6 @@ http { server { server_name "blog.shockrah.xyz"; location / { - return 200 'Visiting blog.shockrah.xyz'; root /var/www/blog.shockrah.xyz; } } diff --git a/infra/load-balancer.tf b/infra/load-balancer.tf index 2179f74..82324af 100644 --- a/infra/load-balancer.tf +++ b/infra/load-balancer.tf @@ -26,6 +26,9 @@ resource "aws_lb_target_group" "shockrah_xyz" { protocol = "HTTP" target_type = "ip" vpc_id = aws_vpc.athens_vpc.id + health_check { + interval = 60 + } } resource "aws_lb_listener" "https" { diff --git a/infra/nginx.tf b/infra/nginx.tf new file mode 100644 index 0000000..559c6bb --- /dev/null +++ b/infra/nginx.tf @@ -0,0 +1,67 @@ +# This nginx service will replace the beta host so that +# we leverage nginx as a reverse proxy in fargate instead + +resource "aws_ecs_task_definition" "beta" { + family = "${var.athens_prefix}-beta" + + network_mode = "awsvpc" + requires_compatibilities = ["FARGATE"] + execution_role_arn = aws_iam_role.alpha_iam_role.arn + + cpu = 256 + memory = 512 + + container_definitions = jsonencode([ + { + name = "${var.athens_prefix}-beta-container" + image = "805875567437.dkr.ecr.us-west-1.amazonaws.com/reverse-proxy:latest" + cpu = 256 + memory = 512 + essential = true + portMappings = [ + # blog.shockrah.xyz + { + containerPort = var.shockrah_xyz_nginx_port, + hostPort = var.shockrah_xyz_nginx_port + } + ] + logConfiguration = { + logDriver = "awslogs" + options = { + awslogs-group = aws_cloudwatch_log_group.alpha.name + awslogs-region = "us-west-1" + awslogs-stream-prefix = "beta-container" + } + } + } + ]) + tags = { + Name = "${var.athens_prefix}-beta-task-def-container" + Description = "Reverse proxy for all static content" + } +} + +resource "aws_ecs_service" "beta_reverse_proxy" { + name = "${var.athens_prefix}-beta-reverse-proxy" + cluster = aws_ecs_cluster.alpha.id + task_definition = aws_ecs_task_definition.beta.arn + desired_count = 1 + launch_type = "FARGATE" + load_balancer { + target_group_arn = aws_lb_target_group.shockrah_xyz.arn + container_name = "${var.athens_prefix}-beta-container" + container_port = var.shockrah_xyz_nginx_port + } + + network_configuration { + assign_public_ip = true + subnets = [ + aws_subnet.delphi.id, + aws_subnet.crete_subnet.id, + ] + security_groups = [ + aws_security_group.ecs_web_ingress.id, + aws_security_group.base_ecs.id, + ] + } +} diff --git a/infra/route53-shockrah-xyz.tf b/infra/route53-shockrah-xyz.tf index f78e653..9a29037 100644 --- a/infra/route53-shockrah-xyz.tf +++ b/infra/route53-shockrah-xyz.tf @@ -38,6 +38,11 @@ locals { { name = "freechat.shockrah.xyz", records = [ aws_eip.beta_eip.public_ip ] }, { name = "resume.shockrah.xyz", records = [ aws_eip.beta_eip.public_ip ] }, { name = "www.shockrah.xyz", records = [ aws_eip.beta_eip.public_ip ] }, + { + name = "blog.shockrah.xyz" + type = "CNAME" + records = [ aws_lb.alpha.dns_name ] + }, ] }