* build(deps): bump the dependencies group with 6 updates Bumps the dependencies group with 6 updates: | Package | From | To | | --- | --- | --- | | [github.com/docker/cli](https://github.com/docker/cli) | `27.5.1+incompatible` | `28.0.0+incompatible` | | [github.com/docker/docker](https://github.com/docker/docker) | `27.4.1+incompatible` | `28.0.0+incompatible` | | [github.com/go-git/go-billy/v5](https://github.com/go-git/go-billy) | `5.6.1` | `5.6.2` | | [github.com/go-git/go-git/v5](https://github.com/go-git/go-git) | `5.13.1` | `5.13.2` | | [golang.org/x/term](https://github.com/golang/term) | `0.28.0` | `0.29.0` | | google.golang.org/protobuf | `1.36.4` | `1.36.5` | Updates `github.com/docker/cli` from 27.5.1+incompatible to 28.0.0+incompatible - [Commits](https://github.com/docker/cli/compare/v27.5.1...v28.0.0) Updates `github.com/docker/docker` from 27.4.1+incompatible to 28.0.0+incompatible - [Release notes](https://github.com/docker/docker/releases) - [Commits](https://github.com/docker/docker/compare/v27.4.1...v28.0.0) Updates `github.com/go-git/go-billy/v5` from 5.6.1 to 5.6.2 - [Release notes](https://github.com/go-git/go-billy/releases) - [Commits](https://github.com/go-git/go-billy/compare/v5.6.1...v5.6.2) Updates `github.com/go-git/go-git/v5` from 5.13.1 to 5.13.2 - [Release notes](https://github.com/go-git/go-git/releases) - [Commits](https://github.com/go-git/go-git/compare/v5.13.1...v5.13.2) Updates `golang.org/x/term` from 0.28.0 to 0.29.0 - [Commits](https://github.com/golang/term/compare/v0.28.0...v0.29.0) Updates `google.golang.org/protobuf` from 1.36.4 to 1.36.5 --- updated-dependencies: - dependency-name: github.com/docker/cli dependency-type: direct:production update-type: version-update:semver-major dependency-group: dependencies - dependency-name: github.com/docker/docker dependency-type: direct:production update-type: version-update:semver-major dependency-group: dependencies - dependency-name: github.com/go-git/go-billy/v5 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: dependencies - dependency-name: github.com/go-git/go-git/v5 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: dependencies - dependency-name: golang.org/x/term dependency-type: direct:production update-type: version-update:semver-minor dependency-group: dependencies - dependency-name: google.golang.org/protobuf dependency-type: direct:production update-type: version-update:semver-patch dependency-group: dependencies ... Signed-off-by: dependabot[bot] <support@github.com> * Migrate docker pkg to next release --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: ChristopherHX <christopher.homberger@web.de> Co-authored-by: Casey Lee <cplee@nektos.com>
61 lines
1.5 KiB
Go
61 lines
1.5 KiB
Go
//go:build !(WITHOUT_DOCKER || !(linux || darwin || windows || netbsd))
|
|
|
|
package container
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/docker/docker/api/types/image"
|
|
"github.com/docker/docker/client"
|
|
)
|
|
|
|
// ImageExistsLocally returns a boolean indicating if an image with the
|
|
// requested name, tag and architecture exists in the local docker image store
|
|
func ImageExistsLocally(ctx context.Context, imageName string, platform string) (bool, error) {
|
|
cli, err := GetDockerClient(ctx)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
defer cli.Close()
|
|
|
|
inspectImage, err := cli.ImageInspect(ctx, imageName)
|
|
if client.IsErrNotFound(err) {
|
|
return false, nil
|
|
} else if err != nil {
|
|
return false, err
|
|
}
|
|
|
|
if platform == "" || platform == "any" || fmt.Sprintf("%s/%s", inspectImage.Os, inspectImage.Architecture) == platform {
|
|
return true, nil
|
|
}
|
|
|
|
return false, nil
|
|
}
|
|
|
|
// RemoveImage removes image from local store, the function is used to run different
|
|
// container image architectures
|
|
func RemoveImage(ctx context.Context, imageName string, force bool, pruneChildren bool) (bool, error) {
|
|
cli, err := GetDockerClient(ctx)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
defer cli.Close()
|
|
|
|
inspectImage, err := cli.ImageInspect(ctx, imageName)
|
|
if client.IsErrNotFound(err) {
|
|
return false, nil
|
|
} else if err != nil {
|
|
return false, err
|
|
}
|
|
|
|
if _, err = cli.ImageRemove(ctx, inspectImage.ID, image.RemoveOptions{
|
|
Force: force,
|
|
PruneChildren: pruneChildren,
|
|
}); err != nil {
|
|
return false, err
|
|
}
|
|
|
|
return true, nil
|
|
}
|