Browse code

integration-cli: rewrite some tests depending on intermediate images

These tests used intermediate images (as produced by the classic builder)
as part of the test. When using BuildKit, such images are not produced,
and will only be in the build-cache.

From the tests, it looks like the extra checks were not critical to
verify the behavior, so let's simplify them to not depend on this.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Sebastiaan van Stijn authored on 2025/12/03 22:15:33
Showing 1 changed files
... ...
@@ -4614,60 +4614,39 @@ func (s *DockerCLIBuildSuite) TestBuildBuildTimeArgDefinitionWithNoEnvInjection(
4614 4614
 	}
4615 4615
 }
4616 4616
 
4617
+// TestBuildMultiStageArg verifies that build-args are scoped to the FROM
4618
+// they're defined in. Test for https://github.com/moby/moby/issues/31892
4617 4619
 func (s *DockerCLIBuildSuite) TestBuildMultiStageArg(c *testing.T) {
4618 4620
 	imgName := strings.ToLower(c.Name())
4619
-	dockerfile := `FROM busybox
4620
-    ARG foo=abc
4621
-    LABEL multifromtest=1
4622
-    RUN env > /out
4623
-    FROM busybox
4624
-    ARG bar=def
4625
-    RUN env > /out`
4626
-
4627
-	result := cli.BuildCmd(c, imgName, build.WithDockerfile(dockerfile))
4628
-	result.Assert(c, icmd.Success)
4629
-
4630
-	result = cli.DockerCmd(c, "images", "-q", "-f", "label=multifromtest=1")
4631
-	result.Assert(c, icmd.Success)
4632
-
4633
-	imgs := strings.Split(strings.TrimSpace(result.Stdout()), "\n")
4634
-	assert.Assert(c, is.Len(imgs, 1), `only one image with "multifromtest" label is expected`)
4621
+	const dockerfile = `FROM busybox
4622
+ARG stage_1_arg=AAAA
4623
+LABEL multifromtest=1
4624
+RUN env > /out
4625
+FROM busybox
4626
+ARG stage_2_arg=BBBB
4627
+RUN env > /out
4628
+`
4635 4629
 
4636
-	parentID := imgs[0]
4630
+	cli.BuildCmd(c, imgName, build.WithDockerfile(dockerfile))
4637 4631
 
4638
-	result = cli.DockerCmd(c, "run", "--rm", parentID, "cat", "/out")
4639
-	assert.Assert(c, is.Contains(result.Stdout(), "foo=abc"))
4640
-	result = cli.DockerCmd(c, "run", "--rm", imgName, "cat", "/out")
4641
-	assert.Assert(c, !strings.Contains(result.Stdout(), "foo"))
4642
-	assert.Assert(c, is.Contains(result.Stdout(), "bar=def"))
4632
+	result := cli.DockerCmd(c, "run", "--rm", imgName, "cat", "/out")
4633
+	assert.Check(c, !strings.Contains(result.Stdout(), "stage_1_arg"), "build arg leaked to second stage")
4634
+	assert.Assert(c, is.Contains(result.Stdout(), "stage_2_arg=BBBB"), "build arg not applied to second stage")
4643 4635
 }
4644 4636
 
4645 4637
 func (s *DockerCLIBuildSuite) TestBuildMultiStageGlobalArg(c *testing.T) {
4646 4638
 	imgName := strings.ToLower(c.Name())
4647
-	dockerfile := `ARG tag=nosuchtag
4648
-     FROM busybox:${tag}
4649
-     LABEL multifromtest2=1
4650
-     RUN env > /out
4651
-     FROM busybox:${tag}
4652
-     ARG tag
4653
-     RUN env > /out`
4654
-
4655
-	result := cli.BuildCmd(c, imgName,
4656
-		build.WithDockerfile(dockerfile),
4657
-		cli.WithFlags("--build-arg", "tag=latest"))
4658
-	result.Assert(c, icmd.Success)
4659
-
4660
-	result = cli.DockerCmd(c, "images", "-q", "-f", "label=multifromtest2=1")
4661
-	result.Assert(c, icmd.Success)
4639
+	const dockerfile = `ARG tag=nosuchtag
4640
+FROM busybox:${tag}
4641
+LABEL multifromtest2=1
4642
+RUN env > /out
4643
+FROM busybox:${tag}
4644
+ARG tag
4645
+RUN env > /out`
4662 4646
 
4663
-	imgs := strings.Split(strings.TrimSpace(result.Stdout()), "\n")
4664
-	assert.Assert(c, is.Len(imgs, 1), `only one image with "multifromtest" label is expected`)
4647
+	cli.BuildCmd(c, imgName, build.WithDockerfile(dockerfile), cli.WithFlags("--build-arg", "tag=latest"))
4665 4648
 
4666
-	parentID := imgs[0]
4667
-
4668
-	result = cli.DockerCmd(c, "run", "--rm", parentID, "cat", "/out")
4669
-	assert.Assert(c, !strings.Contains(result.Stdout(), "tag"))
4670
-	result = cli.DockerCmd(c, "run", "--rm", imgName, "cat", "/out")
4649
+	result := cli.DockerCmd(c, "run", "--rm", imgName, "cat", "/out")
4671 4650
 	assert.Assert(c, is.Contains(result.Stdout(), "tag=latest"))
4672 4651
 }
4673 4652