From efded2cf5efcb16dac6ec54437629671f6ff902a Mon Sep 17 00:00:00 2001 From: Umputun Date: Fri, 23 Apr 2021 04:05:14 -0500 Subject: [PATCH] flip order in docker proxy+static labels #55 we want proxy rule to have priority over assets rule --- app/discovery/provider/docker.go | 11 ++++++----- app/discovery/provider/docker_test.go | 21 +++++++++++++++++++++ 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/app/discovery/provider/docker.go b/app/discovery/provider/docker.go index f25ae38..ee3f6e4 100644 --- a/app/discovery/provider/docker.go +++ b/app/discovery/provider/docker.go @@ -135,6 +135,12 @@ func (d *Docker) List() ([]discovery.URLMapper, error) { mp := discovery.URLMapper{Server: strings.TrimSpace(srv), SrcMatch: *srcRegex, Dst: destURL, PingURL: pingURL, ProviderID: discovery.PIDocker, MatchType: discovery.MTProxy} + // for assets we add the second proxy mapping only if explicitly requested + if assetsWebRoot != "" && explicit { + mp.MatchType = discovery.MTProxy + res = append(res, mp) + } + if assetsWebRoot != "" { mp.MatchType = discovery.MTStatic mp.AssetsWebRoot = assetsWebRoot @@ -142,11 +148,6 @@ func (d *Docker) List() ([]discovery.URLMapper, error) { } res = append(res, mp) - // for assets we add the second proxy mapping only if explicitly requested - if assetsWebRoot != "" && explicit { - mp.MatchType = discovery.MTProxy - res = append(res, mp) - } } } diff --git a/app/discovery/provider/docker_test.go b/app/discovery/provider/docker_test.go index e42f474..534e049 100644 --- a/app/discovery/provider/docker_test.go +++ b/app/discovery/provider/docker_test.go @@ -114,6 +114,27 @@ func TestDocker_ListWithAutoAPI(t *testing.T) { assert.Equal(t, "*", res[2].Server) } +func TestDocker_ListPriority(t *testing.T) { + dclient := &DockerClientMock{ + ListContainersFunc: func() ([]containerInfo, error) { + return []containerInfo{ + { + Name: "c0", State: "running", IP: "127.0.0.2", Ports: []int{12348}, + Labels: map[string]string{"reproxy.route": "^/whoami/(.*)", "reproxy.dest": "/$1", + "reproxy.server": "example.com", "reproxy.ping": "/ping", "reproxy.assets": "/:/assets/static1"}, + }, + }, nil + }, + } + + d := Docker{DockerClient: dclient} + res, err := d.List() + require.NoError(t, err) + require.Equal(t, 2, len(res)) + assert.Equal(t, discovery.MTProxy, res[0].MatchType) + assert.Equal(t, discovery.MTStatic, res[1].MatchType) +} + func TestDocker_refresh(t *testing.T) { containers := make(chan []containerInfo)