Skip to content

Commit

Permalink
bring back database check
Browse files Browse the repository at this point in the history
  • Loading branch information
yusing committed Feb 24, 2025
1 parent 1d16d51 commit 9925b04
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
32 changes: 31 additions & 1 deletion internal/docker/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ type (

Labels map[string]string `json:"-"`

Mounts []string `json:"mounts"`

PublicPortMapping PortMapping `json:"public_ports"` // non-zero publicPort:types.Port
PrivatePortMapping PortMapping `json:"private_ports"` // privatePort:types.Port
PublicHostname string `json:"public_hostname"`
Expand Down Expand Up @@ -70,6 +72,8 @@ func FromDocker(c *container.Summary, dockerHost string) (res *Container) {

Labels: c.Labels,

Mounts: helper.getMounts(),

PublicPortMapping: helper.getPublicPortMapping(),
PrivatePortMapping: helper.getPrivatePortMapping(),

Expand Down Expand Up @@ -133,8 +137,34 @@ func FromInspectResponse(json container.InspectResponse, dockerHost string) *Con
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 {
return c.Image.IsBlacklisted()
return c.Image.IsBlacklisted() || c.isDatabase()
}

func (c *Container) setPublicHostname() {
Expand Down
8 changes: 8 additions & 0 deletions internal/docker/container_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ func (c containerHelper) getName() string {
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 {
colonSep := strutils.SplitRune(c.Image, ':')
slashSep := strutils.SplitRune(colonSep[0], '/')
Expand Down

0 comments on commit 9925b04

Please sign in to comment.