Merge pull request #4072 from christoph-zededa/docker_cache_consider_architecture

moby: check architecture for docker image
This commit is contained in:
Avi Deitcher 2024-08-29 22:15:19 +03:00 committed by GitHub
commit fa3207c86e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 3 deletions

View File

@ -3,6 +3,7 @@ package docker
import ( import (
"context" "context"
"errors" "errors"
"fmt"
"io" "io"
"os" "os"
"sync" "sync"
@ -51,13 +52,19 @@ func createClient() (*client.Client, error) {
} }
// HasImage check if the provided ref is available in the docker cache. // 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) log.Debugf("docker inspect image: %s", ref)
cli, err := Client() cli, err := Client()
if err != nil { if err != nil {
return err 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 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 // - !alwaysPull && !dockerCache: try linuxkit cache, then try to pull from registry, then fail
// first, try docker, if that is available // first, try docker, if that is available
if !alwaysPull && dockerCache { if !alwaysPull && dockerCache {
if err := docker.HasImage(ref); err == nil { if err := docker.HasImage(ref, architecture); err == nil {
return docker.NewSource(ref), nil return docker.NewSource(ref), nil
} }
// docker is not required, so any error - image not available, no docker, whatever - just gets ignored // docker is not required, so any error - image not available, no docker, whatever - just gets ignored