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) +}