Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix pruning anon volume created from image config
Volumes created from the image config were not being pruned because the volume service did not think they were anonymous since the code to create passes along a generated name instead of letting the volume service generate it. This changes the code path to have the volume service generate the name instead of doing it ahead of time. Signed-off-by: Brian Goff <cpuguy83@gmail.com> (cherry picked from commit 146df5f) Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
- Loading branch information
Showing
5 changed files
with
91 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package build | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"io" | ||
"testing" | ||
|
||
"github.com/docker/docker/api/types" | ||
"github.com/docker/docker/client" | ||
"github.com/docker/docker/pkg/jsonmessage" | ||
"github.com/docker/docker/testutil/fakecontext" | ||
"gotest.tools/v3/assert" | ||
) | ||
|
||
// Do builds an image from the given context and returns the image ID. | ||
func Do(ctx context.Context, t *testing.T, client client.APIClient, buildCtx *fakecontext.Fake) string { | ||
resp, err := client.ImageBuild(ctx, buildCtx.AsTarReader(t), types.ImageBuildOptions{}) | ||
if resp.Body != nil { | ||
defer resp.Body.Close() | ||
} | ||
assert.NilError(t, err) | ||
img := GetImageIDFromBody(t, resp.Body) | ||
t.Cleanup(func() { | ||
client.ImageRemove(ctx, img, types.ImageRemoveOptions{Force: true}) | ||
}) | ||
return img | ||
} | ||
|
||
// GetImageIDFRommBody reads the image ID from the build response body. | ||
func GetImageIDFromBody(t *testing.T, body io.Reader) string { | ||
var ( | ||
jm jsonmessage.JSONMessage | ||
br types.BuildResult | ||
dec = json.NewDecoder(body) | ||
) | ||
for { | ||
err := dec.Decode(&jm) | ||
if err == io.EOF { | ||
break | ||
} | ||
assert.NilError(t, err) | ||
if jm.Aux == nil { | ||
continue | ||
} | ||
assert.NilError(t, json.Unmarshal(*jm.Aux, &br)) | ||
assert.Assert(t, br.ID != "", "could not read image ID from build output") | ||
break | ||
} | ||
io.Copy(io.Discard, body) | ||
return br.ID | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters