Skip to content

Commit 84fa67d

Browse files
committed
Backport use docker-java 3.0.x for launch tests
Backport commit d439b73 to upgrade launch integration tests to use docker-java 3.0.x.
1 parent 7b3bedc commit 84fa67d

File tree

4 files changed

+27
-64
lines changed

4 files changed

+27
-64
lines changed

spring-boot-integration-tests/spring-boot-launch-script-tests/README.adoc

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,20 @@ This module contains integration tests for the default launch script that is use
44
to make a jar file fully executable on Linux. The tests use Docker to verify the
55
functionality in a variety of Linux distributions.
66

7-
== Setting up Docker
87

8+
9+
== Setting up Docker
910
The setup that's required varies depending on your operating system.
1011

12+
13+
1114
=== Docker on OS X
15+
Install Docker for Mac. See the https://docs.docker.com/docker-for-mac/install/[macOS
16+
installation instructions] for details.
1217

13-
The latest version of Docker runs as a native Mac application but isn't supported by
14-
docker-java. This means that you should use Docker Toolbox. See the
15-
https://docs.docker.com/engine/installation/mac/[OS X installation instructions] for
16-
details.
1718

18-
=== Docker on Linux
1919

20+
=== Docker on Linux
2021
Install Docker as appropriate for your Linux distribution. See the
2122
https://docs.docker.com/engine/installation/[Linux installation instructions] for more
2223
information.
@@ -30,32 +31,9 @@ $ sudo usermod -a -G docker awilkinson
3031
You may need to log out and back in again for this change to take affect and for your
3132
user to be able to connect to the daemon.
3233

33-
== Preparing to run the tests
34-
35-
Before running the tests, you must prepare your environment according to your operating
36-
system.
37-
38-
=== Preparation on OS X
3934

40-
The tests must be run in an environment where various environment variables including
41-
`DOCKER_HOST` and `DOCKER_CERT_PATH` have been set:
42-
43-
----
44-
$ eval $(docker-machine env default)
45-
----
46-
47-
=== Preparation on Linux
48-
49-
Docker Daemon's default configuration on Linux uses a Unix socket for communication.
50-
However, Docker's Java client uses HTTP by default. Docker Java's client can be configured
51-
to use the Unix socket via the `DOCKER_URL` environment variable:
52-
53-
----
54-
$ export DOCKER_URL=unix:///var/run/docker.sock
55-
----
5635

5736
== Running the tests
58-
5937
You're now ready to run the tests. Assuming that you're in the same directory as this
6038
README, the tests can be launched as follows:
6139

@@ -69,8 +47,9 @@ connection. Subsequent runs will be faster as the images are cached locally. You
6947
`docker images` to see a list of the cached images. Images created by these tests will be
7048
tagged with `spring-boot-it` prefix to easily distinguish them.
7149

72-
== Cleaning up
7350

