Skip to content

Commit

Permalink
Revert "Update docker-java to 3.0.12 (#393)"
Browse files Browse the repository at this point in the history
  • Loading branch information
rnorth committed Jul 11, 2017
1 parent 20755cf commit 89b96c5
Show file tree
Hide file tree
Showing 12 changed files with 126 additions and 25 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ All notable changes to this project will be documented in this file.
- Fixed erroneous version reference used during CI testing of shaded dependencies
- Fixed leakage of Vibur and Tomcat JDBC test dependencies in `jdbc-test` and `mysql` modules (#382)
- Added timeout and retries for creation of `RemoteWebDriver` (#381, #373, #257)
- Fixed double encoding of listNetwork's filter until it's fixed in docker-java (#385)
- Fixed various shading issues
- Improved removal of containers/networks when using Docker Compose, eliminating irrelevant errors during cleanup (#342, #394)

Expand All @@ -24,7 +25,6 @@ All notable changes to this project will be documented in this file.
- Added `getFirstMappedPort` method (#377)
- Extracted Oracle XE container into a separate repository ([testcontainers/testcontainers-java-module-oracle-xe](https://github.com/testcontainers/testcontainers-java-module-oracle-xe))
- Added shading tests
- Updated docker-java to 3.0.12 (#393)

## [1.3.1] - 2017-06-22
### Fixed
Expand Down
13 changes: 11 additions & 2 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
<version>${docker-java.version}</version>
<scope>compile</scope>
<exclusions>
<!-- replace with junixsocket -->
<exclusion>
<groupId>de.gesellix</groupId>
<artifactId>unix-socket-factory</artifactId>
</exclusion>
<exclusion>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>*</artifactId>
Expand Down Expand Up @@ -68,6 +73,12 @@
<version>2.0.1</version>
</dependency>

<dependency>
<groupId>org.rnorth</groupId>
<artifactId>tcp-unix-socket-proxy</artifactId>
<version>1.0.1</version>
</dependency>

<dependency>
<groupId>org.zeroturnaround</groupId>
<artifactId>zt-exec</artifactId>
Expand Down Expand Up @@ -270,8 +281,6 @@
dest="${project.build.directory}/exploded/"/>
<move file="${project.build.directory}/exploded/META-INF/native/libnetty-transport-native-epoll.so"
tofile="${project.build.directory}/exploded/META-INF/native/liborg-testcontainers-shaded-netty-transport-native-epoll.so"/>
<move file="${project.build.directory}/exploded/META-INF/native/libnetty-transport-native-kqueue.jnilib"
tofile="${project.build.directory}/exploded/META-INF/native/liborg-testcontainers-shaded-netty-transport-native-kqueue.jnilib"/>
<jar destfile="${project.build.directory}/${project.artifactId}-${project.version}.jar"
basedir="${project.build.directory}/exploded"/>
</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public class DockerClientFactory {
private static final List<DockerClientProviderStrategy> CONFIGURATION_STRATEGIES =
asList(new EnvironmentAndSystemPropertyClientProviderStrategy(),
new UnixSocketClientProviderStrategy(),
new ProxiedUnixSocketClientProviderStrategy(),
new DockerMachineClientProviderStrategy(),
new WindowsClientProviderStrategy());
private String activeApiVersion;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import org.testcontainers.DockerClientFactory;
import org.testcontainers.containers.ContainerLaunchException;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.dockerclient.DockerMachineClientProviderStrategy;
import org.testcontainers.dockerclient.ProxiedUnixSocketClientProviderStrategy;
import org.testcontainers.dockerclient.WindowsClientProviderStrategy;

import java.net.Socket;
Expand Down Expand Up @@ -93,7 +93,7 @@ protected void waitUntilReady() {

private boolean shouldCheckWithCommand() {
// Special case for Docker for Mac, see #160
if(!DockerClientFactory.instance().isUsing(DockerMachineClientProviderStrategy.class)
if(DockerClientFactory.instance().isUsing(ProxiedUnixSocketClientProviderStrategy.class)
&& System.getProperty("os.name").toLowerCase().contains("mac")) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.github.dockerjava.api.DockerClient;
import com.github.dockerjava.core.DockerClientBuilder;
import com.github.dockerjava.core.DockerClientConfig;
import com.github.dockerjava.netty.NettyDockerCmdExecFactory;
import com.google.common.base.Throwables;
import org.apache.commons.io.IOUtils;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -142,7 +141,7 @@ public DockerClient getClient() {
protected DockerClient getClientForConfig(DockerClientConfig config) {
return DockerClientBuilder
.getInstance(config)
.withDockerCmdExecFactory(new NettyDockerCmdExecFactory())
.withDockerCmdExecFactory(new TestcontainersDockerCmdExecFactory())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
*/
@Slf4j
public class DockerMachineClientProviderStrategy extends DockerClientProviderStrategy {

public static final int PRIORITY = EnvironmentAndSystemPropertyClientProviderStrategy.PRIORITY - 10;

private static final String PING_TIMEOUT_DEFAULT = "30";
private static final String PING_TIMEOUT_PROPERTY_NAME = "testcontainers.dockermachineprovider.timeout";

Expand All @@ -29,7 +26,7 @@ protected boolean isApplicable() {

@Override
protected int getPriority() {
return PRIORITY;
return ProxiedUnixSocketClientProviderStrategy.PRIORITY - 10;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
@Slf4j
public class EnvironmentAndSystemPropertyClientProviderStrategy extends DockerClientProviderStrategy {

public static final int PRIORITY = UnixSocketClientProviderStrategy.PRIORITY - 10;
public static final int PRIORITY = 100;

private static final String PING_TIMEOUT_DEFAULT = "10";
private static final String PING_TIMEOUT_PROPERTY_NAME = "testcontainers.environmentprovider.timeout";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package org.testcontainers.dockerclient;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.SystemUtils;
import org.rnorth.tcpunixsocketproxy.TcpToUnixSocketProxy;

import java.io.File;

@Slf4j
public class ProxiedUnixSocketClientProviderStrategy extends UnixSocketClientProviderStrategy {

public static final int PRIORITY = EnvironmentAndSystemPropertyClientProviderStrategy.PRIORITY - 10;

private final File socketFile = new File(DOCKER_SOCK_PATH);

@Override
protected boolean isApplicable() {
return !SystemUtils.IS_OS_LINUX && socketFile.exists();
}

@Override
protected int getPriority() {
return PRIORITY;
}

@Override
public void test() throws InvalidConfigurationException {
TcpToUnixSocketProxy proxy = new TcpToUnixSocketProxy(socketFile);

try {
int proxyPort = proxy.start().getPort();

config = tryConfiguration("tcp://localhost:" + proxyPort);

log.debug("Accessing unix domain socket via TCP proxy (" + DOCKER_SOCK_PATH + " via localhost:" + proxyPort + ")");
} catch (Exception e) {

proxy.stop();

throw new InvalidConfigurationException("ping failed", e);
}

}

@Override
public String getDescription() {
return "local Unix socket (via TCP proxy)";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package org.testcontainers.dockerclient;

import com.fasterxml.jackson.core.type.TypeReference;
import com.github.dockerjava.api.command.ListNetworksCmd;
import com.github.dockerjava.api.model.Network;
import com.github.dockerjava.core.DockerClientConfig;
import com.github.dockerjava.core.util.FiltersEncoder;
import com.github.dockerjava.netty.MediaType;
import com.github.dockerjava.netty.NettyDockerCmdExecFactory;
import com.github.dockerjava.netty.WebTarget;
import com.github.dockerjava.netty.exec.AbstrSyncDockerCmdExec;
import lombok.SneakyThrows;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.reflect.Field;
import java.util.List;

class TestcontainersDockerCmdExecFactory extends NettyDockerCmdExecFactory {

@Override
@SneakyThrows
public ListNetworksCmd.Exec createListNetworksCmdExec() {
Field baseResourceField = NettyDockerCmdExecFactory.class.getDeclaredField("baseResource");
baseResourceField.setAccessible(true);

// FIXME Workaround for https://github.com/docker-java/docker-java/issues/857
return new ListNetworksCmdExec((WebTarget) baseResourceField.get(this), getDockerClientConfig());
}

private static class ListNetworksCmdExec extends AbstrSyncDockerCmdExec<ListNetworksCmd, List<Network>> implements ListNetworksCmd.Exec {

private static final Logger LOGGER = LoggerFactory.getLogger(com.github.dockerjava.netty.exec.ListNetworksCmdExec.class);

public ListNetworksCmdExec(WebTarget baseResource, DockerClientConfig dockerClientConfig) {
super(baseResource, dockerClientConfig);
}

@Override
protected List<Network> execute(ListNetworksCmd command) {
WebTarget webTarget = getBaseResource().path("/networks");

if (command.getFilters() != null && !command.getFilters().isEmpty()) {
// Next line was changed (urlPathSegmentEscaper was removed)
webTarget = webTarget.queryParam("filters", FiltersEncoder.jsonEncode(command.getFilters()));
}

LOGGER.trace("GET: {}", webTarget);

return webTarget.request().accept(MediaType.APPLICATION_JSON).get(new TypeReference<List<Network>>() {
});
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,13 @@
import org.apache.commons.lang.SystemUtils;
import org.jetbrains.annotations.NotNull;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

@Slf4j
public class UnixSocketClientProviderStrategy extends DockerClientProviderStrategy {

public static final int PRIORITY = 100;

protected static final String DOCKER_SOCK_PATH = "/var/run/docker.sock";
private static final String SOCKET_LOCATION = "unix://" + DOCKER_SOCK_PATH;
private static final int SOCKET_FILE_MODE_MASK = 0xc000;
Expand All @@ -25,12 +21,7 @@ public class UnixSocketClientProviderStrategy extends DockerClientProviderStrate

@Override
protected boolean isApplicable() {
return SystemUtils.IS_OS_UNIX && new File(DOCKER_SOCK_PATH).exists();
}

@Override
protected int getPriority() {
return PRIORITY;
return SystemUtils.IS_OS_LINUX;
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<docker-java.version>3.0.12</docker-java.version>
<docker-java.version>3.0.10</docker-java.version>
</properties>

<modules>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ public void testMetaInf() throws Exception {
);

assertThatFileList(root.resolve("META-INF").resolve("native")).containsOnly(
"liborg-testcontainers-shaded-netty-transport-native-epoll.so",
"liborg-testcontainers-shaded-netty-transport-native-kqueue.jnilib"
"liborg-testcontainers-shaded-netty-transport-native-epoll.so"
);
}

Expand Down

0 comments on commit 89b96c5

Please sign in to comment.