MCPcopy
hub / github.com/docker/compose / TestLocalComposeBuild

Function TestLocalComposeBuild

pkg/e2e/build_test.go:36–144  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

34)
35
36func TestLocalComposeBuild(t *testing.T) {
37 for _, env := range []string{"DOCKER_BUILDKIT=0", "DOCKER_BUILDKIT=1"} {
38 c := NewCLI(t, WithEnv(strings.Split(env, ",")...))
39
40 t.Run(env+" build named and unnamed images", func(t *testing.T) {
41 // ensure local test run does not reuse previously build image
42 c.RunDockerOrExitError(t, "rmi", "-f", "build-test-nginx")
43 c.RunDockerOrExitError(t, "rmi", "-f", "custom-nginx")
44
45 res := c.RunDockerComposeCmd(t, "--project-directory", "fixtures/build-test", "build")
46
47 res.Assert(t, icmd.Expected{Out: "COPY static /usr/share/nginx/html"})
48 c.RunDockerCmd(t, "image", "inspect", "build-test-nginx")
49 c.RunDockerCmd(t, "image", "inspect", "custom-nginx")
50 })
51
52 t.Run(env+" build with build-arg", func(t *testing.T) {
53 // ensure local test run does not reuse previously build image
54 c.RunDockerOrExitError(t, "rmi", "-f", "build-test-nginx")
55 c.RunDockerOrExitError(t, "rmi", "-f", "custom-nginx")
56
57 c.RunDockerComposeCmd(t, "--project-directory", "fixtures/build-test", "build", "--build-arg", "FOO=BAR")
58
59 res := c.RunDockerCmd(t, "image", "inspect", "build-test-nginx")
60 res.Assert(t, icmd.Expected{Out: `"FOO": "BAR"`})
61 })
62
63 t.Run(env+" build with build-arg set by env", func(t *testing.T) {
64 // ensure local test run does not reuse previously build image
65 c.RunDockerOrExitError(t, "rmi", "-f", "build-test-nginx")
66 c.RunDockerOrExitError(t, "rmi", "-f", "custom-nginx")
67
68 icmd.RunCmd(c.NewDockerComposeCmd(t,
69 "--project-directory",
70 "fixtures/build-test",
71 "build",
72 "--build-arg",
73 "FOO"),
74 func(cmd *icmd.Cmd) {
75 cmd.Env = append(cmd.Env, "FOO=BAR")
76 }).Assert(t, icmd.Success)
77
78 res := c.RunDockerCmd(t, "image", "inspect", "build-test-nginx")
79 res.Assert(t, icmd.Expected{Out: `"FOO": "BAR"`})
80 })
81
82 t.Run(env+" build with multiple build-args ", func(t *testing.T) {
83 // ensure local test run does not reuse previously build image
84 c.RunDockerOrExitError(t, "rmi", "-f", "multi-args-multiargs")
85 cmd := c.NewDockerComposeCmd(t, "--project-directory", "fixtures/build-test/multi-args", "build")
86
87 icmd.RunCmd(cmd, func(cmd *icmd.Cmd) {
88 cmd.Env = append(cmd.Env, "DOCKER_BUILDKIT=0")
89 })
90
91 res := c.RunDockerCmd(t, "image", "inspect", "multi-args-multiargs")
92 res.Assert(t, icmd.Expected{Out: `"RESULT": "SUCCESS"`})
93 })

Callers

nothing calls this directly

Calls 8

RunDockerOrExitErrorMethod · 0.95
RunDockerComposeCmdMethod · 0.95
RunDockerCmdMethod · 0.95
NewDockerComposeCmdMethod · 0.95
NewCLIFunction · 0.85
WithEnvFunction · 0.85
HTTPGetWithRetryFunction · 0.85
RunCmdMethod · 0.80

Tested by

no test coverage detected