From 936ef0c4c97737066ae1e028f04b5188022a91b8 Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Wed, 22 Nov 2017 12:55:36 -0500 Subject: [PATCH] Fix layer DNE with duplicate layers. Signed-off-by: Daniel Nephin --- daemon/build.go | 6 +----- integration/build/build_test.go | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/daemon/build.go b/daemon/build.go index 6a0081484a..3674ad9d28 100644 --- a/daemon/build.go +++ b/daemon/build.go @@ -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 } diff --git a/integration/build/build_test.go b/integration/build/build_test.go index cbaa7dc9bb..b447b623cc 100644 --- a/integration/build/build_test.go +++ b/integration/build/build_test.go @@ -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) +}