All checks were successful
Build and Push Docker Image / build (push) Successful in 2m6s
94 lines
2.6 KiB
HCL
94 lines
2.6 KiB
HCL
# export to json for ci/cd scripts with the following command
|
|
# nomad job run -output blog.nomad.hcl > blog.nomad.json
|
|
|
|
locals {
|
|
HOST = "cbraaten.dev"
|
|
|
|
# shared by both production and canary allocations so Traefik never
|
|
# loses sight of the router during a rolling switchover
|
|
traefik_tags = [
|
|
# ----- router for the naked domain -----
|
|
"traefik.enable=true",
|
|
"traefik.http.routers.blog.rule=Host(`${local.HOST}`)",
|
|
"traefik.http.routers.blog.entrypoints=websecure",
|
|
"traefik.http.routers.blog.tls=true",
|
|
"traefik.http.routers.blog.service=blog-svc",
|
|
|
|
# ----- router for the www domain -----
|
|
"traefik.http.routers.blog-www.rule=Host(`www.${local.HOST}`)",
|
|
"traefik.http.routers.blog-www.entrypoints=websecure",
|
|
"traefik.http.routers.blog-www.tls=true",
|
|
"traefik.http.routers.blog-www.middlewares=redirect-www-to-root",
|
|
|
|
# ----- middleware that does the 301 redirect -----
|
|
"traefik.http.middlewares.redirect-www-to-root.redirectregex.regex=^https?://www\\.${local.HOST}(.*)",
|
|
"traefik.http.middlewares.redirect-www-to-root.redirectregex.replacement=https://${local.HOST}$${1}",
|
|
"traefik.http.middlewares.redirect-www-to-root.redirectregex.permanent=true",
|
|
|
|
# ----- service and health check -----
|
|
"traefik.http.services.blog-svc.loadbalancer.healthcheck.path=/healthz",
|
|
"traefik.http.services.blog-svc.loadbalancer.healthcheck.interval=5s",
|
|
"traefik.http.services.blog-svc.loadbalancer.healthcheck.timeout=2s",
|
|
"traefik.http.services.blog-svc.loadbalancer.healthcheck.hostname=${local.HOST}",
|
|
]
|
|
}
|
|
|
|
variable "image_tag" {
|
|
type = string
|
|
default = "latest"
|
|
}
|
|
|
|
job "blog" {
|
|
type = "service"
|
|
|
|
group "blog" {
|
|
count = 1
|
|
|
|
# let Consul/Traefik deregister the old allocation before it exits,
|
|
# so no requests are routed to it during a rolling switchover
|
|
shutdown_delay = "10s"
|
|
|
|
network {
|
|
port "http" {
|
|
to = 3000
|
|
}
|
|
}
|
|
|
|
service {
|
|
name = "blog"
|
|
provider = "consul"
|
|
port = "http"
|
|
|
|
tags = local.traefik_tags
|
|
canary_tags = local.traefik_tags
|
|
|
|
check {
|
|
name = "blog-health"
|
|
type = "http"
|
|
path = "/healthz"
|
|
interval = "10s"
|
|
timeout = "2s"
|
|
}
|
|
}
|
|
|
|
task "blog" {
|
|
driver = "docker"
|
|
|
|
config {
|
|
image = "git.cbraaten.dev/caleb/blog:${var.image_tag}"
|
|
ports = ["http"]
|
|
}
|
|
}
|
|
|
|
update {
|
|
max_parallel = 1
|
|
health_check = "checks"
|
|
min_healthy_time = "10s"
|
|
healthy_deadline = "3m"
|
|
canary = 1
|
|
auto_promote = true
|
|
auto_revert = true
|
|
}
|
|
}
|
|
}
|