Skip to content

Commit 7ecda0e

Browse files
committed
Revert "Update docker-java to 3.0.12 (#393)"
3cce55a
1 parent 98ec10e commit 7ecda0e

File tree

12 files changed

+126
-25
lines changed

12 files changed

+126
-25
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ All notable changes to this project will be documented in this file.
1717
- Fixed erroneous version reference used during CI testing of shaded dependencies
1818
- Fixed leakage of Vibur and Tomcat JDBC test dependencies in `jdbc-test` and `mysql` modules (#382)
1919
- Added timeout and retries for creation of `RemoteWebDriver` (#381, #373, #257)
20+
- Fixed double encoding of listNetwork's filter until it's fixed in docker-java (#385)
2021
- Fixed various shading issues
2122
- Improved removal of containers/networks when using Docker Compose, eliminating irrelevant errors during cleanup (#342, #394)
2223

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

3030
## [1.3.1] - 2017-06-22
3131
### Fixed

core/pom.xml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@
3333
<version>${docker-java.version}</version>
3434
<scope>compile</scope>
3535
<exclusions>
36+
<!-- replace with junixsocket -->
37+
<exclusion>
38+
<groupId>de.gesellix</groupId>
39+
<artifactId>unix-socket-factory</artifactId>
40+
</exclusion>
3641
<exclusion>
3742
<groupId>org.glassfish.jersey.core</groupId>
3843
<artifactId>*</artifactId>
@@ -68,6 +73,12 @@
6873
<version>2.0.1</version>
6974
</dependency>
7075

76+
<dependency>
77+
<groupId>org.rnorth</groupId>
78+
<artifactId>tcp-unix-socket-proxy</artifactId>
79+
<version>1.0.1</version>
80+
</dependency>
81+
7182
<dependency>
7283
<groupId>org.zeroturnaround</groupId>
7384
<artifactId>zt-exec</artifactId>
@@ -270,8 +281,6 @@
270281
dest="${project.build.directory}/exploded/"/>
271282
<move file="${project.build.directory}/exploded/META-INF/native/libnetty-transport-native-epoll.so"
272283
tofile="${project.build.directory}/exploded/META-INF/native/liborg-testcontainers-shaded-netty-transport-native-epoll.so"/>
273-
<move file="${project.build.directory}/exploded/META-INF/native/libnetty-transport-native-kqueue.jnilib"
274-
tofile="${project.build.directory}/exploded/META-INF/native/liborg-testcontainers-shaded-netty-transport-native-kqueue.jnilib"/>
275284
<jar destfile="${project.build.directory}/${project.artifactId}-${project.version}.jar"
276285
basedir="${project.build.directory}/exploded"/>
277286
</target>

core/src/main/java/org/testcontainers/DockerClientFactory.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public class DockerClientFactory {
5050
private static final List<DockerClientProviderStrategy> CONFIGURATION_STRATEGIES =
5151
asList(new EnvironmentAndSystemPropertyClientProviderStrategy(),
5252
new UnixSocketClientProviderStrategy(),
53+
new ProxiedUnixSocketClientProviderStrategy(),
5354
new DockerMachineClientProviderStrategy(),
5455
new WindowsClientProviderStrategy());
5556
private String activeApiVersion;

core/src/main/java/org/testcontainers/containers/wait/HostPortWaitStrategy.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import org.testcontainers.DockerClientFactory;
77
import org.testcontainers.containers.ContainerLaunchException;
88
import org.testcontainers.containers.GenericContainer;
9-
import org.testcontainers.dockerclient.DockerMachineClientProviderStrategy;
9+
import org.testcontainers.dockerclient.ProxiedUnixSocketClientProviderStrategy;
1010
import org.testcontainers.dockerclient.WindowsClientProviderStrategy;
1111

1212
import java.net.Socket;
@@ -93,7 +93,7 @@ protected void waitUntilReady() {
9393

9494
private boolean shouldCheckWithCommand() {
9595
// Special case for Docker for Mac, see #160
96-
if(!DockerClientFactory.instance().isUsing(DockerMachineClientProviderStrategy.class)
96+
if(DockerClientFactory.instance().isUsing(ProxiedUnixSocketClientProviderStrategy.class)
9797
&& System.getProperty("os.name").toLowerCase().contains("mac")) {
9898
return true;
9999
}

core/src/main/java/org/testcontainers/dockerclient/DockerClientProviderStrategy.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import com.github.dockerjava.api.DockerClient;
44
import com.github.dockerjava.core.DockerClientBuilder;
55
import com.github.dockerjava.core.DockerClientConfig;
6-
import com.github.dockerjava.netty.NettyDockerCmdExecFactory;
76
import com.google.common.base.Throwables;
87
import org.apache.commons.io.IOUtils;
98
import org.jetbrains.annotations.Nullable;
@@ -148,7 +147,7 @@ public DockerClient getClient() {
148147
protected DockerClient getClientForConfig(DockerClientConfig config) {
149148
return DockerClientBuilder
150149
.getInstance(config)
151-
.withDockerCmdExecFactory(new NettyDockerCmdExecFactory())
150+
.withDockerCmdExecFactory(new TestcontainersDockerCmdExecFactory())
152151
.build();
153152
}
154153

core/src/main/java/org/testcontainers/dockerclient/DockerMachineClientProviderStrategy.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616
*/
1717
@Slf4j
1818
public class DockerMachineClientProviderStrategy extends DockerClientProviderStrategy {
19-
20-
public static final int PRIORITY = EnvironmentAndSystemPropertyClientProviderStrategy.PRIORITY - 10;
21-
2219
private static final String PING_TIMEOUT_DEFAULT = "30";
2320
private static final String PING_TIMEOUT_PROPERTY_NAME = "testcontainers.dockermachineprovider.timeout";
2421

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

3027
@Override
3128
protected int getPriority() {
32-
return PRIORITY;
29+
return ProxiedUnixSocketClientProviderStrategy.PRIORITY - 10;
3330
}
3431

3532
@Override

core/src/main/java/org/testcontainers/dockerclient/EnvironmentAndSystemPropertyClientProviderStrategy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
@Slf4j
1313
public class EnvironmentAndSystemPropertyClientProviderStrategy extends DockerClientProviderStrategy {
1414

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

1717
private static final String PING_TIMEOUT_DEFAULT = "10";
1818
private static final String PING_TIMEOUT_PROPERTY_NAME = "testcontainers.environmentprovider.timeout";
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package org.testcontainers.dockerclient;
2+
3+
import lombok.extern.slf4j.Slf4j;
4+
import org.apache.commons.lang.SystemUtils;
5+
import org.rnorth.tcpunixsocketproxy.TcpToUnixSocketProxy;
6+
7+
import java.io.File;
8+
9+
@Slf4j
10+
public class ProxiedUnixSocketClientProviderStrategy extends UnixSocketClientProviderStrategy {
11+
12+
public static final int PRIORITY = EnvironmentAndSystemPropertyClientProviderStrategy.PRIORITY - 10;
13+
14+
private final File socketFile = new File(DOCKER_SOCK_PATH);
15+
16+
@Override
17+
protected boolean isApplicable() {
18+
return !SystemUtils.IS_OS_LINUX && socketFile.exists();
19+
}
20+
21+
@Override
22+
protected int getPriority() {
23+
return PRIORITY;
24+
}
25+
26+
@Override
27+
public void test() throws InvalidConfigurationException {
28+
TcpToUnixSocketProxy proxy = new TcpToUnixSocketProxy(socketFile);
29+
30+
try {
31+
int proxyPort = proxy.start().getPort();
32+
33+
config = tryConfiguration("tcp://localhost:" + proxyPort);
34+
35+
log.debug("Accessing unix domain socket via TCP proxy (" + DOCKER_SOCK_PATH + " via localhost:" + proxyPort + ")");
36+
} catch (Exception e) {
37+
38+
proxy.stop();
39+
40+
throw new InvalidConfigurationException("ping failed", e);
41+
}
42+
43+
}
44+
45+
@Override
46+
public String getDescription() {
47+
return "local Unix socket (via TCP proxy)";
48+
}
49+
50+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package org.testcontainers.dockerclient;
2+
3+
import com.fasterxml.jackson.core.type.TypeReference;
4+
import com.github.dockerjava.api.command.ListNetworksCmd;
5+
import com.github.dockerjava.api.model.Network;
6+
import com.github.dockerjava.core.DockerClientConfig;
7+
import com.github.dockerjava.core.util.FiltersEncoder;
8+
import com.github.dockerjava.netty.MediaType;
9+
import com.github.dockerjava.netty.NettyDockerCmdExecFactory;
10+
import com.github.dockerjava.netty.WebTarget;
11+
import com.github.dockerjava.netty.exec.AbstrSyncDockerCmdExec;
12+
import lombok.SneakyThrows;
13+
import org.slf4j.Logger;
14+
import org.slf4j.LoggerFactory;
15+
16+
import java.lang.reflect.Field;
17+
import java.util.List;
18+
19+
class TestcontainersDockerCmdExecFactory extends NettyDockerCmdExecFactory {
20+
21+
@Override
22+
@SneakyThrows
23+
public ListNetworksCmd.Exec createListNetworksCmdExec() {
24+
Field baseResourceField = NettyDockerCmdExecFactory.class.getDeclaredField("baseResource");
25+
baseResourceField.setAccessible(true);
26+
27+
// FIXME Workaround for https://github.com/docker-java/docker-java/issues/857
28+
return new ListNetworksCmdExec((WebTarget) baseResourceField.get(this), getDockerClientConfig());
29+
}
30+
31+
private static class ListNetworksCmdExec extends AbstrSyncDockerCmdExec<ListNetworksCmd, List<Network>> implements ListNetworksCmd.Exec {
32+
33+
private static final Logger LOGGER = LoggerFactory.getLogger(com.github.dockerjava.netty.exec.ListNetworksCmdExec.class);
34+
35+
public ListNetworksCmdExec(WebTarget baseResource, DockerClientConfig dockerClientConfig) {
36+
super(baseResource, dockerClientConfig);
37+
}
38+
39+
@Override
40+
protected List<Network> execute(ListNetworksCmd command) {
41+
WebTarget webTarget = getBaseResource().path("/networks");
42+
43+
if (command.getFilters() != null && !command.getFilters().isEmpty()) {
44+
// Next line was changed (urlPathSegmentEscaper was removed)
45+
webTarget = webTarget.queryParam("filters", FiltersEncoder.jsonEncode(command.getFilters()));
46+
}
47+
48+
LOGGER.trace("GET: {}", webTarget);
49+
50+
return webTarget.request().accept(MediaType.APPLICATION_JSON).get(new TypeReference<List<Network>>() {
51+
});
52+
}
53+
}
54+
55+
}

core/src/main/java/org/testcontainers/dockerclient/UnixSocketClientProviderStrategy.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,13 @@
66
import org.apache.commons.lang.SystemUtils;
77
import org.jetbrains.annotations.NotNull;
88

9-
import java.io.File;
109
import java.io.IOException;
1110
import java.nio.file.Files;
1211
import java.nio.file.Path;
1312
import java.nio.file.Paths;
1413

1514
@Slf4j
1615
public class UnixSocketClientProviderStrategy extends DockerClientProviderStrategy {
17-
18-
public static final int PRIORITY = 100;
19-
2016
protected static final String DOCKER_SOCK_PATH = "/var/run/docker.sock";
2117
private static final String SOCKET_LOCATION = "unix://" + DOCKER_SOCK_PATH;
2218
private static final int SOCKET_FILE_MODE_MASK = 0xc000;
@@ -25,12 +21,7 @@ public class UnixSocketClientProviderStrategy extends DockerClientProviderStrate
2521

2622
@Override
2723
protected boolean isApplicable() {
28-
return SystemUtils.IS_OS_UNIX && new File(DOCKER_SOCK_PATH).exists();
29-
}
30-
31-
@Override
32-
protected int getPriority() {
33-
return PRIORITY;
24+
return SystemUtils.IS_OS_LINUX;
3425
}
3526

3627
@Override

0 commit comments

Comments
 (0)