Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix annotations #690

Merged
merged 1 commit into from
May 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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