From 6b46e99bc3636a473d125a8b01bd76e69f2332ab Mon Sep 17 00:00:00 2001 From: Jake Heath <76011913+jakeyheath@users.noreply.github.com> Date: Mon, 25 Nov 2024 14:48:16 -0800 Subject: [PATCH] feat: allow stacks to overwrite their image URI (#3690) Co-authored-by: github-actions[bot] --- terraform/modules/happy-service-eks/README.md | 1 + terraform/modules/happy-service-eks/main.tf | 2 +- terraform/modules/happy-service-eks/variables.tf | 6 ++++++ terraform/modules/happy-stack-eks/README.md | 1 + terraform/modules/happy-stack-eks/main.tf | 1 + terraform/modules/happy-stack-eks/variables.tf | 6 ++++++ 6 files changed, 16 insertions(+), 1 deletion(-) diff --git a/terraform/modules/happy-service-eks/README.md b/terraform/modules/happy-service-eks/README.md index 22a3378c6d..8567f00b38 100644 --- a/terraform/modules/happy-service-eks/README.md +++ b/terraform/modules/happy-service-eks/README.md @@ -73,6 +73,7 @@ | [health\_check\_path](#input\_health\_check\_path) | path to use for health checks | `string` | `"/"` | no | | [image\_pull\_policy](#input\_image\_pull\_policy) | The image pull policy to use | `string` | `"IfNotPresent"` | no | | [image\_tag](#input\_image\_tag) | The image tag to deploy | `string` | n/a | yes | +| [image\_uri](#input\_image\_uri) | The image URI to deploy | `string` | `""` | no | | [ingress\_security\_groups](#input\_ingress\_security\_groups) | A list of security groups that should be allowed to communicate with the ALB ingress. Currently only used when the service\_type is VPC. | `list(string)` | `[]` | no | | [init\_containers](#input\_init\_containers) | Map of init containers to bootstrap the service |
map(object({
image : string
tag : string
cmd : optional(list(string), [])
}))
| `{}` | no | | [initial\_delay\_seconds](#input\_initial\_delay\_seconds) | The initial delay in seconds for the liveness and readiness probes. | `number` | `30` | no | diff --git a/terraform/modules/happy-service-eks/main.tf b/terraform/modules/happy-service-eks/main.tf index feedcf3edb..19df5f805e 100644 --- a/terraform/modules/happy-service-eks/main.tf +++ b/terraform/modules/happy-service-eks/main.tf @@ -176,7 +176,7 @@ resource "kubernetes_deployment_v1" "deployment" { container { name = var.container_name - image = "${module.ecr.repository_url}:${var.image_tag}" + image = "${length(var.image_uri) == 0 ? module.ecr.repository_url : var.image_uri}:${var.image_tag}" command = var.cmd args = var.args image_pull_policy = var.image_pull_policy diff --git a/terraform/modules/happy-service-eks/variables.tf b/terraform/modules/happy-service-eks/variables.tf index a8c4e03794..0f82cddf37 100644 --- a/terraform/modules/happy-service-eks/variables.tf +++ b/terraform/modules/happy-service-eks/variables.tf @@ -51,6 +51,12 @@ variable "args" { default = [] } +variable "image_uri" { + type = string + description = "The image URI to deploy" + default = "" +} + variable "image_tag" { type = string description = "The image tag to deploy" diff --git a/terraform/modules/happy-stack-eks/README.md b/terraform/modules/happy-stack-eks/README.md index 23a6da9a10..b0cb5dcadc 100644 --- a/terraform/modules/happy-stack-eks/README.md +++ b/terraform/modules/happy-stack-eks/README.md @@ -58,6 +58,7 @@ | [enable\_service\_mesh](#input\_enable\_service\_mesh) | Enable service mesh for this stack | `bool` | `false` | no | | [image\_tag](#input\_image\_tag) | Please provide a default image tag | `string` | n/a | yes | | [image\_tags](#input\_image\_tags) | Override image tag for each docker image | `map(string)` | `{}` | no | +| [image\_uri](#input\_image\_uri) | The URI of the docker image to deploy, defaults to the image URI created by happy | `string` | `""` | no | | [k8s\_namespace](#input\_k8s\_namespace) | K8S namespace for this stack | `string` | n/a | yes | | [routing\_method](#input\_routing\_method) | Traffic routing method for this stack. Valid options are 'DOMAIN', when every service gets a unique domain name, or a 'CONTEXT' when all services share the same domain name, and routing is done by request path. | `string` | `"DOMAIN"` | no | | [services](#input\_services) | The services you want to deploy as part of this stack. |
map(object({
name = string,
service_type = optional(string, "INTERNAL"),
allow_mesh_services = optional(list(object({
service = optional(string, null),
stack = optional(string, null),
service_account_name = optional(string, null)
})), null),
ingress_security_groups = optional(list(string), []), // Only used for VPC service_type
alb = optional(object({
name = string,
listener_port = number,
}), null), // Only used for TARGET_GROUP_ONLY
desired_count = optional(number, 2),
max_count = optional(number, 5),
max_unavailable_count = optional(string, "1"),
scaling_cpu_threshold_percentage = optional(number, 80),
port = optional(number, 80),
scheme = optional(string, "HTTP"),
cmd = optional(list(string), []),
args = optional(list(string), []),
image_pull_policy = optional(string, "IfNotPresent"), // Supported values= IfNotPresent, Always, Never
tag_mutability = optional(bool, true),
scan_on_push = optional(bool, false),
service_port = optional(number, null),
service_scheme = optional(string, "HTTP"),
linkerd_additional_skip_ports = optional(set(number), []),
memory = optional(string, "500Mi"),
memory_requests = optional(string, "200Mi"),
cpu = optional(string, "1"),
cpu_requests = optional(string, "500m"),
gpu = optional(number, null), // Whole number of GPUs to request, 0 will schedule all available GPUs. Requires GPU-enabled nodes in the cluster, `k8s-device-plugin` installed, platform_architecture = "amd64", and additional_node_selectors = { "nvidia.com/gpu.present" = "true" } present.
health_check_path = optional(string, "/"),
health_check_command = optional(list(string), [])
aws_iam = optional(object({
policy_json = optional(string, ""),
service_account_name = optional(string, null),
}), {}),
path = optional(string, "/*"), // Only used for CONTEXT and TARGET_GROUP_ONLY routing
priority = optional(number, 0), // Only used for CONTEXT and TARGET_GROUP_ONLY routing
success_codes = optional(string, "200-499"),
synthetics = optional(bool, false),
initial_delay_seconds = optional(number, 30),
alb_idle_timeout = optional(number, 60) // in seconds
period_seconds = optional(number, 3),
liveness_timeout_seconds = optional(number, 30),
readiness_timeout_seconds = optional(number, 30),
progress_deadline_seconds = optional(number, 600),
platform_architecture = optional(string, "amd64"), // Supported values= amd64, arm64; GPU nodes are amd64 only.
additional_node_selectors = optional(map(string), {}), // For GPU use= { "nvidia.com/gpu.present" = "true" }
bypasses = optional(map(object({ // Only used for INTERNAL service_type
paths = optional(set(string), [])
methods = optional(set(string), [])
deny_action = optional(object({
deny = optional(bool, false)
deny_status_code = optional(string, "403")
deny_message_body = optional(string, "Denied")
}), {})
})), {})
sticky_sessions = optional(object({
enabled = optional(bool, false),
duration_seconds = optional(number, 600),
cookie_name = optional(string, "happy_sticky_session"),
}), {})
sidecars = optional(map(object({
image = string
tag = string
cmd = optional(list(string), [])
args = optional(list(string), [])
port = optional(number, 80)
scheme = optional(string, "HTTP")
memory = optional(string, "200Mi")
cpu = optional(string, "500m")
image_pull_policy = optional(string, "IfNotPresent") // Supported values= IfNotPresent, Always, Never
health_check_path = optional(string, "/")
initial_delay_seconds = optional(number, 30)
period_seconds = optional(number, 3)
liveness_timeout_seconds = optional(number, 30)
readiness_timeout_seconds = optional(number, 30)
})), {})
init_containers = optional(map(object({
image = string
tag = string
cmd = optional(list(string), []),
})), {}),
additional_env_vars = optional(map(string), {}),
cache_volume_mount_dir = optional(string, "/var/shared/cache"),
oidc_config = optional(object({
issuer = string
authorizationEndpoint = string
tokenEndpoint = string
userInfoEndpoint = string
secretName = string
}), null)
}))
| n/a | yes | diff --git a/terraform/modules/happy-stack-eks/main.tf b/terraform/modules/happy-stack-eks/main.tf index 8de5ba35fa..336a9dc0d9 100644 --- a/terraform/modules/happy-stack-eks/main.tf +++ b/terraform/modules/happy-stack-eks/main.tf @@ -166,6 +166,7 @@ module "services" { source = "../happy-service-eks" image_tag = lookup(var.image_tags, each.key, var.image_tag) + image_uri = var.image_uri tag_mutability = each.value.tag_mutability scan_on_push = each.value.scan_on_push container_name = each.value.name diff --git a/terraform/modules/happy-stack-eks/variables.tf b/terraform/modules/happy-stack-eks/variables.tf index 1bc8e6b346..ccbab06b1a 100644 --- a/terraform/modules/happy-stack-eks/variables.tf +++ b/terraform/modules/happy-stack-eks/variables.tf @@ -4,6 +4,12 @@ variable "app_name" { default = "" } +variable "image_uri" { + type = string + description = "The URI of the docker image to deploy, defaults to the image URI created by happy" + default = "" +} + variable "image_tags" { type = map(string) description = "Override image tag for each docker image"