mirror of https://github.com/docker/buildx.git
Pass in index annotations from builds on multiple nodes
Fixes #2540 Signed-off-by: Eli Treuherz <et@arenko.group>
This commit is contained in:
parent
9b100c2552
commit
3971361ed2
|
@ -61,6 +61,7 @@ type Options struct {
|
||||||
|
|
||||||
Ref string
|
Ref string
|
||||||
Allow []entitlements.Entitlement
|
Allow []entitlements.Entitlement
|
||||||
|
Annotations map[exptypes.AnnotationKey]string
|
||||||
Attests map[string]*string
|
Attests map[string]*string
|
||||||
BuildArgs map[string]string
|
BuildArgs map[string]string
|
||||||
CacheFrom []client.CacheOptionsEntry
|
CacheFrom []client.CacheOptionsEntry
|
||||||
|
@ -607,7 +608,8 @@ func BuildWithResultHandler(ctx context.Context, nodes []builder.Node, opt map[s
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dt, desc, err := itpull.Combine(ctx, srcs, nil, false)
|
filteredAnnotations := filterIndexAnnotations(opt.Annotations)
|
||||||
|
dt, desc, err := itpull.Combine(ctx, srcs, filteredAnnotations, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -655,6 +657,17 @@ func BuildWithResultHandler(ctx context.Context, nodes []builder.Node, opt map[s
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func filterIndexAnnotations(annotations map[exptypes.AnnotationKey]string) map[exptypes.AnnotationKey]string {
|
||||||
|
filteredAnnotations := map[exptypes.AnnotationKey]string{}
|
||||||
|
for k, v := range annotations {
|
||||||
|
switch k.Type {
|
||||||
|
case exptypes.AnnotationIndex, exptypes.AnnotationManifestDescriptor:
|
||||||
|
filteredAnnotations[k] = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return filteredAnnotations
|
||||||
|
}
|
||||||
|
|
||||||
func pushWithMoby(ctx context.Context, d *driver.DriverHandle, name string, l progress.SubLogger) error {
|
func pushWithMoby(ctx context.Context, d *driver.DriverHandle, name string, l progress.SubLogger) error {
|
||||||
api := d.Config().DockerAPI
|
api := d.Config().DockerAPI
|
||||||
if api == nil {
|
if api == nil {
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
|
|
||||||
"github.com/distribution/reference"
|
"github.com/distribution/reference"
|
||||||
"github.com/docker/buildx/builder"
|
"github.com/docker/buildx/builder"
|
||||||
|
"github.com/docker/buildx/util/buildflags"
|
||||||
"github.com/docker/buildx/util/cobrautil/completion"
|
"github.com/docker/buildx/util/cobrautil/completion"
|
||||||
"github.com/docker/buildx/util/imagetools"
|
"github.com/docker/buildx/util/imagetools"
|
||||||
"github.com/docker/buildx/util/progress"
|
"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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -136,8 +136,9 @@ func RunBuild(ctx context.Context, dockerCli command.Cli, in controllerapi.Build
|
||||||
|
|
||||||
annotations, err := buildflags.ParseAnnotations(in.Annotations)
|
annotations, err := buildflags.ParseAnnotations(in.Annotations)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, errors.Wrap(err, "parse annotations")
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, o := range outputs {
|
for _, o := range outputs {
|
||||||
for k, v := range annotations {
|
for k, v := range annotations {
|
||||||
o.Attrs[k.String()] = v
|
o.Attrs[k.String()] = v
|
||||||
|
@ -146,6 +147,8 @@ func RunBuild(ctx context.Context, dockerCli command.Cli, in controllerapi.Build
|
||||||
|
|
||||||
opts.Exports = outputs
|
opts.Exports = outputs
|
||||||
|
|
||||||
|
opts.Annotations = annotations
|
||||||
|
|
||||||
opts.CacheFrom = controllerapi.CreateCaches(in.CacheFrom)
|
opts.CacheFrom = controllerapi.CreateCaches(in.CacheFrom)
|
||||||
opts.CacheTo = controllerapi.CreateCaches(in.CacheTo)
|
opts.CacheTo = controllerapi.CreateCaches(in.CacheTo)
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,6 @@ import (
|
||||||
"github.com/containerd/containerd/remotes"
|
"github.com/containerd/containerd/remotes"
|
||||||
"github.com/containerd/errdefs"
|
"github.com/containerd/errdefs"
|
||||||
"github.com/distribution/reference"
|
"github.com/distribution/reference"
|
||||||
"github.com/docker/buildx/util/buildflags"
|
|
||||||
"github.com/moby/buildkit/exporter/containerimage/exptypes"
|
"github.com/moby/buildkit/exporter/containerimage/exptypes"
|
||||||
"github.com/moby/buildkit/util/contentutil"
|
"github.com/moby/buildkit/util/contentutil"
|
||||||
"github.com/opencontainers/go-digest"
|
"github.com/opencontainers/go-digest"
|
||||||
|
@ -29,7 +28,7 @@ type Source struct {
|
||||||
Ref reference.Named
|
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)
|
eg, ctx := errgroup.WithContext(ctx)
|
||||||
|
|
||||||
dts := make([][]byte, len(srcs))
|
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
|
// annotations are only allowed on OCI indexes
|
||||||
indexAnnotation := make(map[string]string)
|
indexAnnotation := make(map[string]string)
|
||||||
if mt == ocispec.MediaTypeImageIndex {
|
if mt == ocispec.MediaTypeImageIndex {
|
||||||
annotations, err := buildflags.ParseAnnotations(ann)
|
for k, v := range ann {
|
||||||
if err != nil {
|
|
||||||
return nil, ocispec.Descriptor{}, err
|
|
||||||
}
|
|
||||||
for k, v := range annotations {
|
|
||||||
switch k.Type {
|
switch k.Type {
|
||||||
case exptypes.AnnotationIndex:
|
case exptypes.AnnotationIndex:
|
||||||
indexAnnotation[k.Key] = v
|
indexAnnotation[k.Key] = v
|
||||||
|
|
Loading…
Reference in New Issue