51+
52+
== Cleaning up
7453
If you want to reclaim the disk space used by the cached images (at the expense of having
7554
to wait for them to be downloaded and rebuilt the next time you run the tests), you can
7655
use `docker images` to list the images and `docker rmi <image>` to delete them (look for

spring-boot-integration-tests/spring-boot-launch-script-tests/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
</organization>
1818
<properties>
1919
<main.basedir>${basedir}/../..</main.basedir>
20-
<jersey.version>2.11</jersey.version>
20+
<jersey.version>2.23.1</jersey.version>
2121
</properties>
2222
<dependencies>
2323
<dependency>
@@ -37,7 +37,7 @@
3737
<dependency>
3838
<groupId>com.github.docker-java</groupId>
3939
<artifactId>docker-java</artifactId>
40-
<version>2.2.3</version>
40+
<version>3.0.14</version>
4141
<scope>test</scope>
4242
</dependency>
4343
<dependency>

spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/java/org/springframework/boot/launchscript/SysVinitLaunchScriptIT.java

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -18,32 +18,32 @@
1818

1919
import java.io.File;
2020
import java.io.FileInputStream;
21-
import java.io.IOException;
2221
import java.io.InputStream;
2322
import java.util.ArrayList;
2423
import java.util.Arrays;
2524
import java.util.Collections;
25+
import java.util.HashSet;
2626
import java.util.List;
2727
import java.util.concurrent.TimeUnit;
2828
import java.util.regex.Pattern;
2929

30-
import javax.ws.rs.client.ClientRequestContext;
31-
import javax.ws.rs.client.ClientRequestFilter;
3230
import javax.ws.rs.client.Entity;
3331
import javax.ws.rs.client.WebTarget;
3432

3533
import com.github.dockerjava.api.DockerClient;
36-
import com.github.dockerjava.api.DockerClientException;
3734
import com.github.dockerjava.api.command.DockerCmd;
35+
import com.github.dockerjava.api.exception.DockerClientException;
3836
import com.github.dockerjava.api.model.BuildResponseItem;
3937
import com.github.dockerjava.api.model.Frame;
40-
import com.github.dockerjava.core.CompressArchiveUtil;
38+
import com.github.dockerjava.core.DefaultDockerClientConfig;
4139
import com.github.dockerjava.core.DockerClientBuilder;
4240
import com.github.dockerjava.core.DockerClientConfig;
4341
import com.github.dockerjava.core.command.AttachContainerResultCallback;
4442
import com.github.dockerjava.core.command.BuildImageResultCallback;
43+
import com.github.dockerjava.core.command.WaitContainerResultCallback;
44+
import com.github.dockerjava.core.util.CompressArchiveUtil;
4545
import com.github.dockerjava.jaxrs.AbstrSyncDockerCmdExec;
46-
import com.github.dockerjava.jaxrs.DockerCmdExecFactoryImpl;
46+
import com.github.dockerjava.jaxrs.JerseyDockerCmdExecFactory;
4747
import org.assertj.core.api.Condition;
4848
import org.junit.Test;
4949
import org.junit.runner.RunWith;
@@ -250,8 +250,10 @@ public void onNext(Frame item) {
250250
}
251251

252252
});
253-
resultCallback.awaitCompletion(60, TimeUnit.SECONDS).close();
254-
docker.waitContainerCmd(container).exec();
253+
resultCallback.awaitCompletion(60, TimeUnit.SECONDS);
254+
WaitContainerResultCallback waitContainerCallback = new WaitContainerResultCallback();
255+
docker.waitContainerCmd(container).exec(waitContainerCallback);
256+
waitContainerCallback.awaitCompletion(60, TimeUnit.SECONDS);
255257
return output.toString();
256258
}
257259
finally {
@@ -265,11 +267,10 @@ public void onNext(Frame item) {
265267
}
266268

267269
private DockerClient createClient() {
268-
DockerClientConfig config = DockerClientConfig.createDefaultConfigBuilder()
269-
.withVersion("1.19").build();
270-
DockerClient docker = DockerClientBuilder.getInstance(config)
270+
DockerClientConfig config = DefaultDockerClientConfig.createDefaultConfigBuilder()
271+
.withApiVersion("1.19").build();
272+
return DockerClientBuilder.getInstance(config)
271273
.withDockerCmdExecFactory(this.commandExecFactory).build();
272-
return docker;
273274
}
274275

275276
private String buildImage(DockerClient docker) {
@@ -325,7 +326,8 @@ private String extractImageId() {
325326
}
326327

327328
};
328-
docker.buildImageCmd(new File(dockerfile)).withTag(tag).exec(resultCallback);
329+
docker.buildImageCmd(new File(dockerfile))
330+
.withTags(new HashSet<String>(Arrays.asList(tag))).exec(resultCallback);
329331
String imageId = resultCallback.awaitImageId();
330332
return imageId;
331333
}
@@ -446,20 +448,7 @@ public void close() {
446448
}
447449

448450
private static final class SpringBootDockerCmdExecFactory
449-
extends DockerCmdExecFactoryImpl {
450-
451-
private SpringBootDockerCmdExecFactory() {
452-
withClientRequestFilters(new ClientRequestFilter() {
453-
454-
@Override
455-
public void filter(ClientRequestContext requestContext)
456-
throws IOException {
457-
// Workaround for https://go-review.googlesource.com/#/c/3821/
458-
requestContext.getHeaders().add("Connection", "close");
459-
}
460-
461-
});
462-
}
451+
extends JerseyDockerCmdExecFactory {
463452

464453
private CopyToContainerCmdExec createCopyToContainerCmdExec() {
465454
return new CopyToContainerCmdExec(getBaseResource(), getDockerClientConfig());
Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
<configuration>
2-
32
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
43
<encoder>
54
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
65
</encoder>
76
</appender>
8-
9-
<logger name="com.github.dockerjava.core.command" level="DEBUG"/>
10-
117
<root level="INFO">
128
<appender-ref ref="STDOUT" />
139
</root>
14-
1510
</configuration>

0 commit comments

Comments
 (0)