mirror of https://github.com/docker/buildx.git
Merge pull request #2546 from treuherz/multinode-annotations
Pass in index annotations from builds on multiple nodes
This commit is contained in:
commit
59a0ffcf83
|
@ -608,7 +608,12 @@ func BuildWithResultHandler(ctx context.Context, nodes []builder.Node, opt map[s
|
|||
}
|
||||
}
|
||||
|
||||
dt, desc, err := itpull.Combine(ctx, srcs, nil, false)
|
||||
indexAnnotations, err := extractIndexAnnotations(opt.Exports)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
dt, desc, err := itpull.Combine(ctx, srcs, indexAnnotations, false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -656,6 +661,27 @@ func BuildWithResultHandler(ctx context.Context, nodes []builder.Node, opt map[s
|
|||
return resp, nil
|
||||
}
|
||||
|
||||
func extractIndexAnnotations(exports []client.ExportEntry) (map[exptypes.AnnotationKey]string, error) {
|
||||
annotations := map[exptypes.AnnotationKey]string{}
|
||||
for _, exp := range exports {
|
||||
for k, v := range exp.Attrs {
|
||||
ak, ok, err := exptypes.ParseAnnotationKey(k)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
switch ak.Type {
|
||||
case exptypes.AnnotationIndex, exptypes.AnnotationManifestDescriptor:
|
||||
annotations[ak] = v
|
||||
}
|
||||
}
|
||||
}
|
||||
return annotations, nil
|
||||
}
|
||||
|
||||
func pushWithMoby(ctx context.Context, d *driver.DriverHandle, name string, l progress.SubLogger) error {
|
||||
api := d.Config().DockerAPI
|
||||
if api == nil {
|
||||
|
|
|
@ -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"
|
||||
|
@ -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
|
||||
}
|
||||
|
|
|
@ -136,8 +136,9 @@ func RunBuild(ctx context.Context, dockerCli command.Cli, in controllerapi.Build
|
|||
|
||||
annotations, err := buildflags.ParseAnnotations(in.Annotations)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
return nil, nil, errors.Wrap(err, "parse annotations")
|
||||
}
|
||||
|
||||
for _, o := range outputs {
|
||||
for k, v := range annotations {
|
||||
o.Attrs[k.String()] = v
|
||||
|
|
|
@ -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"
|
||||
|
@ -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))
|
||||
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue