Browse code

integration/internal/build: let Do accept ImageBuildOptions

Tests that use the build helper currently cannot influence the build
beyond providing the context (e.g. they cannot set Tags, BuildArgs, or
Version).

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>

Paweł Gronowski authored on 2026/05/09 05:26:43
Showing 7 changed files
... ...
@@ -294,8 +294,8 @@ func TestExecUser(t *testing.T) {
294 294
 		container.WithTty(true),
295 295
 		container.WithUser("1:1"),
296 296
 	}
297
-	withoutEtcGroups := container.WithImage(build.Do(ctx, t, apiClient, fakecontext.New(t, "", fakecontext.WithDockerfile("FROM busybox\nRUN rm /etc/group"))))
298
-	withoutEtcPasswd := container.WithImage(build.Do(ctx, t, apiClient, fakecontext.New(t, "", fakecontext.WithDockerfile("FROM busybox\nRUN rm /etc/passwd"))))
297
+	withoutEtcGroups := container.WithImage(build.Do(ctx, t, apiClient, fakecontext.New(t, "", fakecontext.WithDockerfile("FROM busybox\nRUN rm /etc/group")), client.ImageBuildOptions{}))
298
+	withoutEtcPasswd := container.WithImage(build.Do(ctx, t, apiClient, fakecontext.New(t, "", fakecontext.WithDockerfile("FROM busybox\nRUN rm /etc/passwd")), client.ImageBuildOptions{}))
299 299
 
300 300
 	withUser := func(user string) func(options *client.ExecCreateOptions) {
301 301
 		return func(options *client.ExecCreateOptions) { options.User = user }
... ...
@@ -22,7 +22,7 @@ func TestAPIImagesHistory(t *testing.T) {
22 22
 
23 23
 	dockerfile := "FROM busybox\nENV FOO bar"
24 24
 
25
-	imgID := build.Do(ctx, t, apiClient, fakecontext.New(t, t.TempDir(), fakecontext.WithDockerfile(dockerfile)))
25
+	imgID := build.Do(ctx, t, apiClient, fakecontext.New(t, t.TempDir(), fakecontext.WithDockerfile(dockerfile)), client.ImageBuildOptions{})
26 26
 
27 27
 	res, err := apiClient.ImageHistory(ctx, imgID)
28 28
 	assert.NilError(t, err)
... ...
@@ -191,7 +191,7 @@ func TestAPIImagesDelete(t *testing.T) {
191 191
 ENV FOO=bar`))
192 192
 	defer buildCtx.Close()
193 193
 
194
-	imgID := build.Do(ctx, t, apiClient, buildCtx)
194
+	imgID := build.Do(ctx, t, apiClient, buildCtx, client.ImageBuildOptions{})
195 195
 
196 196
 	// Cleanup always runs
197 197
 	defer func() {
... ...
@@ -489,7 +489,7 @@ func TestSaveDirectoryPermissions(t *testing.T) {
489 489
 RUN adduser -D user && mkdir -p /opt/a/b && chown -R user:user /opt/a
490 490
 RUN touch /opt/a/b/c && chown user:user /opt/a/b/c`
491 491
 
492
-	imgID := build.Do(ctx, t, apiClient, fakecontext.New(t, t.TempDir(), fakecontext.WithDockerfile(dockerfile)))
492
+	imgID := build.Do(ctx, t, apiClient, fakecontext.New(t, t.TempDir(), fakecontext.WithDockerfile(dockerfile)), client.ImageBuildOptions{})
493 493
 
494 494
 	rdr, err := apiClient.ImageSave(ctx, []string{imgID})
495 495
 	assert.NilError(t, err)
... ...
@@ -17,9 +17,10 @@ import (
17 17
 	"gotest.tools/v3/assert"
18 18
 )
19 19
 
20
-// Do builds an image from the given context and returns the image ID.
21
-func Do(ctx context.Context, t *testing.T, apiClient client.APIClient, buildCtx *fakecontext.Fake) string {
22
-	resp, err := apiClient.ImageBuild(ctx, buildCtx.AsTarReader(t), client.ImageBuildOptions{})
20
+// Do builds an image from the given context with the supplied options
21
+// and returns the image ID.
22
+func Do(ctx context.Context, t *testing.T, apiClient client.APIClient, buildCtx *fakecontext.Fake, options client.ImageBuildOptions) string {
23
+	resp, err := apiClient.ImageBuild(ctx, buildCtx.AsTarReader(t), options)
23 24
 	assert.NilError(t, err)
24 25
 	if resp.Body != nil {
25 26
 		defer resp.Body.Close()
... ...
@@ -2272,7 +2272,7 @@ func TestPublishAllWithNilPortBindings(t *testing.T) {
2272 2272
 	c := testEnv.APIClient()
2273 2273
 
2274 2274
 	imgWithExpose := container.WithImage(build.Do(ctx, t, c,
2275
-		fakecontext.New(t, "", fakecontext.WithDockerfile("FROM busybox\nEXPOSE 80/tcp\n"))))
2275
+		fakecontext.New(t, "", fakecontext.WithDockerfile("FROM busybox\nEXPOSE 80/tcp\n")), client.ImageBuildOptions{}))
2276 2276
 
2277 2277
 	_ = container.Run(ctx, t, c,
2278 2278
 		container.WithAutoRemove,
... ...
@@ -338,7 +338,7 @@ func TestVolumePruneAnonFromImage(t *testing.T) {
338 338
 	dockerfile := `FROM busybox
339 339
 VOLUME ` + volDest
340 340
 
341
-	img := build.Do(ctx, t, apiClient, fakecontext.New(t, "", fakecontext.WithDockerfile(dockerfile)))
341
+	img := build.Do(ctx, t, apiClient, fakecontext.New(t, "", fakecontext.WithDockerfile(dockerfile)), client.ImageBuildOptions{})
342 342
 
343 343
 	id := container.Create(ctx, t, apiClient, container.WithImage(img))
344 344
 	defer apiClient.ContainerRemove(ctx, id, client.ContainerRemoveOptions{})