update image extra attributes author in labels (#17294)

Signed-off-by: yminer <yminer@vmware.com>
This commit is contained in:
MinerYang 2022-08-03 13:56:09 +08:00 committed by GitHub
parent fe37fb7384
commit a412fb7943
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -65,11 +65,19 @@ func (m *manifestV2Processor) AbstractMetadata(ctx context.Context, artifact *ar
artifact.ExtraAttrs["architecture"] = config.Architecture
artifact.ExtraAttrs["os"] = config.OS
artifact.ExtraAttrs["config"] = config.Config
author := config.Author
// if the author is null, try to get it from labels:
// https://docs.docker.com/engine/reference/builder/#maintainer-deprecated
author := config.Author
// https://github.com/opencontainers/image-spec/blob/main/annotations.md#pre-defined-annotation-keys
authorlist := []string{"org.opencontainers.image.authors", "maintainer"}
if len(author) == 0 && len(config.Config.Labels) > 0 {
author = config.Config.Labels["maintainer"]
for _, authorlabel := range authorlist {
if val, ok := config.Config.Labels[string(authorlabel)]; ok && len(val) > 0 {
author = val
break
}
}
}
artifact.ExtraAttrs["author"] = author
return nil