Merge pull request #52 from EmileVauge/emilevauge-add-traefik-domain
Add traefik.domain label #51
This commit is contained in:
commit
adca5dc55b
6 changed files with 89 additions and 73 deletions
75
docker.go
75
docker.go
|
@ -22,40 +22,6 @@ type DockerProvider struct {
|
|||
Domain string
|
||||
}
|
||||
|
||||
var DockerFuncMap = template.FuncMap{
|
||||
"getBackend": func(container docker.Container) string {
|
||||
for key, value := range container.Config.Labels {
|
||||
if key == "traefik.backend" {
|
||||
return value
|
||||
}
|
||||
}
|
||||
return getHost(container)
|
||||
},
|
||||
"getPort": func(container docker.Container) string {
|
||||
for key, value := range container.Config.Labels {
|
||||
if key == "traefik.port" {
|
||||
return value
|
||||
}
|
||||
}
|
||||
for key := range container.NetworkSettings.Ports {
|
||||
return key.Port()
|
||||
}
|
||||
return ""
|
||||
},
|
||||
"getWeight": func(container docker.Container) string {
|
||||
for key, value := range container.Config.Labels {
|
||||
if key == "traefik.weight" {
|
||||
return value
|
||||
}
|
||||
}
|
||||
return "0"
|
||||
},
|
||||
"replace": func(s1 string, s2 string, s3 string) string {
|
||||
return strings.Replace(s3, s1, s2, -1)
|
||||
},
|
||||
"getHost": getHost,
|
||||
}
|
||||
|
||||
func (provider *DockerProvider) Provide(configurationChan chan<- configMessage) error {
|
||||
if dockerClient, err := docker.NewClient(provider.Endpoint); err != nil {
|
||||
log.Errorf("Failed to create a client for docker, error: %s", err)
|
||||
|
@ -105,6 +71,47 @@ func (provider *DockerProvider) Provide(configurationChan chan<- configMessage)
|
|||
}
|
||||
|
||||
func (provider *DockerProvider) loadDockerConfig(dockerClient *docker.Client) *Configuration {
|
||||
var DockerFuncMap = template.FuncMap{
|
||||
"getBackend": func(container docker.Container) string {
|
||||
for key, value := range container.Config.Labels {
|
||||
if key == "traefik.backend" {
|
||||
return value
|
||||
}
|
||||
}
|
||||
return getHost(container)
|
||||
},
|
||||
"getPort": func(container docker.Container) string {
|
||||
for key, value := range container.Config.Labels {
|
||||
if key == "traefik.port" {
|
||||
return value
|
||||
}
|
||||
}
|
||||
for key := range container.NetworkSettings.Ports {
|
||||
return key.Port()
|
||||
}
|
||||
return ""
|
||||
},
|
||||
"getWeight": func(container docker.Container) string {
|
||||
for key, value := range container.Config.Labels {
|
||||
if key == "traefik.weight" {
|
||||
return value
|
||||
}
|
||||
}
|
||||
return "0"
|
||||
},
|
||||
"getDomain": func(container docker.Container) string {
|
||||
for key, value := range container.Config.Labels {
|
||||
if key == "traefik.domain" {
|
||||
return value
|
||||
}
|
||||
}
|
||||
return provider.Domain
|
||||
},
|
||||
"replace": func(s1 string, s2 string, s3 string) string {
|
||||
return strings.Replace(s3, s1, s2, -1)
|
||||
},
|
||||
"getHost": getHost,
|
||||
}
|
||||
configuration := new(Configuration)
|
||||
containerList, _ := dockerClient.ListContainers(docker.ListContainersOptions{})
|
||||
containersInspected := []docker.Container{}
|
||||
|
|
|
@ -402,6 +402,7 @@ Labels can be used on containers to override default behaviour:
|
|||
* `traefik.weight=10`: assign this weight to the container
|
||||
* `traefik.enable=false`: disable this container in Træfɪk
|
||||
* `traefik.host=bar`: override the default routing from {containerName}.{domain} to bar.{domain}
|
||||
* `traefik.domain=traefik.localhost`: override the default domain
|
||||
|
||||
## <a id="marathon"></a> Marathon backend
|
||||
|
||||
|
@ -461,6 +462,7 @@ Labels can be used on containers to override default behaviour:
|
|||
* `traefik.enable=false`: disable this application in Træfɪk
|
||||
* `traefik.host=bar`: override the default routing from {appName}.{domain} to bar.{domain}
|
||||
* `traefik.prefixes=pf1,pf2`: use PathPrefix(es) instead of hostname for routing, use filename="providerTemplates/marathon-prefix.tmpl" with this option
|
||||
* `traefik.domain=traefik.localhost`: override the default domain
|
||||
|
||||
## <a id="consul"></a> Consul backend
|
||||
|
||||
|
|
79
marathon.go
79
marathon.go
|
@ -21,42 +21,6 @@ type MarathonProvider struct {
|
|||
NetworkInterface string
|
||||
}
|
||||
|
||||
var MarathonFuncMap = template.FuncMap{
|
||||
"getPort": func(task marathon.Task) string {
|
||||
for _, port := range task.Ports {
|
||||
return strconv.Itoa(port)
|
||||
}
|
||||
return ""
|
||||
},
|
||||
"getHost": func(application marathon.Application) string {
|
||||
for key, value := range application.Labels {
|
||||
if key == "traefik.host" {
|
||||
return value
|
||||
}
|
||||
}
|
||||
return strings.Replace(application.ID, "/", "", 1)
|
||||
},
|
||||
"getWeight": func(application marathon.Application) string {
|
||||
for key, value := range application.Labels {
|
||||
if key == "traefik.weight" {
|
||||
return value
|
||||
}
|
||||
}
|
||||
return "0"
|
||||
},
|
||||
"getPrefixes": func(application marathon.Application) ([]string, error) {
|
||||
for key, value := range application.Labels {
|
||||
if key == "traefik.prefixes" {
|
||||
return strings.Split(value, ","), nil
|
||||
}
|
||||
}
|
||||
return []string{}, nil
|
||||
},
|
||||
"replace": func(s1 string, s2 string, s3 string) string {
|
||||
return strings.Replace(s3, s1, s2, -1)
|
||||
},
|
||||
}
|
||||
|
||||
func (provider *MarathonProvider) Provide(configurationChan chan<- configMessage) error {
|
||||
config := marathon.NewDefaultConfig()
|
||||
config.URL = provider.Endpoint
|
||||
|
@ -91,6 +55,49 @@ func (provider *MarathonProvider) Provide(configurationChan chan<- configMessage
|
|||
}
|
||||
|
||||
func (provider *MarathonProvider) loadMarathonConfig() *Configuration {
|
||||
var MarathonFuncMap = template.FuncMap{
|
||||
"getPort": func(task marathon.Task) string {
|
||||
for _, port := range task.Ports {
|
||||
return strconv.Itoa(port)
|
||||
}
|
||||
return ""
|
||||
},
|
||||
"getHost": func(application marathon.Application) string {
|
||||
for key, value := range application.Labels {
|
||||
if key == "traefik.host" {
|
||||
return value
|
||||
}
|
||||
}
|
||||
return strings.Replace(application.ID, "/", "", 1)
|
||||
},
|
||||
"getWeight": func(application marathon.Application) string {
|
||||
for key, value := range application.Labels {
|
||||
if key == "traefik.weight" {
|
||||
return value
|
||||
}
|
||||
}
|
||||
return "0"
|
||||
},
|
||||
"getDomain": func(application marathon.Application) string {
|
||||
for key, value := range application.Labels {
|
||||
if key == "traefik.domain" {
|
||||
return value
|
||||
}
|
||||
}
|
||||
return provider.Domain
|
||||
},
|
||||
"getPrefixes": func(application marathon.Application) ([]string, error) {
|
||||
for key, value := range application.Labels {
|
||||
if key == "traefik.prefixes" {
|
||||
return strings.Split(value, ","), nil
|
||||
}
|
||||
}
|
||||
return []string{}, nil
|
||||
},
|
||||
"replace": func(s1 string, s2 string, s3 string) string {
|
||||
return strings.Replace(s3, s1, s2, -1)
|
||||
},
|
||||
}
|
||||
configuration := new(Configuration)
|
||||
|
||||
applications, err := provider.marathonClient.Applications(nil)
|
||||
|
|
|
@ -10,5 +10,5 @@
|
|||
backend = "backend-{{getBackend $container}}"
|
||||
[frontends.frontend-{{$host}}.routes.route-host-{{$host}}]
|
||||
rule = "Host"
|
||||
value = "{{$host}}.{{$.Domain}}"
|
||||
value = "{{$host}}.{{getDomain $container}}"
|
||||
{{end}}
|
|
@ -22,6 +22,6 @@
|
|||
backend = "backend{{.ID | replace "/" "-"}}"
|
||||
[frontends.frontend-{{getHost $app | replace "/" "-"}}.routes.route-host-{{getHost $app | replace "/" "-"}}]
|
||||
rule = "Host"
|
||||
value = "{{getHost $app | replace "/" "-"}}.{{$.Domain}}"
|
||||
value = "{{getHost $app | replace "/" "-"}}.{{getDomain .}}"
|
||||
{{end}}
|
||||
{{end}}
|
||||
|
|
|
@ -15,5 +15,5 @@
|
|||
backend = "backend{{.ID | replace "/" "-"}}"
|
||||
[frontends.frontend-{{getHost . | replace "/" "-"}}.routes.route-host-{{getHost . | replace "/" "-"}}]
|
||||
rule = "Host"
|
||||
value = "{{getHost . | replace "/" "-"}}.{{$.Domain}}"
|
||||
value = "{{getHost . | replace "/" "-"}}.{{getDomain .}}"
|
||||
{{end}}
|
Loading…
Reference in a new issue