1
0
mirror of https://github.com/umputun/reproxy.git synced 2024-11-24 08:12:31 +02:00

correct providers order

This commit is contained in:
Umputun 2021-04-12 02:07:35 -05:00
parent 9c659afb0f
commit a79cd3c7a4

View File

@ -8,6 +8,7 @@ import (
"os"
"os/signal"
"runtime"
"strings"
"syscall"
"time"
@ -56,6 +57,7 @@ var opts struct {
Host string `long:"host" env:"HOST" default:"unix:///var/run/docker.sock" description:"docker host"`
Network string `long:"network" env:"NETWORK" default:"" description:"docker network"`
Excluded []string `long:"exclude" env:"EXCLUDE" description:"excluded containers" env-delim:","`
AutoAPI bool `long:"auto" env:"AUTO" description:"enable automatic routing (without labels)"`
} `group:"docker" namespace:"docker" env-namespace:"DOCKER"`
File struct {
@ -143,9 +145,20 @@ func main() {
}
}
// make all providers. the order is matter, defines which provider will have priority in case of conflicting rules
// static first, file second and docker the last one
func makeProviders() ([]discovery.Provider, error) {
var res []discovery.Provider
if opts.Static.Enabled {
var msgs []string
for _, rule := range opts.Static.Rules {
msgs = append(msgs, "\""+rule+"\"")
}
log.Printf("[DEBUG] inject static rules: %s", strings.Join(msgs, " "))
res = append(res, &provider.Static{Rules: opts.Static.Rules})
}
if opts.File.Enabled {
res = append(res, &provider.File{
FileName: opts.File.Name,
@ -162,10 +175,6 @@ func makeProviders() ([]discovery.Provider, error) {
res = append(res, &provider.Docker{DockerClient: client, Excludes: opts.Docker.Excluded, Network: opts.Docker.Network})
}
if opts.Static.Enabled {
res = append(res, &provider.Static{Rules: opts.Static.Rules})
}
if len(res) == 0 && opts.Assets.Location == "" {
return nil, errors.Errorf("no providers enabled")
}