1
0
mirror of https://github.com/containous/traefik.git synced 2024-12-22 13:34:03 +03:00
This commit is contained in:
emile 2015-09-10 16:14:08 +02:00
parent 46ef489b03
commit 4dc5b34122
8 changed files with 40 additions and 11 deletions

View File

@ -2,7 +2,6 @@
* Godoc
* Weights
* Licence
* GraceTimeout
* Filter no exposed port apps
* Filter træfik.enabled=false apps
* Add træfik.indlude all/enabled policy
@ -14,3 +13,5 @@
* Smart configuration diff
* README
* ~~GraceTimeout~~

View File

@ -24,6 +24,7 @@ type Backend struct {
type Server struct {
Url string
Weight int
}
type Rule struct {

View File

@ -37,6 +37,14 @@ var DockerFuncMap = template.FuncMap{
}
return ""
},
"getWeight": func(container docker.Container) string {
for key, value := range container.Config.Labels {
if (key == "træfik.weight") {
return value
}
}
return "0"
},
"replace": func(s1 string, s2 string, s3 string) string {
return strings.Replace(s3, s1, s2, -1)
},

View File

@ -1,6 +1,7 @@
[backends]{{range .Containers}}
[backends.backend-{{getBackend .}}.servers.server-{{.Name | replace "/" "" | replace "." "-"}}]
url = "http://{{.NetworkSettings.IPAddress}}:{{getPort .}}"
weight = {{getWeight .}}
{{end}}
[routes]{{range $host, $containers := .Hosts}}

View File

@ -34,6 +34,14 @@ var MarathonFuncMap = template.FuncMap{
}
return strings.Replace(application.ID, "/", "", 1)
},
"getWeight": func(application marathon.Application) string {
for key, value := range application.Labels {
if (key == "træfik.weight") {
return value
}
}
return "0"
},
"replace": func(s1 string, s2 string, s3 string) string {
return strings.Replace(s3, s1, s2, -1)
},

View File

@ -1,6 +1,13 @@
{{$apps := .Applications}}
[backends]{{range .Tasks}}
[backends.backend{{.AppID | replace "/" "-"}}.servers.server-{{.ID | replace "." "-"}}]
url = "http://{{.Host}}:{{getPort .}}"
{{$appID := .AppID}}
{{range $apps}}
{{if eq $appID .ID}}
weight = {{getWeight .}}
{{end}}
{{end}}
{{end}}
[routes]{{range .Applications}}

View File

@ -137,7 +137,7 @@ func LoadConfig(configuration *Configuration) *mux.Router {
for serverName, server := range configuration.Backends[route.Backend].Servers {
log.Println("Creating server", serverName)
url, _ := url.Parse(server.Url)
rb.UpsertServer(url)
rb.UpsertServer(url, roundrobin.Weight(server.Weight))
}
backends[route.Backend]=lb
}else {

View File

@ -1,35 +1,38 @@
port = ":8001"
graceTimeOut = 10
#[docker]
#endpoint = "unix:///var/run/docker.sock"
#watch = true
#domain = "toto.fr"
#filename = "docker.tmpl"
# [docker]
# endpoint = "unix:///var/run/docker.sock"
# watch = true
# domain = "toto.fr"
# filename = "docker.tmpl"
[marathon]
endpoint = "http://127.0.0.1:8080"
networkInterface = "eth0"
watch = true
domain = "toto.fr"
filename = "marathon.tmpl"
networkInterface = "eth0"
[web]
address = ":8010"
#[file]
#filename = "rules.toml"
#watch = true
# [file]
# filename = "rules.toml"
# watch = true
[backends]
[backends.backend1]
[backends.backend1.servers.server1]
url = "http://172.17.0.2:80"
weight = 10
[backends.backend1.servers.server2]
url = "http://172.17.0.3:80"
weight = 1
[backends.backend2]
[backends.backend2.servers.server1]
url = "http://172.17.0.2:80"
weight = 100
[routes]
[routes.route1]