From c86ec011be16c8ab59639f45d08f86a100123c77 Mon Sep 17 00:00:00 2001 From: Adrian Mouat Date: Mon, 22 May 2023 12:35:29 +0100 Subject: [PATCH] Fix annotations. - Can now pass annotations to build. - Publish includes annotations from yaml. Signed-off-by: Adrian Mouat --- internal/cli/build.go | 7 +++++++ pkg/build/options.go | 7 +++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/internal/cli/build.go b/internal/cli/build.go index 866544950..7ab822f36 100644 --- a/internal/cli/build.go +++ b/internal/cli/build.go @@ -48,6 +48,7 @@ func buildCmd() *cobra.Command { var extraRepos []string var buildOptions []string var logPolicy []string + var rawAnnotations []string cmd := &cobra.Command{ Use: "build", @@ -82,6 +83,10 @@ bill of materials) describing the image contents. // TODO(kaniini): Print warning when multi-arch build is requested // and ignored by the build system. archs := types.ParseArchitectures(archstrs) + annotations, err := parseAnnotations(rawAnnotations) + if err != nil { + return fmt.Errorf("parsing annotations from command line: %w", err) + } if !writeSBOM { sbomFormats = []string{} @@ -99,6 +104,7 @@ bill of materials) describing the image contents. build.WithLogger(logger), build.WithDebugLogging(debugEnabled), build.WithVCS(withVCS), + build.WithAnnotations(annotations), build.WithBuildOptions(buildOptions), ) }, @@ -117,6 +123,7 @@ bill of materials) describing the image contents. cmd.Flags().StringSliceVarP(&extraRepos, "repository-append", "r", []string{}, "path to extra repositories to include") cmd.Flags().StringSliceVar(&buildOptions, "build-option", []string{}, "build options to enable") cmd.Flags().StringSliceVar(&logPolicy, "log-policy", []string{}, "logging policy to use") + cmd.Flags().StringSliceVar(&rawAnnotations, "annotations", []string{}, "OCI annotations to add. Separate with colon (key:value)") return cmd } diff --git a/pkg/build/options.go b/pkg/build/options.go index d7b8442e0..f4b159ae0 100644 --- a/pkg/build/options.go +++ b/pkg/build/options.go @@ -196,10 +196,13 @@ func WithVCS(enable bool) Option { } } -// WithAnnotations parses and populates the annotations in the ImageConfiguration +// WithAnnotations adds annotations from commandline to those in the config. +// Commandline annotations take precedence. func WithAnnotations(annotations map[string]string) Option { return func(bc *Context) error { - bc.ImageConfiguration.Annotations = annotations + for k, v := range annotations { + bc.ImageConfiguration.Annotations[k] = v + } return nil } }