commit: always set a parent ID
Always set a parent ID when we go to commit an image, whether it's as part of build-using-dockerfile or our "commit" CLI. Coerce the parent image's ID directly into the value that we use instead of digesting it again. Signed-off-by: Nalin Dahyabhai <nalin@redhat.com> Closes: #1538 Approved by: vrothberg
This commit is contained in:
parent
b466cbd23b
commit
810efa340a
|
@ -67,8 +67,6 @@ type CommitOptions struct {
|
|||
|
||||
// OnBuild is a list of commands to be run by images based on this image
|
||||
OnBuild []string
|
||||
// Parent is the base image that this image was created by.
|
||||
Parent string
|
||||
|
||||
// OmitTimestamp forces epoch 0 as created timestamp to allow for
|
||||
// deterministic, content-addressable builds.
|
||||
|
@ -169,7 +167,7 @@ func (b *Builder) Commit(ctx context.Context, dest types.ImageReference, options
|
|||
}
|
||||
}
|
||||
// Build an image reference from which we can copy the finished image.
|
||||
src, err := b.makeImageRef(options.PreferredManifestType, options.Parent, exportBaseLayers, options.Squash, options.BlobDirectory, options.Compression, options.HistoryTimestamp, options.OmitTimestamp)
|
||||
src, err := b.makeImageRef(options.PreferredManifestType, exportBaseLayers, options.Squash, options.BlobDirectory, options.Compression, options.HistoryTimestamp, options.OmitTimestamp)
|
||||
if err != nil {
|
||||
return imgID, nil, "", errors.Wrapf(err, "error computing layer digests and building metadata for container %q", b.ContainerID)
|
||||
}
|
||||
|
|
14
image.go
14
image.go
|
@ -184,7 +184,7 @@ func (i *containerImageRef) createConfigsAndManifests() (v1.Image, v1.Manifest,
|
|||
if err := json.Unmarshal(i.dconfig, &dimage); err != nil {
|
||||
return v1.Image{}, v1.Manifest{}, docker.V2Image{}, docker.V2S2Manifest{}, err
|
||||
}
|
||||
dimage.Parent = docker.ID(digest.FromString(i.parent))
|
||||
dimage.Parent = docker.ID(i.parent)
|
||||
// Always replace this value, since we're newer than our base image.
|
||||
dimage.Created = created
|
||||
// Clear the list of diffIDs, since we always repopulate it.
|
||||
|
@ -445,7 +445,7 @@ func (i *containerImageRef) NewImageSource(ctx context.Context, sc *types.System
|
|||
}
|
||||
dimage.History = append(dimage.History, dnews)
|
||||
appendHistory(i.postEmptyLayers)
|
||||
dimage.Parent = docker.ID(digest.FromString(i.parent))
|
||||
dimage.Parent = docker.ID(i.parent)
|
||||
|
||||
// Sanity check that we didn't just create a mismatch between non-empty layers in the
|
||||
// history and the number of diffIDs.
|
||||
|
@ -636,7 +636,7 @@ func (i *containerImageSource) GetBlob(ctx context.Context, blob types.BlobInfo,
|
|||
return ioutils.NewReadCloserWrapper(layerFile, closer), size, nil
|
||||
}
|
||||
|
||||
func (b *Builder) makeImageRef(manifestType, parent string, exporting bool, squash bool, blobDirectory string, compress archive.Compression, historyTimestamp *time.Time, omitTimestamp bool) (types.ImageReference, error) {
|
||||
func (b *Builder) makeImageRef(manifestType string, exporting bool, squash bool, blobDirectory string, compress archive.Compression, historyTimestamp *time.Time, omitTimestamp bool) (types.ImageReference, error) {
|
||||
var name reference.Named
|
||||
container, err := b.store.Container(b.ContainerID)
|
||||
if err != nil {
|
||||
|
@ -674,6 +674,14 @@ func (b *Builder) makeImageRef(manifestType, parent string, exporting bool, squa
|
|||
created = time.Unix(0, 0)
|
||||
}
|
||||
|
||||
parent := ""
|
||||
if b.FromImageID != "" {
|
||||
parentDigest := digest.NewDigestFromEncoded(digest.Canonical, b.FromImageID)
|
||||
if parentDigest.Validate() == nil {
|
||||
parent = parentDigest.String()
|
||||
}
|
||||
}
|
||||
|
||||
ref := &containerImageRef{
|
||||
store: b.store,
|
||||
compression: compress,
|
||||
|
|
|
@ -1460,7 +1460,6 @@ func (s *StageExecutor) commit(ctx context.Context, ib *imagebuilder.Builder, cr
|
|||
SystemContext: s.executor.systemContext,
|
||||
Squash: s.executor.squash,
|
||||
BlobDirectory: s.executor.blobDirectory,
|
||||
Parent: s.builder.FromImageID,
|
||||
}
|
||||
imgID, _, manifestDigest, err := s.builder.Commit(ctx, imageRef, options)
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue