Merge pull request #2578 from cpuguy83/anotate_os_version

Added support for setting OS version in docker manifest annotate.
This commit is contained in:
Sebastiaan van Stijn 2020-06-15 19:31:17 +02:00 committed by GitHub
commit 077af8151f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 8 additions and 0 deletions

View File

@ -18,6 +18,7 @@ type annotateOptions struct {
os string
arch string
osFeatures []string
osVersion string
}
// NewAnnotateCommand creates a new `docker manifest annotate` command
@ -39,6 +40,7 @@ func newAnnotateCommand(dockerCli command.Cli) *cobra.Command {
flags.StringVar(&opts.os, "os", "", "Set operating system")
flags.StringVar(&opts.arch, "arch", "", "Set architecture")
flags.StringVar(&opts.osVersion, "os-version", "", "Set operating system version")
flags.StringSliceVar(&opts.osFeatures, "os-features", []string{}, "Set operating system feature")
flags.StringVar(&opts.variant, "variant", "", "Set architecture variant")
@ -80,6 +82,9 @@ func runManifestAnnotate(dockerCli command.Cli, opts annotateOptions) error {
if opts.variant != "" {
imageManifest.Descriptor.Platform.Variant = opts.variant
}
if opts.osVersion != "" {
imageManifest.Descriptor.Platform.OSVersion = opts.osVersion
}
if !isValidOSArch(imageManifest.Descriptor.Platform.OS, imageManifest.Descriptor.Platform.Architecture) {
return errors.Errorf("manifest entry for image has unsupported os/arch combination: %s/%s", opts.os, opts.arch)

View File

@ -58,6 +58,7 @@ func TestManifestAnnotate(t *testing.T) {
cmd.SetArgs([]string{"example.com/list:v1", "example.com/alpine:3.0"})
cmd.Flags().Set("os", "freebsd")
cmd.Flags().Set("arch", "fake")
cmd.Flags().Set("os-version", "1")
cmd.Flags().Set("os-features", "feature1")
cmd.Flags().Set("variant", "v7")
expectedError = "manifest entry for image has unsupported os/arch combination"

View File

@ -7,6 +7,7 @@
"platform": {
"architecture": "arm",
"os": "freebsd",
"os.version": "1",
"os.features": [
"feature1"
],

View File

@ -77,6 +77,7 @@ Options:
--arch string Set architecture
--help Print usage
--os string Set operating system
--os-version string Set operating system version
--os-features stringSlice Set operating system feature
--variant string Set architecture variant