Fix layer DNE with duplicate layers
| ... | ... |
@@ -71,11 +71,7 @@ func (rl *releaseableLayer) Commit(os string) (builder.ReleaseableLayer, error) |
| 71 | 71 |
if err != nil {
|
| 72 | 72 |
return nil, err |
| 73 | 73 |
} |
| 74 |
- |
|
| 75 |
- if layer.IsEmpty(newLayer.DiffID()) {
|
|
| 76 |
- _, err := rl.layerStore.Release(newLayer) |
|
| 77 |
- return &releaseableLayer{layerStore: rl.layerStore}, err
|
|
| 78 |
- } |
|
| 74 |
+ // TODO: An optimization woudld be to handle empty layers before returning |
|
| 79 | 75 |
return &releaseableLayer{layerStore: rl.layerStore, roLayer: newLayer}, nil
|
| 80 | 76 |
} |
| 81 | 77 |
|
| ... | ... |
@@ -169,3 +169,31 @@ func TestBuildMultiStageParentConfig(t *testing.T) {
|
| 169 | 169 |
assert.Equal(t, "/foo/sub2", image.Config.WorkingDir) |
| 170 | 170 |
assert.Contains(t, image.Config.Env, "WHO=parent") |
| 171 | 171 |
} |
| 172 |
+ |
|
| 173 |
+func TestBuildWithEmptyLayers(t *testing.T) {
|
|
| 174 |
+ dockerfile := ` |
|
| 175 |
+ FROM busybox |
|
| 176 |
+ COPY 1/ /target/ |
|
| 177 |
+ COPY 2/ /target/ |
|
| 178 |
+ COPY 3/ /target/ |
|
| 179 |
+ ` |
|
| 180 |
+ ctx := context.Background() |
|
| 181 |
+ source := fakecontext.New(t, "", |
|
| 182 |
+ fakecontext.WithDockerfile(dockerfile), |
|
| 183 |
+ fakecontext.WithFile("1/a", "asdf"),
|
|
| 184 |
+ fakecontext.WithFile("2/a", "asdf"),
|
|
| 185 |
+ fakecontext.WithFile("3/a", "asdf"))
|
|
| 186 |
+ defer source.Close() |
|
| 187 |
+ |
|
| 188 |
+ apiclient := testEnv.APIClient() |
|
| 189 |
+ resp, err := apiclient.ImageBuild(ctx, |
|
| 190 |
+ source.AsTarReader(t), |
|
| 191 |
+ types.ImageBuildOptions{
|
|
| 192 |
+ Remove: true, |
|
| 193 |
+ ForceRemove: true, |
|
| 194 |
+ }) |
|
| 195 |
+ require.NoError(t, err) |
|
| 196 |
+ _, err = io.Copy(ioutil.Discard, resp.Body) |
|
| 197 |
+ resp.Body.Close() |
|
| 198 |
+ require.NoError(t, err) |
|
| 199 |
+} |