1
0
mirror of https://github.com/containers/buildah.git synced 2026-02-05 09:45:38 +01:00

Add --metadata-file

Add a MetadataFile field to BuildOptions, to which we write a dictionary
of information about a just-committed image.

Pay more attention to sourceDateEpoch than to timestamp when we're
tagging an existing image with the intended destination name.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
This commit is contained in:
Nalin Dahyabhai
2025-10-17 14:33:04 -04:00
parent 45da9cff3b
commit 1e6bb467fe
14 changed files with 263 additions and 92 deletions

View File

@@ -0,0 +1,22 @@
package metadata
import (
"github.com/containers/buildah/docker"
"github.com/opencontainers/go-digest"
v1 "github.com/opencontainers/image-spec/specs-go/v1"
)
// Build constructs a map containing the passed-in information about a just-committed or reused-as-cache image.
func Build(imageConfigDigest digest.Digest, descriptor v1.Descriptor) (map[string]any, error) {
metadata := make(map[string]any)
if imageConfigDigest.Validate() == nil {
metadata[docker.ExporterImageConfigDigestKey] = imageConfigDigest.String()
}
if descriptor.MediaType != "" && descriptor.Digest.Validate() == nil && descriptor.Size > 0 {
metadata[docker.ExporterImageDescriptorKey] = descriptor
}
if descriptor.Digest.Validate() == nil {
metadata[docker.ExporterImageDigestKey] = descriptor.Digest
}
return metadata, nil
}