Skip to content

Commit

Permalink
dynamically set node heap size based on container memory limit (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
bruce-y authored Jan 27, 2023
1 parent 62c97df commit 7baa5a8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
9 changes: 9 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
#################################################################
# Cloud Run
#################################################################

locals {
_container_memory_value = regex("^(\\d*)(.*)", var.container_limits_memory)[0]
_container_memory_unit = regex("^(\\d*)(.*)", var.container_limits_memory)[1]
_container_memory_multiplier = lower(local._container_memory_unit) == "gi" ? 1000 : 1
node_heap = local._container_memory_value * 0.75 * local._container_memory_multiplier
}

module "cloud_run" {
count = var.deploy_in_cloud_run ? 1 : 0
source = "./modules/cloud-run"
Expand All @@ -21,6 +29,7 @@ module "cloud_run" {
"SUPERBLOCKS_AGENT_HOST_URL" = "https://${var.subdomain}.${var.domain}",
"SUPERBLOCKS_AGENT_ENVIRONMENT" = var.superblocks_agent_environment,
"SUPERBLOCKS_AGENT_PORT" = var.superblocks_agent_port
"NODE_OPTIONS" = "--max_old_space_size=${local.node_heap}"
}
container_cpu_throttling = var.container_cpu_throttling
container_requests_cpu = var.container_requests_cpu
Expand Down
1 change: 1 addition & 0 deletions modules/dns/main.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
data "google_dns_managed_zone" "superblocks" {
name = var.zone_name
project = var.project_id
}

locals {
Expand Down

0 comments on commit 7baa5a8

Please sign in to comment.