@@ -29,100 +29,104 @@ import (
29
29
)
30
30
31
31
func TestLocalComposeBuild (t * testing.T ) {
32
- c := NewParallelCLI (t )
33
32
34
- t .Run ("build named and unnamed images" , func (t * testing.T ) {
35
- // ensure local test run does not reuse previously build image
36
- c .RunDockerOrExitError (t , "rmi" , "build-test-nginx" )
37
- c .RunDockerOrExitError (t , "rmi" , "custom-nginx" )
33
+ for _ , env := range []string {"DOCKER_BUILDKIT=0" , "DOCKER_BUILDKIT=1" } {
34
+ c := NewCLI (t , WithEnv (env ))
38
35
39
- res := c .RunDockerComposeCmd (t , "--project-directory" , "fixtures/build-test" , "build" )
36
+ t .Run (env + " build named and unnamed images" , func (t * testing.T ) {
37
+ // ensure local test run does not reuse previously build image
38
+ c .RunDockerOrExitError (t , "rmi" , "build-test-nginx" )
39
+ c .RunDockerOrExitError (t , "rmi" , "custom-nginx" )
40
40
41
- res .Assert (t , icmd.Expected {Out : "COPY static /usr/share/nginx/html" })
42
- c .RunDockerCmd (t , "image" , "inspect" , "build-test-nginx" )
43
- c .RunDockerCmd (t , "image" , "inspect" , "custom-nginx" )
44
- })
41
+ res := c .RunDockerComposeCmd (t , "--project-directory" , "fixtures/build-test" , "build" )
45
42
46
- t . Run ( "build with build-arg" , func ( t * testing. T ) {
47
- // ensure local test run does not reuse previously build image
48
- c . RunDockerOrExitError (t , "rmi " , "build-test -nginx" )
49
- c . RunDockerOrExitError ( t , "rmi" , "custom-nginx" )
43
+ res . Assert ( t , icmd. Expected { Out : "COPY static /usr/share/nginx/html" })
44
+ c . RunDockerCmd ( t , "image" , "inspect" , " build-test-nginx" )
45
+ c . RunDockerCmd (t , "image " , "inspect" , "custom -nginx" )
46
+ } )
50
47
51
- c .RunDockerComposeCmd (t , "--project-directory" , "fixtures/build-test" , "build" , "--build-arg" , "FOO=BAR" )
48
+ t .Run (env + " build with build-arg" , func (t * testing.T ) {
49
+ // ensure local test run does not reuse previously build image
50
+ c .RunDockerOrExitError (t , "rmi" , "build-test-nginx" )
51
+ c .RunDockerOrExitError (t , "rmi" , "custom-nginx" )
52
52
53
- res := c .RunDockerCmd (t , "image" , "inspect" , "build-test-nginx" )
54
- res .Assert (t , icmd.Expected {Out : `"FOO": "BAR"` })
55
- })
53
+ c .RunDockerComposeCmd (t , "--project-directory" , "fixtures/build-test" , "build" , "--build-arg" , "FOO=BAR" )
56
54
57
- t .Run ("build with build-arg set by env" , func (t * testing.T ) {
58
- // ensure local test run does not reuse previously build image
59
- c .RunDockerOrExitError (t , "rmi" , "build-test-nginx" )
60
- c .RunDockerOrExitError (t , "rmi" , "custom-nginx" )
61
-
62
- icmd .RunCmd (c .NewDockerComposeCmd (t ,
63
- "--project-directory" ,
64
- "fixtures/build-test" ,
65
- "build" ,
66
- "--build-arg" ,
67
- "FOO" ),
68
- func (cmd * icmd.Cmd ) {
69
- cmd .Env = append (cmd .Env , "FOO=BAR" )
70
- })
55
+ res := c .RunDockerCmd (t , "image" , "inspect" , "build-test-nginx" )
56
+ res .Assert (t , icmd.Expected {Out : `"FOO": "BAR"` })
57
+ })
71
58
72
- res := c .RunDockerCmd (t , "image" , "inspect" , "build-test-nginx" )
73
- res .Assert (t , icmd.Expected {Out : `"FOO": "BAR"` })
74
- })
59
+ t .Run (env + " build with build-arg set by env" , func (t * testing.T ) {
60
+ // ensure local test run does not reuse previously build image
61
+ c .RunDockerOrExitError (t , "rmi" , "build-test-nginx" )
62
+ c .RunDockerOrExitError (t , "rmi" , "custom-nginx" )
63
+
64
+ icmd .RunCmd (c .NewDockerComposeCmd (t ,
65
+ "--project-directory" ,
66
+ "fixtures/build-test" ,
67
+ "build" ,
68
+ "--build-arg" ,
69
+ "FOO" ),
70
+ func (cmd * icmd.Cmd ) {
71
+ cmd .Env = append (cmd .Env , "FOO=BAR" )
72
+ })
73
+
74
+ res := c .RunDockerCmd (t , "image" , "inspect" , "build-test-nginx" )
75
+ res .Assert (t , icmd.Expected {Out : `"FOO": "BAR"` })
76
+ })
75
77
76
- t .Run (" build with multiple build-args " , func (t * testing.T ) {
77
- // ensure local test run does not reuse previously build image
78
- c .RunDockerOrExitError (t , "rmi" , "-f" , "multi-args-multiargs" )
79
- cmd := c .NewDockerComposeCmd (t , "--project-directory" , "fixtures/build-test/multi-args" , "build" )
78
+ t .Run (env + " build with multiple build-args " , func (t * testing.T ) {
79
+ // ensure local test run does not reuse previously build image
80
+ c .RunDockerOrExitError (t , "rmi" , "-f" , "multi-args-multiargs" )
81
+ cmd := c .NewDockerComposeCmd (t , "--project-directory" , "fixtures/build-test/multi-args" , "build" )
80
82
81
- icmd .RunCmd (cmd , func (cmd * icmd.Cmd ) {
82
- cmd .Env = append (cmd .Env , "DOCKER_BUILDKIT=0" )
83
+ icmd .RunCmd (cmd , func (cmd * icmd.Cmd ) {
84
+ cmd .Env = append (cmd .Env , "DOCKER_BUILDKIT=0" )
85
+ })
86
+
87
+ res := c .RunDockerCmd (t , "image" , "inspect" , "multi-args-multiargs" )
88
+ res .Assert (t , icmd.Expected {Out : `"RESULT": "SUCCESS"` })
83
89
})
84
90
85
- res := c . RunDockerCmd ( t , "image" , "inspect" , "multi-args-multiargs" )
86
- res . Assert (t , icmd. Expected { Out : `"RESULT": "SUCCESS"` } )
87
- } )
91
+ t . Run ( env + " build as part of up" , func ( t * testing. T ) {
92
+ c . RunDockerOrExitError (t , "rmi" , "build-test-nginx" )
93
+ c . RunDockerOrExitError ( t , "rmi" , "custom-nginx" )
88
94
89
- t .Run ("build as part of up" , func (t * testing.T ) {
90
- c .RunDockerOrExitError (t , "rmi" , "build-test-nginx" )
91
- c .RunDockerOrExitError (t , "rmi" , "custom-nginx" )
95
+ res := c .RunDockerComposeCmd (t , "--project-directory" , "fixtures/build-test" , "up" , "-d" )
96
+ t .Cleanup (func () {
97
+ c .RunDockerComposeCmd (t , "--project-directory" , "fixtures/build-test" , "down" )
98
+ })
92
99
93
- res := c .RunDockerComposeCmd (t , "--project-directory" , "fixtures/build-test" , "up" , "-d" )
94
- t .Cleanup (func () {
95
- c .RunDockerComposeCmd (t , "--project-directory" , "fixtures/build-test" , "down" )
96
- })
100
+ res .Assert (t , icmd.Expected {Out : "COPY static /usr/share/nginx/html" })
101
+ res .Assert (t , icmd.Expected {Out : "COPY static2 /usr/share/nginx/html" })
97
102
98
- res . Assert (t , icmd. Expected { Out : "COPY static /usr/share/nginx/html" } )
99
- res .Assert (t , icmd. Expected { Out : "COPY static2 /usr/share/nginx/html" } )
103
+ output := HTTPGetWithRetry (t , "http://localhost:8070" , http . StatusOK , 2 * time . Second , 20 * time . Second )
104
+ assert .Assert (t , strings . Contains ( output , "Hello from Nginx container" ) )
100
105
101
- output := HTTPGetWithRetry (t , "http://localhost:8070" , http .StatusOK , 2 * time .Second , 20 * time .Second )
102
- assert .Assert (t , strings .Contains (output , "Hello from Nginx container" ))
106
+ c .RunDockerCmd (t , "image" , "inspect" , "build-test-nginx" )
107
+ c .RunDockerCmd (t , "image" , "inspect" , "custom-nginx" )
108
+ })
103
109
104
- c .RunDockerCmd (t , "image" , "inspect" , "build-test-nginx" )
105
- c .RunDockerCmd (t , "image" , "inspect" , "custom-nginx" )
106
- })
110
+ t .Run (env + " no rebuild when up again" , func (t * testing.T ) {
111
+ res := c .RunDockerComposeCmd (t , "--project-directory" , "fixtures/build-test" , "up" , "-d" )
107
112
108
- t . Run ( "no rebuild when up again" , func ( t * testing. T ) {
109
- res := c . RunDockerComposeCmd ( t , "--project-directory" , "fixtures/build-test" , "up" , "-d" )
113
+ assert . Assert ( t , ! strings . Contains ( res . Stdout (), "COPY static" ), res . Stdout ())
114
+ } )
110
115
111
- assert . Assert ( t , ! strings . Contains ( res . Stdout (), "COPY static" ), res . Stdout ())
112
- } )
116
+ t . Run ( env + " rebuild when up --build" , func ( t * testing. T ) {
117
+ res := c . RunDockerComposeCmd ( t , "--workdir" , "fixtures/build-test" , "up" , "-d" , "--build" )
113
118
114
- t .Run ("rebuild when up --build" , func (t * testing.T ) {
115
- res := c .RunDockerComposeCmd (t , "--workdir" , "fixtures/build-test" , "up" , "-d" , "--build" )
119
+ res .Assert (t , icmd.Expected {Out : "COPY static /usr/share/nginx/html" })
120
+ res .Assert (t , icmd.Expected {Out : "COPY static2 /usr/share/nginx/html" })
121
+ })
116
122
117
- res .Assert (t , icmd.Expected {Out : "COPY static /usr/share/nginx/html" })
118
- res .Assert (t , icmd.Expected {Out : "COPY static2 /usr/share/nginx/html" })
119
- })
123
+ t .Run (env + " cleanup build project" , func (t * testing.T ) {
124
+ c .RunDockerComposeCmd (t , "--project-directory" , "fixtures/build-test" , "down" )
125
+ c .RunDockerCmd (t , "rmi" , "build-test-nginx" )
126
+ c .RunDockerCmd (t , "rmi" , "custom-nginx" )
127
+ })
128
+ }
120
129
121
- t .Run ("cleanup build project" , func (t * testing.T ) {
122
- c .RunDockerComposeCmd (t , "--project-directory" , "fixtures/build-test" , "down" )
123
- c .RunDockerCmd (t , "rmi" , "build-test-nginx" )
124
- c .RunDockerCmd (t , "rmi" , "custom-nginx" )
125
- })
126
130
}
127
131
128
132
func TestBuildSSH (t * testing.T ) {
0 commit comments