ImageExistsLocally returns a boolean indicating if an image with the requested name, tag and architecture exists in the local docker image store
(ctx context.Context, imageName string, platform string)
| 14 | // ImageExistsLocally returns a boolean indicating if an image with the |
| 15 | // requested name, tag and architecture exists in the local docker image store |
| 16 | func ImageExistsLocally(ctx context.Context, imageName string, platform string) (bool, error) { |
| 17 | cli, err := GetDockerClient(ctx) |
| 18 | if err != nil { |
| 19 | return false, err |
| 20 | } |
| 21 | defer cli.Close() |
| 22 | |
| 23 | inspectImage, err := cli.ImageInspect(ctx, imageName) |
| 24 | if cerrdefs.IsNotFound(err) { |
| 25 | return false, nil |
| 26 | } else if err != nil { |
| 27 | return false, err |
| 28 | } |
| 29 | |
| 30 | imagePlatform := fmt.Sprintf("%s/%s", inspectImage.Os, inspectImage.Architecture) |
| 31 | |
| 32 | if platform == "" || platform == "any" || imagePlatform == platform { |
| 33 | return true, nil |
| 34 | } |
| 35 | |
| 36 | logger := common.Logger(ctx) |
| 37 | logger.Infof("image found but platform does not match: %s (image) != %s (platform)\n", imagePlatform, platform) |
| 38 | |
| 39 | return false, nil |
| 40 | } |
| 41 | |
| 42 | // RemoveImage removes image from local store, the function is used to run different |
| 43 | // container image architectures |
no test coverage detected
searching dependent graphs…