NormalizePlatform normalizes (according to the OCI spec) the specified os, arch and variant. If left empty, the individual item will not be normalized.
(rawOS, rawArch, rawVariant string)
| 13 | // NormalizePlatform normalizes (according to the OCI spec) the specified os, |
| 14 | // arch and variant. If left empty, the individual item will not be normalized. |
| 15 | func NormalizePlatform(rawOS, rawArch, rawVariant string) (os, arch, variant string) { |
| 16 | os, arch, variant = rawOS, rawArch, rawVariant |
| 17 | if os == "" { |
| 18 | os = runtime.GOOS |
| 19 | } |
| 20 | if arch == "" { |
| 21 | arch = runtime.GOARCH |
| 22 | } |
| 23 | rawPlatform := os + "/" + arch |
| 24 | if variant != "" { |
| 25 | rawPlatform += "/" + variant |
| 26 | } |
| 27 | |
| 28 | normalizedPlatform, err := platforms.Parse(rawPlatform) |
| 29 | if err != nil { |
| 30 | logrus.Debugf("Error normalizing platform: %v", err) |
| 31 | return rawOS, rawArch, rawVariant |
| 32 | } |
| 33 | logrus.Debugf("Normalized platform %s to %s", rawPlatform, normalizedPlatform) |
| 34 | os = rawOS |
| 35 | if rawOS != "" { |
| 36 | os = normalizedPlatform.OS |
| 37 | } |
| 38 | arch = rawArch |
| 39 | if rawArch != "" { |
| 40 | arch = normalizedPlatform.Architecture |
| 41 | } |
| 42 | variant = rawVariant |
| 43 | if rawVariant != "" { |
| 44 | variant = normalizedPlatform.Variant |
| 45 | } |
| 46 | return os, arch, variant |
| 47 | } |
| 48 | |
| 49 | // NormalizeName normalizes the provided name according to the conventions by |
| 50 | // Podman and Buildah. If tag and digest are missing, the "latest" tag will be |
searching dependent graphs…