traefik / traefik

The Cloud Native Application Proxy
https://traefik.io
MIT License
49.24k stars 4.93k forks source link

Frontend rules based on dynamic environments/domains/zones #2916

Open gaui opened 6 years ago

gaui commented 6 years ago

Do you want to request a feature or report a bug?

feature

What is your environment & configuration (arguments, toml, provider, platform, ...)?

logLevel = "INFO"
debug = false
defaultEntryPoints = ["http"]

[traefikLog]
filePath = "/logs/traefik.log"

[accessLog]
filePath = "/logs/access.log"

[api]
entryPoint = "traefik"
dashboard = true
debug = false

[rest]
entryPoint = "traefik"

[ping]
entryPoint = "traefik"

[docker]
exposedbydefault = false
watch = true
domain = "dev.domain.tld"
swarmmode = true

[entryPoints]
  [entryPoints.http]
  address = ":80"

  [entryPoints.traefik]
  address = ":8080"
  [entryPoints.traefik.auth.basic]
    usersFile = "/.htpasswd"

Feature request

When you specify docker.domain=dev.domain.tld in the TOML and create a Docker Swarm service/stack the default frontend rule will be stackName-serviceName.dev.domain.tld, which is really ugly when you have a single service per stack file.

How to change this? I could specify a custom Host or HostRegexp frontend rule, something like traefik.frontend.rule=HostRegexp:customName.{subdomain:(dev|staging|prod)}.domain.tld but it's really hacky/messy and you're stuck with these 3 environments. What if I add a new VPC for our release/pre-prod environment?

I'm using Terraform to span up a Docker Swarm for 3 different Terraform workspaces / VPCs (dev, staging, production) and using Træfik on each of them....... The traefik.toml is set up on the server initially when the instance is provisioned and the docker.domain is specified in it, based on my DNS zone Terraform resource and I keep my Docker stack/compose files seperate without specifying domain in each of them (because it varies between environments). Same Docker stack/compose file, different environments (VPC / DNS zones).

This would be really beneficial for those who are aiming at infrastructure-as-code with Terraform and trying to seperate domain/DNS/zones from frontend rules and want to keep their Docker stack/compose files "stateless" and not coupled to the environment/domain/DNS zone.

Let's say I want to use the same Docker stack file for 3 different DNS zones and 3 different Træfik instances... dev.domain.tld, staging.domain.tld, prod.domain.tld I would like to specify myservice as a frontend/subdomain rule and it would work for all 3 different zones (based on docker.domain specified in the traefik.toml on the server), so the same Docker stack/compose file with myservice frontend rule in the Docker stack/compose file, would work for myservice.dev.domain.tld on Træfik instance on dev environment, myservice.staging.domain.tld on Træfik instance on staging environment and myservice.prod.domain.tld on Træfik instance on production environment.

I suggest to allow people to change the name of the stack/service via Træfik frontend label (traefik.name=someCustomName), so it would not become stackName-serviceName but instead someCustomName and that would generate a default frontend rule someCustomName.domain.tld. Or to create a new variable ${domain} you could use in Docker service/container Træfik labels, so you could set docker.domain=dev.domain.tld (generated via TOML template file in Terraform) and then in stack file, use traefik.frontend.rule=Host:customName.${domain} and that would be translated to Host:customName.dev.domain.tld or whatever domain is set in the TOML. Then people could be in same control, without having to couple the domain to the Docker stack/compose file.

traefiker commented 6 years ago

Every time someone does not respect the issue's template, a little bunny dies.

![southpark - estrella kill rabbit](https://user-images.githubusercontent.com/5674651/27143914-3cea7896-5130-11e7-81f8-02d8ac2da7a7.gif) ![southpark - estrella kill rabbit2](https://user-images.githubusercontent.com/5674651/27143924-49104c72-5130-11e7-82ae-ccedbd5dfa1c.gif)


Please edit your issue description to respect the issue template as much as possible.

gaui commented 6 years ago

@traefiker I fixed it!

manuchauvet commented 6 years ago

+1 Similar need