Added support for setting OS version in docker manifest annotate.

Signed-off-by: Saswat Bhattacharya <sas.saswat@gmail.com>
This commit is contained in:
Saswat Bhattacharya 2018-10-18 23:19:51 -07:00 committed by Brian Goff
parent af2c31c4a7
commit bc5f102244
4 changed files with 8 additions and 0 deletions

View File

@ -18,6 +18,7 @@ type annotateOptions struct {
os string os string
arch string arch string
osFeatures []string osFeatures []string
osVersion string
} }
// NewAnnotateCommand creates a new `docker manifest annotate` command // 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.os, "os", "", "Set operating system")
flags.StringVar(&opts.arch, "arch", "", "Set architecture") 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.StringSliceVar(&opts.osFeatures, "os-features", []string{}, "Set operating system feature")
flags.StringVar(&opts.variant, "variant", "", "Set architecture variant") flags.StringVar(&opts.variant, "variant", "", "Set architecture variant")
@ -80,6 +82,9 @@ func runManifestAnnotate(dockerCli command.Cli, opts annotateOptions) error {
if opts.variant != "" { if opts.variant != "" {
imageManifest.Descriptor.Platform.Variant = 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) { 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) 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.SetArgs([]string{"example.com/list:v1", "example.com/alpine:3.0"})
cmd.Flags().Set("os", "freebsd") cmd.Flags().Set("os", "freebsd")
cmd.Flags().Set("arch", "fake") cmd.Flags().Set("arch", "fake")
cmd.Flags().Set("os-version", "1")
cmd.Flags().Set("os-features", "feature1") cmd.Flags().Set("os-features", "feature1")
cmd.Flags().Set("variant", "v7") cmd.Flags().Set("variant", "v7")
expectedError = "manifest entry for image has unsupported os/arch combination" expectedError = "manifest entry for image has unsupported os/arch combination"

View File

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

View File

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