mirror of
https://github.com/yusing/godoxy.git
synced 2025-06-09 13:02:33 +02:00
bring back database check
This commit is contained in:
parent
1d16d514c7
commit
9925b042d8
2 changed files with 39 additions and 1 deletions
|
@ -27,6 +27,8 @@ type (
|
||||||
|
|
||||||
Labels map[string]string `json:"-"`
|
Labels map[string]string `json:"-"`
|
||||||
|
|
||||||
|
Mounts []string `json:"mounts"`
|
||||||
|
|
||||||
PublicPortMapping PortMapping `json:"public_ports"` // non-zero publicPort:types.Port
|
PublicPortMapping PortMapping `json:"public_ports"` // non-zero publicPort:types.Port
|
||||||
PrivatePortMapping PortMapping `json:"private_ports"` // privatePort:types.Port
|
PrivatePortMapping PortMapping `json:"private_ports"` // privatePort:types.Port
|
||||||
PublicHostname string `json:"public_hostname"`
|
PublicHostname string `json:"public_hostname"`
|
||||||
|
@ -70,6 +72,8 @@ func FromDocker(c *container.Summary, dockerHost string) (res *Container) {
|
||||||
|
|
||||||
Labels: c.Labels,
|
Labels: c.Labels,
|
||||||
|
|
||||||
|
Mounts: helper.getMounts(),
|
||||||
|
|
||||||
PublicPortMapping: helper.getPublicPortMapping(),
|
PublicPortMapping: helper.getPublicPortMapping(),
|
||||||
PrivatePortMapping: helper.getPrivatePortMapping(),
|
PrivatePortMapping: helper.getPrivatePortMapping(),
|
||||||
|
|
||||||
|
@ -133,8 +137,34 @@ func FromInspectResponse(json container.InspectResponse, dockerHost string) *Con
|
||||||
return cont
|
return cont
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var databaseMPs = map[string]struct{}{
|
||||||
|
"/var/lib/postgresql/data": {},
|
||||||
|
"/var/lib/mysql": {},
|
||||||
|
"/var/lib/mongodb": {},
|
||||||
|
"/var/lib/mariadb": {},
|
||||||
|
"/var/lib/memcached": {},
|
||||||
|
"/var/lib/rabbitmq": {},
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Container) isDatabase() bool {
|
||||||
|
for _, m := range c.Mounts {
|
||||||
|
if _, ok := databaseMPs[m]; ok {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, v := range c.PrivatePortMapping {
|
||||||
|
switch v.PrivatePort {
|
||||||
|
// postgres, mysql or mariadb, redis, memcached, mongodb
|
||||||
|
case 5432, 3306, 6379, 11211, 27017:
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Container) IsBlacklisted() bool {
|
func (c *Container) IsBlacklisted() bool {
|
||||||
return c.Image.IsBlacklisted()
|
return c.Image.IsBlacklisted() || c.isDatabase()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Container) setPublicHostname() {
|
func (c *Container) setPublicHostname() {
|
||||||
|
|
|
@ -32,6 +32,14 @@ func (c containerHelper) getName() string {
|
||||||
return strings.TrimPrefix(c.Names[0], "/")
|
return strings.TrimPrefix(c.Names[0], "/")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c containerHelper) getMounts() []string {
|
||||||
|
m := make([]string, len(c.Mounts))
|
||||||
|
for i, v := range c.Mounts {
|
||||||
|
m[i] = v.Destination
|
||||||
|
}
|
||||||
|
return m
|
||||||
|
}
|
||||||
|
|
||||||
func (c containerHelper) parseImage() *ContainerImage {
|
func (c containerHelper) parseImage() *ContainerImage {
|
||||||
colonSep := strutils.SplitRune(c.Image, ':')
|
colonSep := strutils.SplitRune(c.Image, ':')
|
||||||
slashSep := strutils.SplitRune(colonSep[0], '/')
|
slashSep := strutils.SplitRune(colonSep[0], '/')
|
||||||
|
|
Loading…
Add table
Reference in a new issue