Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (
github.com/crazy-max/gohealthchecks v0.5.0
github.com/crazy-max/gonfig v0.7.1
github.com/distribution/reference v0.6.0
github.com/docker/docker v27.3.1+incompatible
github.com/docker/docker v28.3.3+incompatible
github.com/docker/go-connections v0.5.0
github.com/docker/go-units v0.5.0
github.com/dromara/carbon/v2 v2.6.11
Expand Down Expand Up @@ -63,6 +63,8 @@ require (
github.com/andybalholm/cascadia v1.3.2 // indirect
github.com/aokoli/goutils v1.0.1 // indirect
github.com/aymerick/douceur v0.2.0 // indirect
github.com/containerd/errdefs v0.3.0 // indirect
github.com/containerd/errdefs/pkg v0.3.0 // indirect
github.com/containerd/log v0.1.0 // indirect
github.com/containerd/typeurl/v2 v2.2.0 // indirect
github.com/containers/libtrust v0.0.0-20230121012942-c1716e8a8d01 // indirect
Expand Down Expand Up @@ -113,6 +115,7 @@ require (
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/moby/docker-image-spec v1.3.1 // indirect
github.com/moby/sys/atomicwriter v0.1.0 // indirect
github.com/moby/sys/capability v0.3.0 // indirect
github.com/moby/sys/mountinfo v0.7.2 // indirect
github.com/moby/sys/user v0.3.0 // indirect
Expand Down
12 changes: 10 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5P
github.com/chzyer/readline v1.5.1/go.mod h1:Eh+b79XXUwfKfcPLepksvw2tcLE/Ct21YObkaSkeBlk=
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
github.com/chzyer/test v1.0.0/go.mod h1:2JlltgoNkt4TW/z9V/IzDdFaMTM2JPIi26O1pF38GC8=
github.com/containerd/errdefs v0.3.0 h1:FSZgGOeK4yuT/+DnF07/Olde/q4KBoMsaamhXxIMDp4=
github.com/containerd/errdefs v0.3.0/go.mod h1:+YBYIdtsnF4Iw6nWZhJcqGSg/dwvV7tyJ/kCkyJ2k+M=
github.com/containerd/errdefs/pkg v0.3.0 h1:9IKJ06FvyNlexW690DXuQNx2KA2cUJXx151Xdx3ZPPE=
github.com/containerd/errdefs/pkg v0.3.0/go.mod h1:NJw6s9HwNuRhnjJhM7pylWwMyAkmCQvQ4GpJHEqRLVk=
github.com/containerd/log v0.1.0 h1:TCJt7ioM2cr/tfR8GPbGf9/VRAX8D2B4PjzCpfX540I=
github.com/containerd/log v0.1.0/go.mod h1:VRRf09a7mHDIRezVKTRCrOq78v577GXq3bSa3EhrzVo=
github.com/containerd/platforms v0.2.1 h1:zvwtM3rz2YHPQsF2CHYM8+KtB5dvhISiXh5ZpSBQv6A=
Expand Down Expand Up @@ -86,8 +90,8 @@ github.com/docker/cli v27.3.1+incompatible h1:qEGdFBF3Xu6SCvCYhc7CzaQTlBmqDuzxPD
github.com/docker/cli v27.3.1+incompatible/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8=
github.com/docker/distribution v2.8.3+incompatible h1:AtKxIZ36LoNK51+Z6RpzLpddBirtxJnzDrHLEKxTAYk=
github.com/docker/distribution v2.8.3+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
github.com/docker/docker v27.3.1+incompatible h1:KttF0XoteNTicmUtBO0L2tP+J7FGRFTjaEF4k6WdhfI=
github.com/docker/docker v27.3.1+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/docker/docker v28.3.3+incompatible h1:Dypm25kh4rmk49v1eiVbsAtpAsYURjYkaKubwuBdxEI=
github.com/docker/docker v28.3.3+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/docker/docker-credential-helpers v0.8.2 h1:bX3YxiGzFP5sOXWc3bTPEXdEaZSeVMrFgOr3T+zrFAo=
github.com/docker/docker-credential-helpers v0.8.2/go.mod h1:P3ci7E3lwkZg6XiHdRKft1KckHiO9a2rNtyFbZ/ry9M=
github.com/docker/go-connections v0.5.0 h1:USnMq7hx7gwdVZq1L49hLXaFtUdTADjXGp+uj1Br63c=
Expand Down Expand Up @@ -248,10 +252,14 @@ github.com/moby/buildkit v0.17.3 h1:XN8ddC5gO1kGJJfi86kzvDlPOyLyPk66hTvswqhj6NQ=
github.com/moby/buildkit v0.17.3/go.mod h1:vr5vltV8wt4F2jThbNOChfbAklJ0DOW11w36v210hOg=
github.com/moby/docker-image-spec v1.3.1 h1:jMKff3w6PgbfSa69GfNg+zN/XLhfXJGnEx3Nl2EsFP0=
github.com/moby/docker-image-spec v1.3.1/go.mod h1:eKmb5VW8vQEh/BAr2yvVNvuiJuY6UIocYsFu/DxxRpo=
github.com/moby/sys/atomicwriter v0.1.0 h1:kw5D/EqkBwsBFi0ss9v1VG3wIkVhzGvLklJ+w3A14Sw=
github.com/moby/sys/atomicwriter v0.1.0/go.mod h1:Ul8oqv2ZMNHOceF643P6FKPXeCmYtlQMvpizfsSoaWs=
github.com/moby/sys/capability v0.3.0 h1:kEP+y6te0gEXIaeQhIi0s7vKs/w0RPoH1qPa6jROcVg=
github.com/moby/sys/capability v0.3.0/go.mod h1:4g9IK291rVkms3LKCDOoYlnV8xKwoDTpIrNEE35Wq0I=
github.com/moby/sys/mountinfo v0.7.2 h1:1shs6aH5s4o5H2zQLn796ADW1wMrIwHsyJ2v9KouLrg=
github.com/moby/sys/mountinfo v0.7.2/go.mod h1:1YOa8w8Ih7uW0wALDUgT1dTTSBrZ+HiBLGws92L2RU4=
github.com/moby/sys/sequential v0.6.0 h1:qrx7XFUd/5DxtqcoH1h438hF5TmOvzC/lspjy7zgvCU=
github.com/moby/sys/sequential v0.6.0/go.mod h1:uyv8EUTrca5PnDsdMGXhZe6CCe8U/UiTWd+lL+7b/Ko=
github.com/moby/sys/user v0.3.0 h1:9ni5DlcW5an3SvRSx4MouotOygvzaXbaSrc/wGDFWPo=
github.com/moby/sys/user v0.3.0/go.mod h1:bG+tYYYJgaMtRKgEmuueC0hJEAZWwtIbZTB+85uoHjs=
github.com/moby/term v0.5.0 h1:xt8Q1nalod/v7BqbG21f8mQPqH+xAaC9C3N3wfWbVP0=
Expand Down
18 changes: 9 additions & 9 deletions internal/provider/docker/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/crazy-max/diun/v4/internal/model"
"github.com/crazy-max/diun/v4/internal/provider"
"github.com/crazy-max/diun/v4/pkg/docker"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/filters"
"github.com/docker/go-units"
)
Expand Down Expand Up @@ -43,7 +43,7 @@ func (c *Client) listContainerImage() []model.Image {
var list []model.Image
for _, ctn := range ctns {
imageName := ctn.Image
imageRaw, err := cli.ImageInspectWithRaw(imageName)
imageInfo, err := cli.ImageInspect(imageName)
if err != nil {
c.logger.Error().Err(err).
Str("ctn_id", ctn.ID).
Expand All @@ -52,15 +52,15 @@ func (c *Client) listContainerImage() []model.Image {
continue
}

if local := cli.IsLocalImage(imageRaw); local {
if local := cli.IsLocalImage(imageInfo); local {
c.logger.Debug().
Str("ctn_id", ctn.ID).
Str("ctn_image", imageName).
Msg("Skip locally built image")
continue
}

if dangling := cli.IsDanglingImage(imageRaw); dangling {
if dangling := cli.IsDanglingImage(imageInfo); dangling {
c.logger.Debug().
Str("ctn_id", ctn.ID).
Str("ctn_image", imageName).
Expand All @@ -69,18 +69,18 @@ func (c *Client) listContainerImage() []model.Image {
}

if cli.IsDigest(imageName) {
if len(imageRaw.RepoDigests) > 0 {
if len(imageInfo.RepoDigests) > 0 {
c.logger.Debug().
Str("ctn_id", ctn.ID).
Str("ctn_image", imageName).
Strs("img_repodigests", imageRaw.RepoDigests).
Strs("img_repodigests", imageInfo.RepoDigests).
Msg("Using first image repo digest available as image name")
imageName = imageRaw.RepoDigests[0]
imageName = imageInfo.RepoDigests[0]
} else {
c.logger.Debug().
Str("ctn_id", ctn.ID).
Str("ctn_image", imageName).
Strs("img_repodigests", imageRaw.RepoDigests).
Strs("img_repodigests", imageInfo.RepoDigests).
Msg("Skip unknown image digest ref")
continue
}
Expand Down Expand Up @@ -115,7 +115,7 @@ func (c *Client) listContainerImage() []model.Image {
return list
}

func metadata(ctn types.Container) map[string]string {
func metadata(ctn container.Summary) map[string]string {
return map[string]string{
"ctn_id": ctn.ID,
"ctn_names": formatNames(ctn.Names),
Expand Down
3 changes: 1 addition & 2 deletions pkg/docker/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ package docker
import (
"sort"

"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/filters"
)

// ContainerList returns Docker containers
func (c *Client) ContainerList(filterArgs filters.Args) ([]types.Container, error) {
func (c *Client) ContainerList(filterArgs filters.Args) ([]container.Summary, error) {
containers, err := c.API.ContainerList(c.ctx, container.ListOptions{
Filters: filterArgs,
})
Expand Down
16 changes: 8 additions & 8 deletions pkg/docker/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package docker
import (
"regexp"

"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/image"
)

// ContainerInspect returns the container information.
func (c *Client) ContainerInspect(containerID string) (types.ContainerJSON, error) {
func (c *Client) ContainerInspect(containerID string) (container.InspectResponse, error) {
return c.API.ContainerInspect(c.ctx, containerID)
}

Expand All @@ -16,20 +17,19 @@ func (c *Client) IsDigest(imageID string) bool {
return regexp.MustCompile(`^(@|sha256:|@sha256:)([0-9a-f]{64})$`).MatchString(imageID)
}

// ImageInspectWithRaw returns the image information and its raw representation.
func (c *Client) ImageInspectWithRaw(imageID string) (types.ImageInspect, error) {
imageRaw, _, err := c.API.ImageInspectWithRaw(c.ctx, imageID)
return imageRaw, err
// ImageInspect returns the image information.
func (c *Client) ImageInspect(imageID string) (image.InspectResponse, error) {
return c.API.ImageInspect(c.ctx, imageID)
}

// IsLocalImage checks if the image has been built locally
func (c *Client) IsLocalImage(image types.ImageInspect) bool {
func (c *Client) IsLocalImage(image image.InspectResponse) bool {
return len(image.RepoDigests) == 0
}

// IsDanglingImage returns whether the given image is "dangling" which means
// that there are no repository references to the given image and it has no
// child images
func (c *Client) IsDanglingImage(image types.ImageInspect) bool {
func (c *Client) IsDanglingImage(image image.InspectResponse) bool {
return len(image.RepoTags) == 1 && image.RepoTags[0] == "<none>:<none>" && len(image.RepoDigests) == 1 && image.RepoDigests[0] == "<none>@<none>"
}
3 changes: 1 addition & 2 deletions pkg/docker/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ package docker
import (
"sort"

"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/api/types/swarm"
)

// ServiceList returns Swarm services
func (c *Client) ServiceList(filterArgs filters.Args) ([]swarm.Service, error) {
services, err := c.API.ServiceList(c.ctx, types.ServiceListOptions{
services, err := c.API.ServiceList(c.ctx, swarm.ServiceListOptions{
Filters: filterArgs,
})
if err != nil {
Expand Down
Loading