Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add port to LB for service URI in dev #552

Open
wants to merge 15 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM tiangolo/uvicorn-gunicorn-fastapi:python3.10-slim
FROM --platform=linux/amd64 tiangolo/uvicorn-gunicorn-fastapi:python3.10-slim

# Comment to trigger an image rebuild

Expand Down
4 changes: 3 additions & 1 deletion batch/scripts/report_status.sh
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,12 @@ generate_payload()
EOF
}

set -x

echo "$(generate_payload)"

CTYPE_HEADER="Content-Type:application/json"
curl -s -X PATCH -H "${AUTH_HEADER}" -H "${CTYPE_HEADER}" -d "$(generate_payload)" "${URL}"
curl -i -X PATCH -H "${AUTH_HEADER}" -H "${CTYPE_HEADER}" -d "$(generate_payload)" "${URL}"

# Try to clean up free space for potential other batch jobs on the same node
set +e
Expand Down
30 changes: 17 additions & 13 deletions terraform/main.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# Require TF version to be same as or greater than 0.12.24
terraform {
backend "s3" {
region = "us-east-1"
Expand All @@ -25,22 +24,22 @@ locals {
project = "gfw-data-api"
aurora_instance_class = data.terraform_remote_state.core.outputs.aurora_cluster_instance_class
aurora_max_vcpus = local.aurora_instance_class == "db.t3.medium" ? 2 : local.aurora_instance_class == "db.r6g.large" ? 2 : local.aurora_instance_class == "db.r6g.xlarge" ? 4 : local.aurora_instance_class == "db.r6g.2xlarge" ? 8 : local.aurora_instance_class == "db.r6g.4xlarge" ? 16 : local.aurora_instance_class == "db.r6g.8xlarge" ? 32 : local.aurora_instance_class == "db.r6g.16xlarge" ? 64 : local.aurora_instance_class == "db.r5.large" ? 2 : local.aurora_instance_class == "db.r5.xlarge" ? 4 : local.aurora_instance_class == "db.r5.2xlarge" ? 8 : local.aurora_instance_class == "db.r5.4xlarge" ? 16 : local.aurora_instance_class == "db.r5.8xlarge" ? 32 : local.aurora_instance_class == "db.r5.12xlarge" ? 48 : local.aurora_instance_class == "db.r5.16xlarge" ? 64 : local.aurora_instance_class == "db.r5.24xlarge" ? 96 : ""
service_url = var.environment == "dev" ? "http://${module.fargate_autoscaling.lb_dns_name}" : var.service_url
container_tag = substr(var.git_sha, 0, 7)
lb_dns_name = coalesce(module.fargate_autoscaling.lb_dns_name, var.lb_dns_name)
service_url = var.environment == "dev" ? "http://${local.lb_dns_name}:${data.external.generate_port[0].result["port"]}" : var.service_url
}

# Docker image for FastAPI app
module "app_docker_image" {
source = "git::https://github.com/wri/gfw-terraform-modules.git//terraform/modules/container_registry?ref=v0.4.2.3"
source = "git::https://github.com/wri/gfw-terraform-modules.git//terraform/modules/container_registry?ref=v0.4.2.7"
image_name = substr(lower("${local.project}${local.name_suffix}"), 0, 64)
root_dir = "${path.root}/../"
tag = local.container_tag
}

# Docker image for GDAL Python Batch jobs
module "batch_gdal_python_image" {
source = "git::https://github.com/wri/gfw-terraform-modules.git//terraform/modules/container_registry?ref=v0.4.2.3"
source = "git::https://github.com/wri/gfw-terraform-modules.git//terraform/modules/container_registry?ref=v0.4.2.7"
image_name = substr(lower("${local.project}-gdal_python${local.name_suffix}"), 0, 64)
root_dir = "${path.root}/../"
docker_path = "batch"
Expand All @@ -49,7 +48,7 @@ module "batch_gdal_python_image" {

# Docker image for PixETL Batch jobs
module "batch_pixetl_image" {
source = "git::https://github.com/wri/gfw-terraform-modules.git//terraform/modules/container_registry?ref=v0.4.2.3"
source = "git::https://github.com/wri/gfw-terraform-modules.git//terraform/modules/container_registry?ref=v0.4.2.7"
image_name = substr(lower("${local.project}-pixetl${local.name_suffix}"), 0, 64)
root_dir = "${path.root}/../"
docker_path = "batch"
Expand All @@ -58,7 +57,7 @@ module "batch_pixetl_image" {

# Docker image for PostgreSQL Client Batch jobs
module "batch_postgresql_client_image" {
source = "git::https://github.com/wri/gfw-terraform-modules.git//terraform/modules/container_registry?ref=v0.4.2.3"
source = "git::https://github.com/wri/gfw-terraform-modules.git//terraform/modules/container_registry?ref=v0.4.2.7"
image_name = substr(lower("${local.project}-postgresql_client${local.name_suffix}"), 0, 64)
root_dir = "${path.root}/../"
docker_path = "batch"
Expand All @@ -67,7 +66,7 @@ module "batch_postgresql_client_image" {

# Docker image for Tile Cache Batch jobs
module "batch_tile_cache_image" {
source = "git::https://github.com/wri/gfw-terraform-modules.git//terraform/modules/container_registry?ref=v0.4.2.3"
source = "git::https://github.com/wri/gfw-terraform-modules.git//terraform/modules/container_registry?ref=v0.4.2.7"
image_name = substr(lower("${local.project}-tile_cache${local.name_suffix}"), 0, 64)
root_dir = "${path.root}/../"
docker_path = "batch"
Expand All @@ -76,7 +75,7 @@ module "batch_tile_cache_image" {


module "fargate_autoscaling" {
source = "git::https://github.com/wri/gfw-terraform-modules.git//terraform/modules/fargate_autoscaling?ref=v0.4.2.5"
source = "git::https://github.com/wri/gfw-terraform-modules.git//terraform/modules/fargate_autoscaling?ref=v0.4.2.7"
project = local.project
name_suffix = local.name_suffix
tags = local.fargate_tags
Expand All @@ -96,7 +95,10 @@ module "fargate_autoscaling" {
auto_scaling_max_cpu_util = var.auto_scaling_max_cpu_util
auto_scaling_min_capacity = var.auto_scaling_min_capacity
// acm_certificate_arn = var.environment == "dev" ? null : data.terraform_remote_state.core.outputs.acm_certificate
security_group_ids = [data.terraform_remote_state.core.outputs.postgresql_security_group_id]
security_group_ids = [
data.terraform_remote_state.core.outputs.postgresql_security_group_id,
module.fargate_autoscaling.ecs_security_group_id
]
task_role_policies = [
data.terraform_remote_state.core.outputs.iam_policy_s3_write_data-lake_arn,
aws_iam_policy.run_batch_jobs.arn,
Expand All @@ -121,7 +123,7 @@ module "fargate_autoscaling" {

# Using instance types with 1 core only
module "batch_aurora_writer" {
source = "git::https://github.com/wri/gfw-terraform-modules.git//terraform/modules/compute_environment?ref=v0.4.2.3"
source = "git::https://github.com/wri/gfw-terraform-modules.git//terraform/modules/compute_environment?ref=v0.4.2.7"
ecs_role_policy_arns = [
data.terraform_remote_state.core.outputs.iam_policy_s3_write_data-lake_arn,
data.terraform_remote_state.core.outputs.secrets_postgresql-reader_policy_arn,
Expand All @@ -140,7 +142,8 @@ module "batch_aurora_writer" {
project = local.project
security_group_ids = [
data.terraform_remote_state.core.outputs.default_security_group_id,
data.terraform_remote_state.core.outputs.postgresql_security_group_id
data.terraform_remote_state.core.outputs.postgresql_security_group_id,
module.fargate_autoscaling.batch_security_group_id
]
subnets = data.terraform_remote_state.core.outputs.private_subnet_ids
suffix = local.name_suffix
Expand All @@ -152,7 +155,7 @@ module "batch_aurora_writer" {


module "batch_data_lake_writer" {
source = "git::https://github.com/wri/gfw-terraform-modules.git//terraform/modules/compute_environment?ref=v0.4.2.3"
source = "git::https://github.com/wri/gfw-terraform-modules.git//terraform/modules/compute_environment?ref=v0.4.2.7"
ecs_role_policy_arns = [
aws_iam_policy.query_batch_jobs.arn,
aws_iam_policy.s3_read_only.arn,
Expand All @@ -167,7 +170,8 @@ module "batch_data_lake_writer" {
project = local.project
security_group_ids = [
data.terraform_remote_state.core.outputs.default_security_group_id,
data.terraform_remote_state.core.outputs.postgresql_security_group_id
data.terraform_remote_state.core.outputs.postgresql_security_group_id,
module.fargate_autoscaling.batch_security_group_id
]
subnets = data.terraform_remote_state.core.outputs.private_subnet_ids
suffix = local.name_suffix
Expand Down
1 change: 0 additions & 1 deletion terraform/modules/batch/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ resource "aws_batch_job_queue" "pixetl" {
depends_on = [var.pixetl_compute_environment_arn]
}


resource "aws_batch_job_definition" "tile_cache" {
name = substr("${var.project}-tile_cache${var.name_suffix}", 0, 64)
type = "container"
Expand Down
2 changes: 1 addition & 1 deletion terraform/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ variable "load_balancer_arn" {
variable "load_balancer_security_group" {
type = string
default = ""
description = "Optional secuirty group of load balancer with which the task can communicate. Required if load_blancer_arn is not empty"
description = "Optional secuirty group of load balancer with which the task can communicate. Required if load_balancer_arn is not empty"
}

variable "listener_port" {
Expand Down
Loading