build: add --annotation shortcut flag

This extracts the same logic for parsing annotations from the imagetools
create command, and allows the same flags to be attached to the build
command.

These annotations are then merged into all provided exporters.

Signed-off-by: Justin Chadwell <me@jedevc.com>
This commit is contained in:
Justin Chadwell
2023-08-24 13:55:21 +01:00
parent 8fe2070d10
commit a59058e8a5
6 changed files with 109 additions and 58 deletions

View File

@ -83,11 +83,6 @@ func runCreate(dockerCli command.Cli, in createOptions, args []string) error {
return errors.Errorf("no repositories specified, please set a reference in tag or source")
}
ann, err := parseAnnotations(in.annotations)
if err != nil {
return err
}
var defaultRepo *string
if len(repos) == 1 {
for repo := range repos {
@ -160,7 +155,7 @@ func runCreate(dockerCli command.Cli, in createOptions, args []string) error {
}
}
dt, desc, err := r.Combine(ctx, srcs, ann)
dt, desc, err := r.Combine(ctx, srcs, in.annotations)
if err != nil {
return err
}
@ -270,18 +265,6 @@ func parseSource(in string) (*imagetools.Source, error) {
return &s, nil
}
func parseAnnotations(in []string) (map[string]string, error) {
out := make(map[string]string)
for _, i := range in {
kv := strings.SplitN(i, "=", 2)
if len(kv) != 2 {
return nil, errors.Errorf("invalid annotation %q, expected key=value", in)
}
out[kv[0]] = kv[1]
}
return out, nil
}
func createCmd(dockerCli command.Cli, opts RootOptions) *cobra.Command {
var options createOptions