Add DomainRedirect Service

This commit is contained in:
Caleb Braaten 2024-02-20 14:51:36 -08:00
parent 8428e1a269
commit b686486c93
2 changed files with 70 additions and 0 deletions

View File

@ -0,0 +1,52 @@
locals {
HOST = "example.local"
TARGET = "https://example.com/path"
}
job "domainredirect" {
datacenters = ["dc1"]
type = "service"
group "domainredirect" {
count = 1
network {
port "http" {
to = 8080
}
}
service {
name = "domainredirect"
provider = "consul"
port = "http"
tags = [
"traefik.enable=true",
"traefik.http.routers.domainredirect.tls=true",
"traefik.http.routers.domainredirect.entrypoints=websecure",
"traefik.http.routers.domainredirect.rule=Host(`${local.HOST}`)",
]
check {
type = "http"
path = "/health"
interval = "10s"
timeout = "2s"
}
}
task "domainredirect" {
driver = "docker"
config {
image = "git.cbraaten.dev/caleb/domainredirect:latest"
ports = ["http"]
}
env {
REDIRECT_TARGET = local.TARGET
}
}
}
}

View File

@ -0,0 +1,18 @@
# domainredirect
domainredirect is just a redirect service that will redirect any traffic to the url you you specify. This is useful for redirecting traffic from one domain to another.
## Nomad Job for domainredirect
The domainredirect expects a REDIRECT_TARGET environment variable to be set. This is the complete url that the domainredirect will redirect to. You can set it on line 2 of the job spec.
## TODO
If you want to deploy this, you will need to update the domain name in the job spec.
| Line | Default | Adjustment |
| --- | --- | --- |
| 2 | `HOST = "example.local"` | Change `example.local` to the domain you are listening on |
| 3 | `TARGET = "https://example.com/path"` | Change `example.com/path` to your destination |
## Request
If you are deploying this regularly, please consider pulling the image and pushing it to your own registry. This will help reduce the load on my registry and help keep the image available for everyone. (Although it's not that complex, you could also [build the image yourself.](https://git.cbraaten.dev/Caleb/DomainRedirect))