mirror of
https://github.com/containers/podman.git
synced 2025-09-28 01:04:28 +08:00
Vendor buildah after merging mtrmac/blob-info-caching-on-top-of-contents-caching
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
This commit is contained in:
104
vendor/github.com/containers/buildah/image.go
generated
vendored
104
vendor/github.com/containers/buildah/image.go
generated
vendored
@ -57,22 +57,24 @@ type containerImageRef struct {
|
||||
squash bool
|
||||
tarPath func(path string) (io.ReadCloser, error)
|
||||
parent string
|
||||
blobDirectory string
|
||||
}
|
||||
|
||||
type containerImageSource struct {
|
||||
path string
|
||||
ref *containerImageRef
|
||||
store storage.Store
|
||||
containerID string
|
||||
mountLabel string
|
||||
layerID string
|
||||
names []string
|
||||
compression archive.Compression
|
||||
config []byte
|
||||
configDigest digest.Digest
|
||||
manifest []byte
|
||||
manifestType string
|
||||
exporting bool
|
||||
path string
|
||||
ref *containerImageRef
|
||||
store storage.Store
|
||||
containerID string
|
||||
mountLabel string
|
||||
layerID string
|
||||
names []string
|
||||
compression archive.Compression
|
||||
config []byte
|
||||
configDigest digest.Digest
|
||||
manifest []byte
|
||||
manifestType string
|
||||
exporting bool
|
||||
blobDirectory string
|
||||
}
|
||||
|
||||
func (i *containerImageRef) NewImage(ctx context.Context, sc *types.SystemContext) (types.ImageCloser, error) {
|
||||
@ -105,11 +107,11 @@ func expectedDockerDiffIDs(image docker.V2Image) int {
|
||||
|
||||
// Compute the media types which we need to attach to a layer, given the type of
|
||||
// compression that we'll be applying.
|
||||
func (i *containerImageRef) computeLayerMIMEType(what string) (omediaType, dmediaType string, err error) {
|
||||
func computeLayerMIMEType(what string, layerCompression archive.Compression) (omediaType, dmediaType string, err error) {
|
||||
omediaType = v1.MediaTypeImageLayer
|
||||
dmediaType = docker.V2S2MediaTypeUncompressedLayer
|
||||
if i.compression != archive.Uncompressed {
|
||||
switch i.compression {
|
||||
if layerCompression != archive.Uncompressed {
|
||||
switch layerCompression {
|
||||
case archive.Gzip:
|
||||
omediaType = v1.MediaTypeImageLayerGzip
|
||||
dmediaType = manifest.DockerV2Schema2LayerMediaType
|
||||
@ -280,19 +282,21 @@ func (i *containerImageRef) NewImageSource(ctx context.Context, sc *types.System
|
||||
// The default layer media type assumes no compression.
|
||||
omediaType := v1.MediaTypeImageLayer
|
||||
dmediaType := docker.V2S2MediaTypeUncompressedLayer
|
||||
// Look up this layer.
|
||||
layer, err := i.store.Layer(layerID)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "unable to locate layer %q", layerID)
|
||||
}
|
||||
// If we're not re-exporting the data, and we're reusing layers individually, reuse
|
||||
// the blobsum and diff IDs.
|
||||
if !i.exporting && !i.squash && layerID != i.layerID {
|
||||
layer, err2 := i.store.Layer(layerID)
|
||||
if err2 != nil {
|
||||
return nil, errors.Wrapf(err, "unable to locate layer %q", layerID)
|
||||
}
|
||||
if layer.UncompressedDigest == "" {
|
||||
return nil, errors.Errorf("unable to look up size of layer %q", layerID)
|
||||
}
|
||||
layerBlobSum := layer.UncompressedDigest
|
||||
layerBlobSize := layer.UncompressedSize
|
||||
// Note this layer in the manifest, using the uncompressed blobsum.
|
||||
diffID := layer.UncompressedDigest
|
||||
// Note this layer in the manifest, using the appropriate blobsum.
|
||||
olayerDescriptor := v1.Descriptor{
|
||||
MediaType: omediaType,
|
||||
Digest: layerBlobSum,
|
||||
@ -305,13 +309,13 @@ func (i *containerImageRef) NewImageSource(ctx context.Context, sc *types.System
|
||||
Size: layerBlobSize,
|
||||
}
|
||||
dmanifest.Layers = append(dmanifest.Layers, dlayerDescriptor)
|
||||
// Note this layer in the list of diffIDs, again using the uncompressed blobsum.
|
||||
oimage.RootFS.DiffIDs = append(oimage.RootFS.DiffIDs, layerBlobSum)
|
||||
dimage.RootFS.DiffIDs = append(dimage.RootFS.DiffIDs, layerBlobSum)
|
||||
// Note this layer in the list of diffIDs, again using the uncompressed digest.
|
||||
oimage.RootFS.DiffIDs = append(oimage.RootFS.DiffIDs, diffID)
|
||||
dimage.RootFS.DiffIDs = append(dimage.RootFS.DiffIDs, diffID)
|
||||
continue
|
||||
}
|
||||
// Figure out if we need to change the media type, in case we're using compression.
|
||||
omediaType, dmediaType, err = i.computeLayerMIMEType(what)
|
||||
// Figure out if we need to change the media type, in case we've changed the compression.
|
||||
omediaType, dmediaType, err = computeLayerMIMEType(what, i.compression)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -368,8 +372,9 @@ func (i *containerImageRef) NewImageSource(ctx context.Context, sc *types.System
|
||||
}
|
||||
logrus.Debugf("%s size is %d bytes", what, size)
|
||||
// Rename the layer so that we can more easily find it by digest later.
|
||||
if err = os.Rename(filepath.Join(path, "layer"), filepath.Join(path, destHasher.Digest().String())); err != nil {
|
||||
return nil, errors.Wrapf(err, "error storing %s to file while renaming %q to %q", what, filepath.Join(path, "layer"), filepath.Join(path, destHasher.Digest().String()))
|
||||
finalBlobName := filepath.Join(path, destHasher.Digest().String())
|
||||
if err = os.Rename(filepath.Join(path, "layer"), finalBlobName); err != nil {
|
||||
return nil, errors.Wrapf(err, "error storing %s to file while renaming %q to %q", what, filepath.Join(path, "layer"), finalBlobName)
|
||||
}
|
||||
// Add a note in the manifest about the layer. The blobs are identified by their possibly-
|
||||
// compressed blob digests.
|
||||
@ -472,19 +477,20 @@ func (i *containerImageRef) NewImageSource(ctx context.Context, sc *types.System
|
||||
panic("unreachable code: unsupported manifest type")
|
||||
}
|
||||
src = &containerImageSource{
|
||||
path: path,
|
||||
ref: i,
|
||||
store: i.store,
|
||||
containerID: i.containerID,
|
||||
mountLabel: i.mountLabel,
|
||||
layerID: i.layerID,
|
||||
names: i.names,
|
||||
compression: i.compression,
|
||||
config: config,
|
||||
configDigest: digest.Canonical.FromBytes(config),
|
||||
manifest: imageManifest,
|
||||
manifestType: manifestType,
|
||||
exporting: i.exporting,
|
||||
path: path,
|
||||
ref: i,
|
||||
store: i.store,
|
||||
containerID: i.containerID,
|
||||
mountLabel: i.mountLabel,
|
||||
layerID: i.layerID,
|
||||
names: i.names,
|
||||
compression: i.compression,
|
||||
config: config,
|
||||
configDigest: digest.Canonical.FromBytes(config),
|
||||
manifest: imageManifest,
|
||||
manifestType: manifestType,
|
||||
exporting: i.exporting,
|
||||
blobDirectory: i.blobDirectory,
|
||||
}
|
||||
return src, nil
|
||||
}
|
||||
@ -551,7 +557,7 @@ func (i *containerImageSource) LayerInfosForCopy(ctx context.Context) ([]types.B
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (i *containerImageSource) GetBlob(ctx context.Context, blob types.BlobInfo) (reader io.ReadCloser, size int64, err error) {
|
||||
func (i *containerImageSource) GetBlob(ctx context.Context, blob types.BlobInfo, cache types.BlobInfoCache) (reader io.ReadCloser, size int64, err error) {
|
||||
if blob.Digest == i.configDigest {
|
||||
logrus.Debugf("start reading config")
|
||||
reader := bytes.NewReader(i.config)
|
||||
@ -561,7 +567,16 @@ func (i *containerImageSource) GetBlob(ctx context.Context, blob types.BlobInfo)
|
||||
}
|
||||
return ioutils.NewReadCloserWrapper(reader, closer), reader.Size(), nil
|
||||
}
|
||||
layerFile, err := os.OpenFile(filepath.Join(i.path, blob.Digest.String()), os.O_RDONLY, 0600)
|
||||
var layerFile *os.File
|
||||
for _, path := range []string{i.blobDirectory, i.path} {
|
||||
layerFile, err = os.OpenFile(filepath.Join(path, blob.Digest.String()), os.O_RDONLY, 0600)
|
||||
if err == nil {
|
||||
break
|
||||
}
|
||||
if !os.IsNotExist(err) {
|
||||
logrus.Debugf("error checking for layer %q in %q: %v", blob.Digest.String(), path, err)
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
logrus.Debugf("error reading layer %q: %v", blob.Digest.String(), err)
|
||||
return nil, -1, errors.Wrapf(err, "error opening file %q to buffer layer blob", filepath.Join(i.path, blob.Digest.String()))
|
||||
@ -584,7 +599,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, compress archive.Compression, historyTimestamp *time.Time) (types.ImageReference, error) {
|
||||
func (b *Builder) makeImageRef(manifestType, parent string, exporting bool, squash bool, blobDirectory string, compress archive.Compression, historyTimestamp *time.Time) (types.ImageReference, error) {
|
||||
var name reference.Named
|
||||
container, err := b.store.Container(b.ContainerID)
|
||||
if err != nil {
|
||||
@ -630,6 +645,7 @@ func (b *Builder) makeImageRef(manifestType, parent string, exporting bool, squa
|
||||
squash: squash,
|
||||
tarPath: b.tarPath(),
|
||||
parent: parent,
|
||||
blobDirectory: blobDirectory,
|
||||
}
|
||||
return ref, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user