Skip to content

Commit

Permalink
Pass in index annotations from builds on multiple nodes
Browse files Browse the repository at this point in the history
Fixes #2540

Signed-off-by: Eli Treuherz <[email protected]>
  • Loading branch information
treuherz committed Jun 24, 2024
1 parent 9b100c2 commit 7443fbd
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
11 changes: 10 additions & 1 deletion build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ type Options struct {

Ref string
Allow []entitlements.Entitlement
Annotations map[exptypes.AnnotationKey]string
Attests map[string]*string
BuildArgs map[string]string
CacheFrom []client.CacheOptionsEntry
Expand Down Expand Up @@ -607,7 +608,15 @@ func BuildWithResultHandler(ctx context.Context, nodes []builder.Node, opt map[s
}
}

dt, desc, err := itpull.Combine(ctx, srcs, nil, false)
filteredAnnotations := map[exptypes.AnnotationKey]string{}
for k, v := range opt.Annotations {
switch k.Type {
case exptypes.AnnotationIndex, exptypes.AnnotationManifestDescriptor:
filteredAnnotations[k] = v
}
}

dt, desc, err := itpull.Combine(ctx, srcs, filteredAnnotations, false)
if err != nil {
return err
}
Expand Down
8 changes: 7 additions & 1 deletion commands/imagetools/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/distribution/reference"
"github.com/docker/buildx/builder"
"github.com/docker/buildx/util/buildflags"
"github.com/docker/buildx/util/cobrautil/completion"
"github.com/docker/buildx/util/imagetools"
"github.com/docker/buildx/util/progress"
Expand Down Expand Up @@ -154,7 +155,12 @@ func runCreate(ctx context.Context, dockerCli command.Cli, in createOptions, arg
}
}

dt, desc, err := r.Combine(ctx, srcs, in.annotations, in.preferIndex)
annotations, err := buildflags.ParseAnnotations(in.annotations)
if err != nil {
return errors.Wrapf(err, "failed to parse annotations")
}

dt, desc, err := r.Combine(ctx, srcs, annotations, in.preferIndex)
if err != nil {
return err
}
Expand Down
5 changes: 5 additions & 0 deletions controller/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ func RunBuild(ctx context.Context, dockerCli command.Cli, in controllerapi.Build

opts.SourcePolicy = in.SourcePolicy

opts.Annotations, err = buildflags.ParseAnnotations(in.Annotations)
if err != nil {
return nil, nil, errors.Wrapf(err, "failed to parse annotations")
}

allow, err := buildflags.ParseEntitlements(in.Allow)
if err != nil {
return nil, nil, err
Expand Down
9 changes: 2 additions & 7 deletions util/imagetools/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/containerd/containerd/remotes"
"github.com/containerd/errdefs"
"github.com/distribution/reference"
"github.com/docker/buildx/util/buildflags"
"github.com/moby/buildkit/exporter/containerimage/exptypes"
"github.com/moby/buildkit/util/contentutil"
"github.com/opencontainers/go-digest"
Expand All @@ -29,7 +28,7 @@ type Source struct {
Ref reference.Named
}

func (r *Resolver) Combine(ctx context.Context, srcs []*Source, ann []string, preferIndex bool) ([]byte, ocispec.Descriptor, error) {
func (r *Resolver) Combine(ctx context.Context, srcs []*Source, ann map[exptypes.AnnotationKey]string, preferIndex bool) ([]byte, ocispec.Descriptor, error) {
eg, ctx := errgroup.WithContext(ctx)

dts := make([][]byte, len(srcs))
Expand Down Expand Up @@ -152,11 +151,7 @@ func (r *Resolver) Combine(ctx context.Context, srcs []*Source, ann []string, pr
// annotations are only allowed on OCI indexes
indexAnnotation := make(map[string]string)
if mt == ocispec.MediaTypeImageIndex {
annotations, err := buildflags.ParseAnnotations(ann)
if err != nil {
return nil, ocispec.Descriptor{}, err
}
for k, v := range annotations {
for k, v := range ann {
switch k.Type {
case exptypes.AnnotationIndex:
indexAnnotation[k.Key] = v
Expand Down

0 comments on commit 7443fbd

Please sign in to comment.