16
16
17
17
package com .google .cloud .tools .jib .api ;
18
18
19
- import static com .google .common .truth .Truth .assertThat ;
20
- import static org .junit .Assert .assertThrows ;
21
-
22
19
import com .google .cloud .tools .jib .Command ;
23
20
import com .google .cloud .tools .jib .api .buildplan .Platform ;
24
21
import com .google .cloud .tools .jib .blob .Blobs ;
@@ -60,6 +57,8 @@ public class JibIntegrationTest {
60
57
61
58
@ Rule public final TemporaryFolder temporaryFolder = new TemporaryFolder ();
62
59
60
+ private String imageToDelete ;
61
+
63
62
private final String dockerHost =
64
63
System .getenv ("DOCKER_IP" ) != null ? System .getenv ("DOCKER_IP" ) : "localhost" ;
65
64
@@ -104,8 +103,11 @@ public void setUp() {
104
103
}
105
104
106
105
@ After
107
- public void tearDown () {
106
+ public void tearDown () throws IOException , InterruptedException {
108
107
System .clearProperty ("sendCredentialsOverHttp" );
108
+ if (imageToDelete != null ) {
109
+ new Command ("docker" , "rmi" , imageToDelete ).run ();
110
+ }
109
111
}
110
112
111
113
@ Test
@@ -122,6 +124,7 @@ public void testBasic_helloWorld()
122
124
Assert .assertEquals ("Hello World\n " , pullAndRunBuiltImage (toImage ));
123
125
Assert .assertEquals (
124
126
"Hello World\n " , pullAndRunBuiltImage (toImage + "@" + jibContainer .getDigest ()));
127
+ imageToDelete = toImage ;
125
128
}
126
129
127
130
@ Test
@@ -138,20 +141,21 @@ public void testBasic_dockerDaemonBaseImage()
138
141
Assert .assertEquals ("Hello World\n " , pullAndRunBuiltImage (toImage ));
139
142
Assert .assertEquals (
140
143
"Hello World\n " , pullAndRunBuiltImage (toImage + "@" + jibContainer .getDigest ()));
144
+ imageToDelete = toImage ;
141
145
}
142
146
143
147
@ Test
144
148
public void testBasic_dockerDaemonBaseImageToDockerDaemon ()
145
149
throws IOException , InterruptedException , InvalidImageReferenceException , ExecutionException ,
146
150
RegistryException , CacheDirectoryCreationException {
151
+ String toImage = dockerHost + ":5000/docker-to-docker" ;
147
152
Jib .from (DockerDaemonImage .named (dockerHost + ":5000/busybox" ))
148
153
.setEntrypoint ("echo" , "Hello World" )
149
- .containerize (
150
- Containerizer .to (DockerDaemonImage .named (dockerHost + ":5000/docker-to-docker" )));
154
+ .containerize (Containerizer .to (DockerDaemonImage .named (toImage )));
151
155
152
- String output =
153
- new Command ("docker" , "run" , "--rm" , dockerHost + ":5000/docker-to-docker" ).run ();
156
+ String output = new Command ("docker" , "run" , "--rm" , toImage ).run ();
154
157
Assert .assertEquals ("Hello World\n " , output );
158
+ imageToDelete = toImage ;
155
159
}
156
160
157
161
@ Test
@@ -171,6 +175,7 @@ public void testBasic_tarBaseImage_dockerSavedCommand()
171
175
Assert .assertEquals ("Hello World\n " , pullAndRunBuiltImage (toImage ));
172
176
Assert .assertEquals (
173
177
"Hello World\n " , pullAndRunBuiltImage (toImage + "@" + jibContainer .getDigest ()));
178
+ imageToDelete = toImage ;
174
179
}
175
180
176
181
@ Test
@@ -233,6 +238,7 @@ public void testBasic_tarBaseImage_jibImageToDockerDaemon()
233
238
Assert .assertEquals ("Hello World\n " , pullAndRunBuiltImage (toImage ));
234
239
Assert .assertEquals (
235
240
"Hello World\n " , pullAndRunBuiltImage (toImage + "@" + jibContainer .getDigest ()));
241
+ imageToDelete = toImage ;
236
242
}
237
243
238
244
@ Test
@@ -311,59 +317,14 @@ public void testScratch_multiPlatform()
311
317
public void testBasic_jibImageToDockerDaemon ()
312
318
throws IOException , InterruptedException , InvalidImageReferenceException , ExecutionException ,
313
319
RegistryException , CacheDirectoryCreationException {
320
+ String toImage = dockerHost + ":5000/docker-to-docker" ;
314
321
Jib .from (DockerDaemonImage .named (dockerHost + ":5000/busybox" ))
315
322
.setEntrypoint ("echo" , "Hello World" )
316
- .containerize (
317
- Containerizer .to (DockerDaemonImage .named (dockerHost + ":5000/docker-to-docker" )));
323
+ .containerize (Containerizer .to (DockerDaemonImage .named (toImage )));
318
324
319
- String output =
320
- new Command ("docker" , "run" , "--rm" , dockerHost + ":5000/docker-to-docker" ).run ();
325
+ String output = new Command ("docker" , "run" , "--rm" , toImage ).run ();
321
326
Assert .assertEquals ("Hello World\n " , output );
322
- }
323
-
324
- @ Test
325
- public void testBasicMultiPlatform_toDockerDaemon ()
326
- throws IOException , InterruptedException , ExecutionException , RegistryException ,
327
- CacheDirectoryCreationException , InvalidImageReferenceException {
328
- Jib .from (
329
- RegistryImage .named (
330
- "busybox@sha256:4f47c01fa91355af2865ac10fef5bf6ec9c7f42ad2321377c21e844427972977" ))
331
- .setPlatforms (
332
- ImmutableSet .of (new Platform ("arm64" , "linux" ), new Platform ("amd64" , "linux" )))
333
- .setEntrypoint ("echo" , "Hello World" )
334
- .containerize (
335
- Containerizer .to (
336
- DockerDaemonImage .named (dockerHost + ":5000/docker-daemon-multi-platform" ))
337
- .setAllowInsecureRegistries (true ));
338
-
339
- String output =
340
- new Command ("docker" , "run" , "--rm" , dockerHost + ":5000/docker-daemon-multi-platform" )
341
- .run ();
342
- Assert .assertEquals ("Hello World\n " , output );
343
- }
344
-
345
- @ Test
346
- public void testBasicMultiPlatform_toDockerDaemon_noMatchingImage () {
347
- ExecutionException exception =
348
- assertThrows (
349
- ExecutionException .class ,
350
- () ->
351
- Jib .from (
352
- RegistryImage .named (
353
- "busybox@sha256:4f47c01fa91355af2865ac10fef5bf6ec9c7f42ad2321377c21e844427972977" ))
354
- .setPlatforms (
355
- ImmutableSet .of (
356
- new Platform ("s390x" , "linux" ), new Platform ("arm" , "linux" )))
357
- .setEntrypoint ("echo" , "Hello World" )
358
- .containerize (
359
- Containerizer .to (
360
- DockerDaemonImage .named (
361
- dockerHost + ":5000/docker-daemon-multi-platform" ))
362
- .setAllowInsecureRegistries (true )));
363
- assertThat (exception )
364
- .hasCauseThat ()
365
- .hasMessageThat ()
366
- .startsWith ("The configured platforms don't match the Docker Engine's OS and architecture" );
327
+ imageToDelete = toImage ;
367
328
}
368
329
369
330
@ Test
0 commit comments