diff --git a/buildah.go b/buildah.go index 858da993e..03c46f410 100644 --- a/buildah.go +++ b/buildah.go @@ -119,6 +119,9 @@ type Builder struct { // FromImageID is the ID of the source image which was used to create // the container, if one was used. It should not be modified. FromImageID string `json:"image-id"` + // FromImageDigest is the digest of the source image which was used to + // create the container, if one was used. It should not be modified. + FromImageDigest string `json:"image-digest"` // Config is the source image's configuration. It should not be // modified. Config []byte `json:"config,omitempty"` @@ -200,6 +203,7 @@ type BuilderInfo struct { Type string FromImage string FromImageID string + FromImageDigest string Config string Manifest string Container string @@ -243,6 +247,7 @@ func GetBuildInfo(b *Builder) BuilderInfo { Type: b.Type, FromImage: b.FromImage, FromImageID: b.FromImageID, + FromImageDigest: b.FromImageDigest, Config: string(b.Config), Manifest: string(b.Manifest), Container: b.Container, diff --git a/import.go b/import.go index 418487438..b01d4d07b 100644 --- a/import.go +++ b/import.go @@ -5,6 +5,7 @@ import ( "github.com/containers/buildah/docker" "github.com/containers/buildah/util" + "github.com/containers/image/manifest" is "github.com/containers/image/storage" "github.com/containers/image/types" "github.com/containers/storage" @@ -47,6 +48,13 @@ func importBuilderDataFromImage(ctx context.Context, store storage.Store, system } } + imageDigest := "" + if manifestBytes, _, err := src.Manifest(ctx); err == nil { + if manifestDigest, err := manifest.Digest(manifestBytes); err == nil { + imageDigest = manifestDigest.String() + } + } + defaultNamespaceOptions, err := DefaultNamespaceOptions() if err != nil { return nil, err @@ -57,6 +65,7 @@ func importBuilderDataFromImage(ctx context.Context, store storage.Store, system Type: containerType, FromImage: imageName, FromImageID: imageID, + FromImageDigest: imageDigest, Container: containerName, ContainerID: containerID, ImageAnnotations: map[string]string{}, diff --git a/new.go b/new.go index ecd1666bf..72d53dd99 100644 --- a/new.go +++ b/new.go @@ -7,6 +7,7 @@ import ( "strings" "github.com/containers/buildah/util" + "github.com/containers/image/manifest" "github.com/containers/image/pkg/sysregistries" is "github.com/containers/image/storage" "github.com/containers/image/transports" @@ -254,6 +255,7 @@ func newBuilder(ctx context.Context, store storage.Store, options BuilderOptions } image := options.FromImage imageID := "" + imageDigest := "" topLayer := "" if img != nil { image = getImageName(imageNamePrefix(image), img) @@ -266,6 +268,11 @@ func newBuilder(ctx context.Context, store storage.Store, options BuilderOptions if err != nil { return nil, errors.Wrapf(err, "error instantiating image for %q", transports.ImageName(ref)) } + if manifestBytes, _, err := src.Manifest(ctx); err == nil { + if manifestDigest, err := manifest.Digest(manifestBytes); err == nil { + imageDigest = manifestDigest.String() + } + } defer src.Close() } @@ -327,6 +334,7 @@ func newBuilder(ctx context.Context, store storage.Store, options BuilderOptions Type: containerType, FromImage: image, FromImageID: imageID, + FromImageDigest: imageDigest, Container: name, ContainerID: container.ID, ImageAnnotations: map[string]string{},