-
Notifications
You must be signed in to change notification settings - Fork 203
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move platform code to its own directory
Move the platform code into its own directory under libimage so it can be used by farm build in podman without causing the binary size to increase a lot. Signed-off-by: Urvashi Mohnani <[email protected]>
- Loading branch information
Showing
8 changed files
with
114 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package define | ||
|
||
// PlatformPolicy controls the behavior of image-platform matching. | ||
type PlatformPolicy int | ||
|
||
const ( | ||
// Only debug log if an image does not match the expected platform. | ||
PlatformPolicyDefault PlatformPolicy = iota | ||
// Warn if an image does not match the expected platform. | ||
PlatformPolicyWarn | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package platform | ||
|
||
import ( | ||
"fmt" | ||
"runtime" | ||
|
||
"github.com/containerd/containerd/platforms" | ||
v1 "github.com/opencontainers/image-spec/specs-go/v1" | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
// Normalize normalizes (according to the OCI spec) the specified os, | ||
// arch and variant. If left empty, the individual item will be normalized. | ||
func Normalize(rawOS, rawArch, rawVariant string) (os, arch, variant string) { | ||
platformSpec := v1.Platform{ | ||
OS: rawOS, | ||
Architecture: rawArch, | ||
Variant: rawVariant, | ||
} | ||
normalizedSpec := platforms.Normalize(platformSpec) | ||
if normalizedSpec.Variant == "" && rawVariant != "" { | ||
normalizedSpec.Variant = rawVariant | ||
} | ||
rawPlatform := ToString(normalizedSpec.OS, normalizedSpec.Architecture, normalizedSpec.Variant) | ||
normalizedPlatform, err := platforms.Parse(rawPlatform) | ||
if err != nil { | ||
logrus.Debugf("Error normalizing platform: %v", err) | ||
return rawOS, rawArch, rawVariant | ||
} | ||
logrus.Debugf("Normalized platform %s to %s", rawPlatform, normalizedPlatform) | ||
os = rawOS | ||
if rawOS != "" { | ||
os = normalizedPlatform.OS | ||
} | ||
arch = rawArch | ||
if rawArch != "" { | ||
arch = normalizedPlatform.Architecture | ||
} | ||
variant = rawVariant | ||
if rawVariant != "" || (rawVariant == "" && normalizedPlatform.Variant != "") { | ||
variant = normalizedPlatform.Variant | ||
} | ||
return os, arch, variant | ||
} | ||
|
||
func ToString(os, arch, variant string) string { | ||
if os == "" { | ||
os = runtime.GOOS | ||
} | ||
if arch == "" { | ||
arch = runtime.GOARCH | ||
} | ||
if variant == "" { | ||
return fmt.Sprintf("%s/%s", os, arch) | ||
} | ||
return fmt.Sprintf("%s/%s/%s", os, arch, variant) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters