2019-02-17 23:40:22 -06:00
|
|
|
package container
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/docker/docker/api/types"
|
|
|
|
"github.com/docker/docker/api/types/filters"
|
|
|
|
)
|
|
|
|
|
|
|
|
// ImageExistsLocally returns a boolean indicating if an image with the
|
|
|
|
// requested name (and tag) exist in the local docker image store
|
|
|
|
func ImageExistsLocally(ctx context.Context, imageName string) (bool, error) {
|
2020-05-03 23:15:42 -05:00
|
|
|
cli, err := GetDockerClient(ctx)
|
2019-02-17 23:40:22 -06:00
|
|
|
if err != nil {
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
|
|
|
|
filters := filters.NewArgs()
|
|
|
|
filters.Add("reference", imageName)
|
|
|
|
|
|
|
|
imageListOptions := types.ImageListOptions{
|
|
|
|
Filters: filters,
|
|
|
|
}
|
|
|
|
|
|
|
|
images, err := cli.ImageList(ctx, imageListOptions)
|
|
|
|
if err != nil {
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return len(images) > 0, nil
|
|
|
|
}
|