Opinionated.tf/products/docker_registry/registry.tf

76 lines
2.2 KiB
Terraform
Raw Permalink Normal View History

2024-12-06 18:39:06 +00:00
resource "random_password" "http_secret" {
length = 16
}
locals {
registry_config_yaml = {
version = 0.1
storage = {
2025-05-07 19:59:15 +00:00
s3 = merge(nonsensitive(var.s3), {
v4auth = true
chunksize = 5242880
secure = true
loglevel = "on"
2025-05-03 00:20:41 +00:00
})
cache = {
blobdescriptor = "inmemory"
}
delete = {
enabled = var.enable_delete
}
}
http = {
2025-05-03 00:20:41 +00:00
addr = ":5000"
2024-12-06 19:17:06 +00:00
secret = nonsensitive(random_password.http_secret.result)
host = var.domain
headers = {
2024-12-06 19:28:25 +00:00
Access-Control-Allow-Origin = concat(["https://${var.domain}", ], formatlist("https://%s", var.cors_domains))
Access-Control-Allow-Methods = ["HEAD", "GET", "DELETE", "OPTIONS"]
Access-Control-Allow-Credentials = ["true"]
Access-Control-Allow-Headers = ["Authorization", "Cache-Control", "Accept"]
Access-Control-Expose-Headers = ["Docker-Content-Digest"]
}
}
2025-05-03 00:20:41 +00:00
health = {
storagedriver = {
2025-05-07 19:59:15 +00:00
enabled = true
interval = "10s"
2025-05-03 00:20:41 +00:00
threshold = 3
}
}
auth = {
htpasswd = {
realm = "Registry Realm"
2025-05-03 00:20:41 +00:00
path = "/etc/distribution/htpasswd"
}
}
log = {
fields = {
service = "registry"
}
}
}
}
module "docker_registry" {
2024-12-26 16:23:09 +00:00
source = "../../docker/service"
2025-05-07 19:59:15 +00:00
debug = true
2024-12-26 16:23:09 +00:00
stack_name = var.stack_name
service_name = "registry"
2025-05-03 00:20:41 +00:00
image = "registry:3"
restart_policy = "on-failure"
placement_constraints = var.placement_constraints
2025-03-03 14:46:21 +00:00
ports = var.ports
2025-05-03 00:20:41 +00:00
networks = concat([module.registry_network], var.networks)
2024-12-06 19:17:06 +00:00
traefik = merge(var.traefik, { port = 5000, rule = "Host(`${var.domain}`) && PathPrefix(`/v2`)" })
configs = {
2025-05-03 00:20:41 +00:00
"/etc/distribution/config.yml" = yamlencode(local.registry_config_yaml)
"/etc/distribution/htpasswd" = local.registry_htpasswd
}
2025-01-21 12:37:20 +00:00
healthcheck = ["CMD", "wget", "-q", "http://localhost:5000/", "-O", "/dev/null"]
converge_enable = true
converge_timeout = "2m"
2025-05-07 19:59:15 +00:00
dns_nameservers = var.dns_nameservers
2025-05-03 00:20:41 +00:00
environment_variables = {
OTEL_TRACES_EXPORTER = "none"
}
}