-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix: archive/tar: write too long
error when using Docker Desktop containerd backend
#275
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ import ( | |
"github.com/docker/docker/pkg/jsonmessage" | ||
registryName "github.com/google/go-containerregistry/pkg/name" | ||
v1 "github.com/google/go-containerregistry/pkg/v1" | ||
"github.com/google/go-containerregistry/pkg/v1/tarball" | ||
"golang.org/x/sync/errgroup" | ||
|
||
"github.com/buildpacks/imgutil" | ||
|
@@ -288,11 +289,13 @@ func (s *Store) getLayerSize(layer v1.Layer) (int64, error) { | |
return 0, err | ||
} | ||
knownLayer, layerFound := s.onDiskLayersByDiffID[diffID] | ||
if layerFound { | ||
if layerFound && knownLayer.uncompressedSize != -1 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the real fix |
||
return knownLayer.uncompressedSize, nil | ||
} | ||
// FIXME: this is a time sink and should be avoided if the daemon accepts OCI layout-formatted tars | ||
// If layer was not seen previously, we need to read it to get the uncompressed size | ||
// In practice, we should not get here | ||
// In practice, we should only get here if layers saved from the daemon via `docker save` | ||
// are output compressed. | ||
layerReader, err := layer.Uncompressed() | ||
if err != nil { | ||
return 0, err | ||
|
@@ -450,18 +453,11 @@ func (s *Store) doDownloadLayersFor(identifier string) error { | |
return err | ||
} | ||
|
||
for idx, diffID := range configFile.RootFS.DiffIDs { | ||
for idx := range configFile.RootFS.DiffIDs { | ||
layerPath := filepath.Join(tmpDir, manifest[0].Layers[idx]) | ||
hash, err := v1.NewHash(diffID) | ||
if err != nil { | ||
if _, err := s.AddLayer(layerPath); err != nil { | ||
return err | ||
} | ||
layer := newPopulatedLayer(hash, layerPath, 1) | ||
fi, err := os.Stat(layerPath) | ||
if err != nil { | ||
return err | ||
} | ||
s.AddLayer(layer, hash, fi.Size()) | ||
} | ||
return nil | ||
} | ||
|
@@ -546,9 +542,39 @@ func (s *Store) findLayer(withHash v1.Hash) v1.Layer { | |
return aLayer.layer | ||
} | ||
|
||
func (s *Store) AddLayer(layer v1.Layer, withDiffID v1.Hash, withSize int64) { | ||
s.onDiskLayersByDiffID[withDiffID] = annotatedLayer{ | ||
func (s *Store) AddLayer(fromPath string) (v1.Layer, error) { | ||
layer, err := tarball.LayerFromFile(fromPath) | ||
if err != nil { | ||
return nil, err | ||
} | ||
diffID, err := layer.DiffID() | ||
if err != nil { | ||
return nil, err | ||
} | ||
var uncompressedSize int64 | ||
fileSize, err := func() (int64, error) { | ||
fi, err := os.Stat(fromPath) | ||
if err != nil { | ||
return -1, err | ||
} | ||
return fi.Size(), nil | ||
}() | ||
if err != nil { | ||
return nil, err | ||
} | ||
compressedSize, err := layer.Size() | ||
if err != nil { | ||
return nil, err | ||
} | ||
if fileSize == compressedSize { | ||
// the layer is compressed, we don't know the uncompressed size | ||
uncompressedSize = -1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the real fix |
||
} else { | ||
uncompressedSize = fileSize | ||
} | ||
s.onDiskLayersByDiffID[diffID] = annotatedLayer{ | ||
layer: layer, | ||
uncompressedSize: withSize, | ||
uncompressedSize: uncompressedSize, | ||
} | ||
return layer, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function relies on the daemon always outputting uncompressed layers, which is no longer true