Get annotations from exports

Signed-off-by: Eli Treuherz <et@arenko.group>
This commit is contained in:
Eli Treuherz
2024-06-27 13:25:41 +01:00
parent 3971361ed2
commit 6f45b0ea06
2 changed files with 23 additions and 12 deletions

View File

@ -61,7 +61,6 @@ 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
@ -608,8 +607,12 @@ func BuildWithResultHandler(ctx context.Context, nodes []builder.Node, opt map[s
} }
} }
filteredAnnotations := filterIndexAnnotations(opt.Annotations) indexAnnotations, err := extractIndexAnnotations(opt.Exports)
dt, desc, err := itpull.Combine(ctx, srcs, filteredAnnotations, false) if err != nil {
return err
}
dt, desc, err := itpull.Combine(ctx, srcs, indexAnnotations, false)
if err != nil { if err != nil {
return err return err
} }
@ -657,15 +660,25 @@ 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 { func extractIndexAnnotations(exports []client.ExportEntry) (map[exptypes.AnnotationKey]string, error) {
filteredAnnotations := map[exptypes.AnnotationKey]string{} annotations := map[exptypes.AnnotationKey]string{}
for k, v := range annotations { for _, exp := range exports {
switch k.Type { for k, v := range exp.Attrs {
case exptypes.AnnotationIndex, exptypes.AnnotationManifestDescriptor: ak, ok, err := exptypes.ParseAnnotationKey(k)
filteredAnnotations[k] = v if !ok {
continue
}
if err != nil {
return nil, err
}
switch ak.Type {
case exptypes.AnnotationIndex, exptypes.AnnotationManifestDescriptor:
annotations[ak] = v
}
} }
} }
return filteredAnnotations return annotations, nil
} }
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 {

View File

@ -147,8 +147,6 @@ 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)