github.com/justincormack/cli@v0.0.0-20201215022714-831ebeae9675/cli/command/manifest/util.go (about) 1 package manifest 2 3 import ( 4 "context" 5 6 "github.com/docker/cli/cli/command" 7 "github.com/docker/cli/cli/manifest/store" 8 "github.com/docker/cli/cli/manifest/types" 9 "github.com/docker/distribution/reference" 10 ) 11 12 type osArch struct { 13 os string 14 arch string 15 } 16 17 // Remove any unsupported os/arch combo 18 // list of valid os/arch values (see "Optional Environment Variables" section 19 // of https://golang.org/doc/install/source 20 // Added linux/s390x as we know System z support already exists 21 // Keep in sync with _docker_manifest_annotate in contrib/completion/bash/docker 22 var validOSArches = map[osArch]bool{ 23 {os: "darwin", arch: "386"}: true, 24 {os: "darwin", arch: "amd64"}: true, 25 {os: "darwin", arch: "arm"}: true, 26 {os: "darwin", arch: "arm64"}: true, 27 {os: "dragonfly", arch: "amd64"}: true, 28 {os: "freebsd", arch: "386"}: true, 29 {os: "freebsd", arch: "amd64"}: true, 30 {os: "freebsd", arch: "arm"}: true, 31 {os: "linux", arch: "386"}: true, 32 {os: "linux", arch: "amd64"}: true, 33 {os: "linux", arch: "arm"}: true, 34 {os: "linux", arch: "arm64"}: true, 35 {os: "linux", arch: "ppc64le"}: true, 36 {os: "linux", arch: "mips64"}: true, 37 {os: "linux", arch: "mips64le"}: true, 38 {os: "linux", arch: "riscv64"}: true, 39 {os: "linux", arch: "s390x"}: true, 40 {os: "netbsd", arch: "386"}: true, 41 {os: "netbsd", arch: "amd64"}: true, 42 {os: "netbsd", arch: "arm"}: true, 43 {os: "openbsd", arch: "386"}: true, 44 {os: "openbsd", arch: "amd64"}: true, 45 {os: "openbsd", arch: "arm"}: true, 46 {os: "plan9", arch: "386"}: true, 47 {os: "plan9", arch: "amd64"}: true, 48 {os: "solaris", arch: "amd64"}: true, 49 {os: "windows", arch: "386"}: true, 50 {os: "windows", arch: "amd64"}: true, 51 } 52 53 func isValidOSArch(os string, arch string) bool { 54 // check for existence of this combo 55 _, ok := validOSArches[osArch{os, arch}] 56 return ok 57 } 58 59 func normalizeReference(ref string) (reference.Named, error) { 60 namedRef, err := reference.ParseNormalizedNamed(ref) 61 if err != nil { 62 return nil, err 63 } 64 if _, isDigested := namedRef.(reference.Canonical); !isDigested { 65 return reference.TagNameOnly(namedRef), nil 66 } 67 return namedRef, nil 68 } 69 70 // getManifest from the local store, and fallback to the remote registry if it 71 // doesn't exist locally 72 func getManifest(ctx context.Context, dockerCli command.Cli, listRef, namedRef reference.Named, insecure bool) (types.ImageManifest, error) { 73 data, err := dockerCli.ManifestStore().Get(listRef, namedRef) 74 switch { 75 case store.IsNotFound(err): 76 return dockerCli.RegistryClient(insecure).GetManifest(ctx, namedRef) 77 case err != nil: 78 return types.ImageManifest{}, err 79 default: 80 return data, nil 81 } 82 }