From 9c3edff92b9d8970f84f247b957e863cffc97dc8 Mon Sep 17 00:00:00 2001 From: yusing Date: Fri, 4 Oct 2024 09:17:45 +0800 Subject: [PATCH] databases without explicit alias(es) are now excluded by default --- internal/config/query.go | 3 --- internal/docker/container.go | 33 +++++++++++++++++++++++++++++ internal/docker/proxy_properties.go | 1 + internal/proxy/provider/docker.go | 1 + 4 files changed, 35 insertions(+), 3 deletions(-) diff --git a/internal/config/query.go b/internal/config/query.go index 2187470e..17741501 100644 --- a/internal/config/query.go +++ b/internal/config/query.go @@ -4,7 +4,6 @@ import ( "fmt" "strings" - "github.com/sirupsen/logrus" "github.com/yusing/go-proxy/internal/common" H "github.com/yusing/go-proxy/internal/homepage" PR "github.com/yusing/go-proxy/internal/proxy/provider" @@ -55,8 +54,6 @@ func (cfg *Config) HomepageConfig() H.HomePageConfig { } } - logrus.Debugf("%s isexplicit: %v, explicitonly: %v", r, r.Entry().IsExplicit, p.IsExplicitOnly()) - item := entry.Homepage if !item.Show && !item.IsEmpty() { diff --git a/internal/docker/container.go b/internal/docker/container.go index 04a83f4d..f670f067 100644 --- a/internal/docker/container.go +++ b/internal/docker/container.go @@ -28,6 +28,7 @@ func FromDocker(c *types.Container, dockerHost string) (res Container) { Aliases: res.getAliases(), IsExcluded: U.ParseBool(res.getDeleteLabel(LabelExclude)), IsExplicit: isExplicit, + IsDatabase: res.isDatabase(), IdleTimeout: res.getDeleteLabel(LabelIdleTimeout), WakeTimeout: res.getDeleteLabel(LabelWakeTimeout), StopMethod: res.getDeleteLabel(LabelStopMethod), @@ -108,3 +109,35 @@ func (c Container) getPrivatePortMapping() PortMapping { } return res } + +var databaseMPs = map[string]struct{}{ + "/var/lib/postgresql/data": {}, + "/var/lib/mysql": {}, + "/var/lib/mongodb": {}, + "/var/lib/mariadb": {}, + "/var/lib/memcached": {}, + "/var/lib/rabbitmq": {}, +} + +var databasePrivPorts = map[uint16]struct{}{ + 5432: {}, // postgres + 3306: {}, // mysql, mariadb + 6379: {}, // redis + 11211: {}, // memcached + 27017: {}, // mongodb +} + +func (c Container) isDatabase() bool { + for _, m := range c.Container.Mounts { + if _, ok := databaseMPs[m.Destination]; ok { + return true + } + } + + for _, v := range c.Ports { + if _, ok := databasePrivPorts[v.PrivatePort]; ok { + return true + } + } + return false +} diff --git a/internal/docker/proxy_properties.go b/internal/docker/proxy_properties.go index d86b4996..3dc20559 100644 --- a/internal/docker/proxy_properties.go +++ b/internal/docker/proxy_properties.go @@ -15,6 +15,7 @@ type ProxyProperties struct { Aliases []string `yaml:"-" json:"aliases"` IsExcluded bool `yaml:"-" json:"is_excluded"` IsExplicit bool `yaml:"-" json:"is_explicit"` + IsDatabase bool `yaml:"-" json:"is_database"` IdleTimeout string `yaml:"-" json:"idle_timeout"` WakeTimeout string `yaml:"-" json:"wake_timeout"` StopMethod string `yaml:"-" json:"stop_method"` diff --git a/internal/proxy/provider/docker.go b/internal/proxy/provider/docker.go index 0a2586c7..35aa909b 100755 --- a/internal/proxy/provider/docker.go +++ b/internal/proxy/provider/docker.go @@ -83,6 +83,7 @@ func (p *DockerProvider) LoadRoutesImpl() (routes R.Routes, err E.NestedError) { func (p *DockerProvider) shouldIgnore(container D.Container) bool { return container.IsExcluded || !container.IsExplicit && p.ExplicitOnly || + !container.IsExplicit && container.IsDatabase || strings.HasSuffix(container.ContainerName, "-old") }