From 84fa67d33e3484c23cd66bd4b0116ca3518a64fa Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Wed, 10 Jan 2018 11:56:09 -0800 Subject: [PATCH] Backport use docker-java 3.0.x for launch tests Backport commit d439b73758 to upgrade launch integration tests to use docker-java 3.0.x. --- .../README.adoc | 39 ++++------------- .../spring-boot-launch-script-tests/pom.xml | 4 +- .../launchscript/SysVinitLaunchScriptIT.java | 43 +++++++------------ .../src/test/resources/logback.xml | 5 --- 4 files changed, 27 insertions(+), 64 deletions(-) diff --git a/spring-boot-integration-tests/spring-boot-launch-script-tests/README.adoc b/spring-boot-integration-tests/spring-boot-launch-script-tests/README.adoc index 84d96700bd..5b0a46a742 100644 --- a/spring-boot-integration-tests/spring-boot-launch-script-tests/README.adoc +++ b/spring-boot-integration-tests/spring-boot-launch-script-tests/README.adoc @@ -4,19 +4,20 @@ This module contains integration tests for the default launch script that is use to make a jar file fully executable on Linux. The tests use Docker to verify the functionality in a variety of Linux distributions. -== Setting up Docker + +== Setting up Docker The setup that's required varies depending on your operating system. + + === Docker on OS X +Install Docker for Mac. See the https://docs.docker.com/docker-for-mac/install/[macOS +installation instructions] for details. -The latest version of Docker runs as a native Mac application but isn't supported by -docker-java. This means that you should use Docker Toolbox. See the -https://docs.docker.com/engine/installation/mac/[OS X installation instructions] for -details. -=== Docker on Linux +=== Docker on Linux Install Docker as appropriate for your Linux distribution. See the https://docs.docker.com/engine/installation/[Linux installation instructions] for more information. @@ -30,32 +31,9 @@ $ sudo usermod -a -G docker awilkinson You may need to log out and back in again for this change to take affect and for your user to be able to connect to the daemon. -== Preparing to run the tests - -Before running the tests, you must prepare your environment according to your operating -system. - -=== Preparation on OS X -The tests must be run in an environment where various environment variables including -`DOCKER_HOST` and `DOCKER_CERT_PATH` have been set: - ----- -$ eval $(docker-machine env default) ----- - -=== Preparation on Linux - -Docker Daemon's default configuration on Linux uses a Unix socket for communication. -However, Docker's Java client uses HTTP by default. Docker Java's client can be configured -to use the Unix socket via the `DOCKER_URL` environment variable: - ----- -$ export DOCKER_URL=unix:///var/run/docker.sock ----- == Running the tests - You're now ready to run the tests. Assuming that you're in the same directory as this README, the tests can be launched as follows: @@ -69,8 +47,9 @@ connection. Subsequent runs will be faster as the images are cached locally. You `docker images` to see a list of the cached images. Images created by these tests will be tagged with `spring-boot-it` prefix to easily distinguish them. -== Cleaning up + +== Cleaning up If you want to reclaim the disk space used by the cached images (at the expense of having to wait for them to be downloaded and rebuilt the next time you run the tests), you can use `docker images` to list the images and `docker rmi ` to delete them (look for diff --git a/spring-boot-integration-tests/spring-boot-launch-script-tests/pom.xml b/spring-boot-integration-tests/spring-boot-launch-script-tests/pom.xml index e775a1ec33..c6a4c986a8 100644 --- a/spring-boot-integration-tests/spring-boot-launch-script-tests/pom.xml +++ b/spring-boot-integration-tests/spring-boot-launch-script-tests/pom.xml @@ -17,7 +17,7 @@ ${basedir}/../.. - 2.11 + 2.23.1 @@ -37,7 +37,7 @@ com.github.docker-java docker-java - 2.2.3 + 3.0.14 test diff --git a/spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/java/org/springframework/boot/launchscript/SysVinitLaunchScriptIT.java b/spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/java/org/springframework/boot/launchscript/SysVinitLaunchScriptIT.java index cc94762b74..42860f75e4 100644 --- a/spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/java/org/springframework/boot/launchscript/SysVinitLaunchScriptIT.java +++ b/spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/java/org/springframework/boot/launchscript/SysVinitLaunchScriptIT.java @@ -18,32 +18,32 @@ package org.springframework.boot.launchscript; import java.io.File; import java.io.FileInputStream; -import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.HashSet; import java.util.List; import java.util.concurrent.TimeUnit; import java.util.regex.Pattern; -import javax.ws.rs.client.ClientRequestContext; -import javax.ws.rs.client.ClientRequestFilter; import javax.ws.rs.client.Entity; import javax.ws.rs.client.WebTarget; import com.github.dockerjava.api.DockerClient; -import com.github.dockerjava.api.DockerClientException; import com.github.dockerjava.api.command.DockerCmd; +import com.github.dockerjava.api.exception.DockerClientException; import com.github.dockerjava.api.model.BuildResponseItem; import com.github.dockerjava.api.model.Frame; -import com.github.dockerjava.core.CompressArchiveUtil; +import com.github.dockerjava.core.DefaultDockerClientConfig; import com.github.dockerjava.core.DockerClientBuilder; import com.github.dockerjava.core.DockerClientConfig; import com.github.dockerjava.core.command.AttachContainerResultCallback; import com.github.dockerjava.core.command.BuildImageResultCallback; +import com.github.dockerjava.core.command.WaitContainerResultCallback; +import com.github.dockerjava.core.util.CompressArchiveUtil; import com.github.dockerjava.jaxrs.AbstrSyncDockerCmdExec; -import com.github.dockerjava.jaxrs.DockerCmdExecFactoryImpl; +import com.github.dockerjava.jaxrs.JerseyDockerCmdExecFactory; import org.assertj.core.api.Condition; import org.junit.Test; import org.junit.runner.RunWith; @@ -250,8 +250,10 @@ public class SysVinitLaunchScriptIT { } }); - resultCallback.awaitCompletion(60, TimeUnit.SECONDS).close(); - docker.waitContainerCmd(container).exec(); + resultCallback.awaitCompletion(60, TimeUnit.SECONDS); + WaitContainerResultCallback waitContainerCallback = new WaitContainerResultCallback(); + docker.waitContainerCmd(container).exec(waitContainerCallback); + waitContainerCallback.awaitCompletion(60, TimeUnit.SECONDS); return output.toString(); } finally { @@ -265,11 +267,10 @@ public class SysVinitLaunchScriptIT { } private DockerClient createClient() { - DockerClientConfig config = DockerClientConfig.createDefaultConfigBuilder() - .withVersion("1.19").build(); - DockerClient docker = DockerClientBuilder.getInstance(config) + DockerClientConfig config = DefaultDockerClientConfig.createDefaultConfigBuilder() + .withApiVersion("1.19").build(); + return DockerClientBuilder.getInstance(config) .withDockerCmdExecFactory(this.commandExecFactory).build(); - return docker; } private String buildImage(DockerClient docker) { @@ -325,7 +326,8 @@ public class SysVinitLaunchScriptIT { } }; - docker.buildImageCmd(new File(dockerfile)).withTag(tag).exec(resultCallback); + docker.buildImageCmd(new File(dockerfile)) + .withTags(new HashSet(Arrays.asList(tag))).exec(resultCallback); String imageId = resultCallback.awaitImageId(); return imageId; } @@ -446,20 +448,7 @@ public class SysVinitLaunchScriptIT { } private static final class SpringBootDockerCmdExecFactory - extends DockerCmdExecFactoryImpl { - - private SpringBootDockerCmdExecFactory() { - withClientRequestFilters(new ClientRequestFilter() { - - @Override - public void filter(ClientRequestContext requestContext) - throws IOException { - // Workaround for https://go-review.googlesource.com/#/c/3821/ - requestContext.getHeaders().add("Connection", "close"); - } - - }); - } + extends JerseyDockerCmdExecFactory { private CopyToContainerCmdExec createCopyToContainerCmdExec() { return new CopyToContainerCmdExec(getBaseResource(), getDockerClientConfig()); diff --git a/spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/resources/logback.xml b/spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/resources/logback.xml index 06d012c0fb..7c402db9a3 100644 --- a/spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/resources/logback.xml +++ b/spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/resources/logback.xml @@ -1,15 +1,10 @@ - %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n - - - -