mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Fix layer DNE with duplicate layers.
Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
parent
fe8aac6f5a
commit
936ef0c4c9
2 changed files with 29 additions and 5 deletions
|
@ -71,11 +71,7 @@ func (rl *releaseableLayer) Commit(os string) (builder.ReleaseableLayer, error)
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if layer.IsEmpty(newLayer.DiffID()) {
|
||||
_, err := rl.layerStore.Release(newLayer)
|
||||
return &releaseableLayer{layerStore: rl.layerStore}, err
|
||||
}
|
||||
// TODO: An optimization woudld be to handle empty layers before returning
|
||||
return &releaseableLayer{layerStore: rl.layerStore, roLayer: newLayer}, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -169,3 +169,31 @@ func TestBuildMultiStageParentConfig(t *testing.T) {
|
|||
assert.Equal(t, "/foo/sub2", image.Config.WorkingDir)
|
||||
assert.Contains(t, image.Config.Env, "WHO=parent")
|
||||
}
|
||||
|
||||
func TestBuildWithEmptyLayers(t *testing.T) {
|
||||
dockerfile := `
|
||||
FROM busybox
|
||||
COPY 1/ /target/
|
||||
COPY 2/ /target/
|
||||
COPY 3/ /target/
|
||||
`
|
||||
ctx := context.Background()
|
||||
source := fakecontext.New(t, "",
|
||||
fakecontext.WithDockerfile(dockerfile),
|
||||
fakecontext.WithFile("1/a", "asdf"),
|
||||
fakecontext.WithFile("2/a", "asdf"),
|
||||
fakecontext.WithFile("3/a", "asdf"))
|
||||
defer source.Close()
|
||||
|
||||
apiclient := testEnv.APIClient()
|
||||
resp, err := apiclient.ImageBuild(ctx,
|
||||
source.AsTarReader(t),
|
||||
types.ImageBuildOptions{
|
||||
Remove: true,
|
||||
ForceRemove: true,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
_, err = io.Copy(ioutil.Discard, resp.Body)
|
||||
resp.Body.Close()
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue