Make launch script integration tests compatible with Spring Framework 4.3
Previously, the launch script integration tests used Jackson 2.1 to align with the requirements of docker-java 2.x. This stopped working when we upgraded to Spring Framework 4.3 which requires Jackson 2.6+. This commit updates the launch script integration tests to use docker-java 3.0.0-RC1 which is compatible with Jackson 2.6.x. An added benefit is that 3.0 also adds support for copying an archive to a container, allowing the custom command that performs this function to be removed. Closes gh-5278
This commit is contained in:
parent
1ca9cdabf7
commit
2c619f8d93
|
@ -19,7 +19,6 @@
|
||||||
<properties>
|
<properties>
|
||||||
<main.basedir>${basedir}/..</main.basedir>
|
<main.basedir>${basedir}/..</main.basedir>
|
||||||
<java.version>1.8</java.version>
|
<java.version>1.8</java.version>
|
||||||
<jackson.version>2.1.2</jackson.version> <!-- Align with docker-java -->
|
|
||||||
</properties>
|
</properties>
|
||||||
<modules>
|
<modules>
|
||||||
<module>spring-boot-gradle-tests</module>
|
<module>spring-boot-gradle-tests</module>
|
||||||
|
|
|
@ -36,7 +36,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.docker-java</groupId>
|
<groupId>com.github.docker-java</groupId>
|
||||||
<artifactId>docker-java</artifactId>
|
<artifactId>docker-java</artifactId>
|
||||||
<version>2.1.4</version>
|
<version>3.0.0-RC1</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
|
@ -17,30 +17,18 @@
|
||||||
package org.springframework.boot.launchscript;
|
package org.springframework.boot.launchscript;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.regex.Pattern;
|
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.DockerClient;
|
||||||
import com.github.dockerjava.api.command.DockerCmd;
|
|
||||||
import com.github.dockerjava.api.model.Frame;
|
import com.github.dockerjava.api.model.Frame;
|
||||||
import com.github.dockerjava.core.CompressArchiveUtil;
|
|
||||||
import com.github.dockerjava.core.DockerClientBuilder;
|
import com.github.dockerjava.core.DockerClientBuilder;
|
||||||
import com.github.dockerjava.core.DockerClientConfig;
|
import com.github.dockerjava.core.DockerClientConfig;
|
||||||
import com.github.dockerjava.core.command.AttachContainerResultCallback;
|
import com.github.dockerjava.core.command.AttachContainerResultCallback;
|
||||||
import com.github.dockerjava.core.command.BuildImageResultCallback;
|
import com.github.dockerjava.core.command.BuildImageResultCallback;
|
||||||
import com.github.dockerjava.jaxrs.AbstrSyncDockerCmdExec;
|
import com.github.dockerjava.core.command.WaitContainerResultCallback;
|
||||||
import com.github.dockerjava.jaxrs.DockerCmdExecFactoryImpl;
|
|
||||||
import org.assertj.core.api.Condition;
|
import org.assertj.core.api.Condition;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
@ -63,8 +51,6 @@ import static org.junit.Assume.assumeThat;
|
||||||
@RunWith(Parameterized.class)
|
@RunWith(Parameterized.class)
|
||||||
public class SysVinitLaunchScriptIT {
|
public class SysVinitLaunchScriptIT {
|
||||||
|
|
||||||
private final SpringBootDockerCmdExecFactory commandExecFactory = new SpringBootDockerCmdExecFactory();
|
|
||||||
|
|
||||||
private static final char ESC = 27;
|
private static final char ESC = 27;
|
||||||
|
|
||||||
private final String os;
|
private final String os;
|
||||||
|
@ -223,7 +209,8 @@ public class SysVinitLaunchScriptIT {
|
||||||
|
|
||||||
});
|
});
|
||||||
resultCallback.awaitCompletion(60, TimeUnit.SECONDS).close();
|
resultCallback.awaitCompletion(60, TimeUnit.SECONDS).close();
|
||||||
docker.waitContainerCmd(container).exec();
|
docker.waitContainerCmd(container).exec(new WaitContainerResultCallback())
|
||||||
|
.awaitCompletion(60, TimeUnit.SECONDS);
|
||||||
return output.toString();
|
return output.toString();
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
|
@ -234,8 +221,7 @@ public class SysVinitLaunchScriptIT {
|
||||||
private DockerClient createClient() {
|
private DockerClient createClient() {
|
||||||
DockerClientConfig config = DockerClientConfig.createDefaultConfigBuilder()
|
DockerClientConfig config = DockerClientConfig.createDefaultConfigBuilder()
|
||||||
.build();
|
.build();
|
||||||
DockerClient docker = DockerClientBuilder.getInstance(config)
|
DockerClient docker = DockerClientBuilder.getInstance(config).build();
|
||||||
.withDockerCmdExecFactory(this.commandExecFactory).build();
|
|
||||||
return docker;
|
return docker;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -264,10 +250,9 @@ public class SysVinitLaunchScriptIT {
|
||||||
new File("src/test/resources/scripts/" + script));
|
new File("src/test/resources/scripts/" + script));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void copyToContainer(DockerClient docker, final String container,
|
private void copyToContainer(DockerClient docker, String container, File file) {
|
||||||
final File file) {
|
docker.copyArchiveToContainerCmd(container)
|
||||||
this.commandExecFactory.createCopyToContainerCmdExec()
|
.withHostResource(file.getAbsolutePath()).exec();
|
||||||
.exec(new CopyToContainerCmd(container, file));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private File findApplication() {
|
private File findApplication() {
|
||||||
|
@ -309,81 +294,4 @@ public class SysVinitLaunchScriptIT {
|
||||||
"Failed to extract " + label + " from output: " + output);
|
"Failed to extract " + label + " from output: " + output);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class CopyToContainerCmdExec
|
|
||||||
extends AbstrSyncDockerCmdExec<CopyToContainerCmd, Void> {
|
|
||||||
|
|
||||||
private CopyToContainerCmdExec(WebTarget baseResource,
|
|
||||||
DockerClientConfig dockerClientConfig) {
|
|
||||||
super(baseResource, dockerClientConfig);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Void execute(CopyToContainerCmd command) {
|
|
||||||
try {
|
|
||||||
InputStream streamToUpload = new FileInputStream(CompressArchiveUtil
|
|
||||||
.archiveTARFiles(command.getFile().getParentFile(),
|
|
||||||
Arrays.asList(command.getFile()),
|
|
||||||
command.getFile().getName()));
|
|
||||||
WebTarget webResource = getBaseResource().path("/containers/{id}/archive")
|
|
||||||
.resolveTemplate("id", command.getContainer());
|
|
||||||
webResource.queryParam("path", ".")
|
|
||||||
.queryParam("noOverwriteDirNonDir", false).request()
|
|
||||||
.put(Entity.entity(streamToUpload, "application/x-tar")).close();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
catch (Exception ex) {
|
|
||||||
throw new RuntimeException(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final class CopyToContainerCmd implements DockerCmd<Void> {
|
|
||||||
|
|
||||||
private final String container;
|
|
||||||
|
|
||||||
private final File file;
|
|
||||||
|
|
||||||
private CopyToContainerCmd(String container, File file) {
|
|
||||||
this.container = container;
|
|
||||||
this.file = file;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getContainer() {
|
|
||||||
return this.container;
|
|
||||||
}
|
|
||||||
|
|
||||||
public File getFile() {
|
|
||||||
return this.file;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void close() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
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");
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private CopyToContainerCmdExec createCopyToContainerCmdExec() {
|
|
||||||
return new CopyToContainerCmdExec(getBaseResource(), getDockerClientConfig());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue