feat(docker): include full labels, mountpoints and image details

This commit is contained in:
yusing
2025-08-17 01:47:58 +08:00
parent 55018c8ab6
commit 07d6f36159
5 changed files with 28 additions and 12 deletions

View File

@@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"maps"
"net"
"net/url"
"strconv"
@@ -26,6 +27,8 @@ var (
)
func FromDocker(c *container.Summary, dockerHost string) (res *types.Container) {
actualLabels := maps.Clone(c.Labels)
_, isExplicit := c.Labels[LabelAliases]
helper := containerHelper{c}
if !isExplicit {
@@ -46,7 +49,8 @@ func FromDocker(c *container.Summary, dockerHost string) (res *types.Container)
ContainerName: helper.getName(),
ContainerID: c.ID,
Labels: c.Labels,
Labels: c.Labels,
ActualLabels: actualLabels,
Mounts: helper.getMounts(),
@@ -136,7 +140,7 @@ var databaseMPs = map[string]struct{}{
}
func isDatabase(c *types.Container) bool {
for _, m := range c.Mounts {
for _, m := range c.Mounts.Iter {
if _, ok := databaseMPs[m]; ok {
return true
}

View File

@@ -4,6 +4,7 @@ import (
"strings"
"github.com/docker/docker/api/types/container"
"github.com/yusing/ds/ordered"
"github.com/yusing/go-proxy/internal/types"
"github.com/yusing/go-proxy/internal/utils/strutils"
)
@@ -33,10 +34,10 @@ 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
func (c containerHelper) getMounts() *ordered.Map[string, string] {
m := ordered.NewMap[string, string](ordered.WithCapacity(len(c.Mounts)))
for _, v := range c.Mounts {
m.Set(v.Source, v.Destination)
}
return m
}
@@ -44,7 +45,11 @@ func (c containerHelper) getMounts() []string {
func (c containerHelper) parseImage() *types.ContainerImage {
colonSep := strutils.SplitRune(c.Image, ':')
slashSep := strutils.SplitRune(colonSep[0], '/')
im := new(types.ContainerImage)
_, sha256, _ := strings.Cut(c.ImageID, ":")
im := &types.ContainerImage{
SHA256: sha256,
Version: c.Labels["org.opencontainers.image.version"],
}
if len(slashSep) > 1 {
im.Author = strings.Join(slashSep[:len(slashSep)-1], "/")
im.Name = slashSep[len(slashSep)-1]