fix bug that gen layer tar contains duplicated files #4428
Merged
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.
I run into a problem that randomly happen, image build and pushed by buildkit cannot be pulled by containerd or docker.
containerd complains that
failed to convert whiteout file "etc/.wh.hosts": file exists: unknown
.docker complains that
failed to register layer: Error processing tar file(exit status 1): archive/tar: invalid tar header
,or
failed to register layer: Error processing tar file(duplicates of file paths not supported)
.After dig a while, I found that layer which unpack fail contains duplicated files:
According to code at https://github.com/moby/buildkit/blob/master/vendor/github.com/containerd/containerd/content/local/store.go#L594 , content writer always use the already written content, this is ok for pulling content from registry, but when pushing image, content generated by snapshot comparing, in case previous cw partially write and fail, the following build will use the cached snapshot and generate layer content which append to the existing content.
In pushing case, if cw write or commit failed, we should truncate the already written file.
For guys want to know why cw write failed, there is a buildkitd log indicate the reason: