Skip to content

Commit

Permalink
Merge pull request #690 from amouat/build_annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
imjasonh authored May 22, 2023
2 parents 00f6aa4 + 497e2c2 commit 8da2b41
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 7 additions & 0 deletions internal/cli/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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{}
Expand All @@ -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),
)
},
Expand All @@ -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
}
Expand Down
7 changes: 5 additions & 2 deletions pkg/build/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down

0 comments on commit 8da2b41

Please sign in to comment.