moby: check architecture for docker image

under certain cases the container image is already in the local docker
registry, but with the wrong architecture; in this case just pretend
it is not there and let the caller decide if they want to build it

Signed-off-by: Christoph Ostarek <christoph@zededa.com>
This commit is contained in:
Christoph Ostarek 2024-08-27 15:49:17 +02:00
parent 5f09346e1e
commit cb8f36adf3
2 changed files with 10 additions and 3 deletions

View File

@ -3,6 +3,7 @@ package docker
import (
"context"
"errors"
"fmt"
"io"
"os"
"sync"
@ -51,13 +52,19 @@ func createClient() (*client.Client, error) {
}
// HasImage check if the provided ref is available in the docker cache.
func HasImage(ref *reference.Spec) error {
func HasImage(ref *reference.Spec, architecture string) error {
log.Debugf("docker inspect image: %s", ref)
cli, err := Client()
if err != nil {
return err
}
_, err = InspectImage(cli, ref)
imageInspect, err := InspectImage(cli, ref)
if err != nil {
return err
}
if imageInspect.Architecture != "" && imageInspect.Architecture != architecture {
return fmt.Errorf("image not found for right architecture (%s != %s)", imageInspect.Architecture, architecture)
}
return err
}

View File

@ -18,7 +18,7 @@ func imagePull(ref *reference.Spec, alwaysPull bool, cacheDir string, dockerCach
// - !alwaysPull && !dockerCache: try linuxkit cache, then try to pull from registry, then fail
// first, try docker, if that is available
if !alwaysPull && dockerCache {
if err := docker.HasImage(ref); err == nil {
if err := docker.HasImage(ref, architecture); err == nil {
return docker.NewSource(ref), nil
}
// docker is not required, so any error - image not available, no docker, whatever - just gets ignored