mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-07-10 13:37:08 +08:00
imagetools: simplify return type of annotation parser
Signed-off-by: Justin Chadwell <me@jedevc.com>
This commit is contained in:
@ -147,17 +147,15 @@ func (r *Resolver) Combine(ctx context.Context, srcs []*Source, ann map[string]s
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, ocispec.Descriptor{}, err
|
return nil, ocispec.Descriptor{}, err
|
||||||
}
|
}
|
||||||
if len(annotations[exptypes.AnnotationIndex]) > 0 {
|
for k, v := range annotations {
|
||||||
for k, v := range annotations[exptypes.AnnotationIndex] {
|
switch k.Type {
|
||||||
|
case exptypes.AnnotationIndex:
|
||||||
indexAnnotation[k.Key] = v
|
indexAnnotation[k.Key] = v
|
||||||
}
|
case exptypes.AnnotationManifestDescriptor:
|
||||||
}
|
for i := 0; i < len(newDescs); i++ {
|
||||||
if len(annotations[exptypes.AnnotationManifestDescriptor]) > 0 {
|
if newDescs[i].Annotations == nil {
|
||||||
for i := 0; i < len(newDescs); i++ {
|
newDescs[i].Annotations = map[string]string{}
|
||||||
if newDescs[i].Annotations == nil {
|
}
|
||||||
newDescs[i].Annotations = map[string]string{}
|
|
||||||
}
|
|
||||||
for k, v := range annotations[exptypes.AnnotationManifestDescriptor] {
|
|
||||||
if k.Platform == nil || k.PlatformString() == platforms.Format(*newDescs[i].Platform) {
|
if k.Platform == nil || k.PlatformString() == platforms.Format(*newDescs[i].Platform) {
|
||||||
newDescs[i].Annotations[k.Key] = v
|
newDescs[i].Annotations[k.Key] = v
|
||||||
}
|
}
|
||||||
@ -296,11 +294,10 @@ func detectMediaType(dt []byte) (string, error) {
|
|||||||
return images.MediaTypeDockerSchema2ManifestList, nil
|
return images.MediaTypeDockerSchema2ManifestList, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseAnnotations(ann map[string]string) (map[string]map[exptypes.AnnotationKey]string, error) {
|
func parseAnnotations(ann map[string]string) (map[exptypes.AnnotationKey]string, error) {
|
||||||
// TODO: use buildkit's annotation parser once it supports setting custom prefix and ":" separator
|
// TODO: use buildkit's annotation parser once it supports setting custom prefix and ":" separator
|
||||||
annotationRegexp := regexp.MustCompile(`^([a-z-]+)(?:\[([A-Za-z0-9_/-]+)\])?:(\S+)$`)
|
annotationRegexp := regexp.MustCompile(`^([a-z-]+)(?:\[([A-Za-z0-9_/-]+)\])?:(\S+)$`)
|
||||||
indexAnnotations := make(map[exptypes.AnnotationKey]string)
|
annotations := make(map[exptypes.AnnotationKey]string)
|
||||||
manifestDescriptorAnnotations := make(map[exptypes.AnnotationKey]string)
|
|
||||||
for k, v := range ann {
|
for k, v := range ann {
|
||||||
groups := annotationRegexp.FindStringSubmatch(k)
|
groups := annotationRegexp.FindStringSubmatch(k)
|
||||||
if groups == nil {
|
if groups == nil {
|
||||||
@ -323,14 +320,14 @@ func parseAnnotations(ann map[string]string) (map[string]map[exptypes.Annotation
|
|||||||
Platform: ociPlatform,
|
Platform: ociPlatform,
|
||||||
Key: key,
|
Key: key,
|
||||||
}
|
}
|
||||||
indexAnnotations[ak] = v
|
annotations[ak] = v
|
||||||
case exptypes.AnnotationManifestDescriptor:
|
case exptypes.AnnotationManifestDescriptor:
|
||||||
ak := exptypes.AnnotationKey{
|
ak := exptypes.AnnotationKey{
|
||||||
Type: typ,
|
Type: typ,
|
||||||
Platform: ociPlatform,
|
Platform: ociPlatform,
|
||||||
Key: key,
|
Key: key,
|
||||||
}
|
}
|
||||||
manifestDescriptorAnnotations[ak] = v
|
annotations[ak] = v
|
||||||
case exptypes.AnnotationManifest:
|
case exptypes.AnnotationManifest:
|
||||||
return nil, errors.Errorf("%q annotations are not supported yet", typ)
|
return nil, errors.Errorf("%q annotations are not supported yet", typ)
|
||||||
case exptypes.AnnotationIndexDescriptor:
|
case exptypes.AnnotationIndexDescriptor:
|
||||||
@ -339,8 +336,5 @@ func parseAnnotations(ann map[string]string) (map[string]map[exptypes.Annotation
|
|||||||
return nil, errors.Errorf("unknown annotation type %q", typ)
|
return nil, errors.Errorf("unknown annotation type %q", typ)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return map[string]map[exptypes.AnnotationKey]string{
|
return annotations, nil
|
||||||
exptypes.AnnotationIndex: indexAnnotations,
|
|
||||||
exptypes.AnnotationManifestDescriptor: manifestDescriptorAnnotations,
|
|
||||||
}, nil
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user