Skip to content

Commit 513e99b

Browse files
authored
Merge branch 'master' into 2050-sqlserver-eula
2 parents 9470b79 + e7e05d2 commit 513e99b

File tree

22 files changed

+133
-70
lines changed

22 files changed

+133
-70
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Update docs version
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-18.04
10+
steps:
11+
- uses: actions/checkout@v1
12+
- name: Checkout master
13+
run: git checkout master
14+
- name: Update latest_version property in mkdocs.yml
15+
run: |
16+
sed -i "s/latest_version: .*/latest_version: ${GITHUB_REF##*/}/g" mkdocs.yml
17+
git diff
18+
- name: Commit changes
19+
run: |
20+
git config user.email "[email protected]"
21+
git config user.name "GitHub Action - Update docs version"
22+
git add mkdocs.yml
23+
git commit -m "Update documentation version to ${GITHUB_REF##*/}" -m "skip-checks: true" || echo "not changed"
24+
- name: Push changes
25+
uses: ad-m/github-push-action@68af9897f2b021035ca3952bf354bbb4675c1762 # v0.5.0
26+
with:
27+
github_token: ${{ secrets.GITHUB_TOKEN }}

core/build.gradle

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ project.tasks.check.dependsOn(jarFileTest)
5757

5858
dependencies {
5959
compile 'junit:junit:4.12'
60-
compile 'org.slf4j:slf4j-api:1.7.29'
60+
compile 'org.slf4j:slf4j-api:1.7.30'
6161
compile 'org.jetbrains:annotations:17.0.0'
6262
compile 'javax.annotation:javax.annotation-api:1.3.2'
6363
compile 'org.apache.commons:commons-compress:1.19'
@@ -106,10 +106,10 @@ dependencies {
106106
}
107107

108108
testCompile 'org.apache.httpcomponents:httpclient:4.5.9'
109-
testCompile 'redis.clients:jedis:3.1.0'
110-
testCompile 'com.rabbitmq:amqp-client:5.7.3'
111-
testCompile 'org.mongodb:mongo-java-driver:3.11.2'
112-
testCompile ('org.mockito:mockito-core:3.2.0') {
109+
testCompile 'redis.clients:jedis:3.2.0'
110+
testCompile 'com.rabbitmq:amqp-client:5.8.0'
111+
testCompile 'org.mongodb:mongo-java-driver:3.12.0'
112+
testCompile ('org.mockito:mockito-core:3.2.4') {
113113
exclude(module: 'hamcrest-core')
114114
}
115115
// Synthetic JAR used for MountableFileTest and DirectoryTarResourceTest

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,10 @@ public class DockerClientConfigUtils {
4343
.map(StringUtils::trimToEmpty)
4444
.filter(StringUtils::isNotBlank);
4545

46-
47-
46+
/**
47+
* Use {@link DockerClientFactory#dockerHostIpAddress()}
48+
*/
49+
@Deprecated
4850
public static String getDockerHostIpAddress(DockerClientConfig config) {
4951
switch (config.getDockerHost().getScheme()) {
5052
case "http":

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

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package org.testcontainers.dockerclient;
22

33
import com.github.dockerjava.api.DockerClient;
4+
import com.github.dockerjava.api.model.Network;
45
import com.github.dockerjava.core.DockerClientBuilder;
56
import com.github.dockerjava.core.DockerClientConfig;
7+
import com.google.common.annotations.VisibleForTesting;
68
import com.google.common.base.Throwables;
79
import org.apache.commons.io.IOUtils;
810
import org.apache.commons.lang.StringUtils;
@@ -17,6 +19,7 @@
1719
import org.testcontainers.dockerclient.transport.okhttp.OkHttpDockerCmdExecFactory;
1820
import org.testcontainers.utility.TestcontainersConfiguration;
1921

22+
import java.net.URI;
2023
import java.util.ArrayList;
2124
import java.util.Comparator;
2225
import java.util.List;
@@ -33,6 +36,8 @@ public abstract class DockerClientProviderStrategy {
3336
protected DockerClient client;
3437
protected DockerClientConfig config;
3538

39+
private String dockerHostIpAddress;
40+
3641
private static final RateLimiter PING_RATE_LIMITER = RateLimiterBuilder.newBuilder()
3742
.withRate(2, TimeUnit.SECONDS)
3843
.withConstantThroughput()
@@ -188,8 +193,38 @@ protected void ping(DockerClient client, int timeoutInSeconds) {
188193
}
189194
}
190195

191-
public String getDockerHostIpAddress() {
192-
return DockerClientConfigUtils.getDockerHostIpAddress(this.config);
196+
public synchronized String getDockerHostIpAddress() {
197+
if (dockerHostIpAddress == null) {
198+
dockerHostIpAddress = resolveDockerHostIpAddress(client, config.getDockerHost());
199+
}
200+
return dockerHostIpAddress;
201+
}
202+
203+
@VisibleForTesting
204+
static String resolveDockerHostIpAddress(DockerClient client, URI dockerHost) {
205+
switch (dockerHost.getScheme()) {
206+
case "http":
207+
case "https":
208+
case "tcp":
209+
return dockerHost.getHost();
210+
case "unix":
211+
case "npipe":
212+
if (DockerClientConfigUtils.IN_A_CONTAINER) {
213+
return client.inspectNetworkCmd()
214+
.withNetworkId("bridge")
215+
.exec()
216+
.getIpam()
217+
.getConfig()
218+
.stream()
219+
.filter(it -> it.getGateway() != null)
220+
.findAny()
221+
.map(Network.Ipam.Config::getGateway)
222+
.orElse("localhost");
223+
}
224+
return "localhost";
225+
default:
226+
return null;
227+
}
193228
}
194229

195230
protected void checkOSType() {

core/src/main/java/org/testcontainers/dockerclient/transport/okhttp/OkHttpInvocationBuilder.java

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
import java.io.IOException;
3636
import java.io.InputStream;
3737
import java.lang.reflect.Field;
38+
import java.nio.ByteBuffer;
39+
import java.util.Arrays;
3840
import java.util.Objects;
3941
import java.util.function.Consumer;
4042

@@ -362,23 +364,34 @@ public void accept(BufferedSource source) {
362364
try {
363365
while (!source.exhausted()) {
364366
// See https://docs.docker.com/engine/api/v1.37/#operation/ContainerAttach
365-
if(!source.request(HEADER_SIZE)) {
367+
// [8]byte{STREAM_TYPE, 0, 0, 0, SIZE1, SIZE2, SIZE3, SIZE4}[]byte{OUTPUT}
368+
369+
if (!source.request(HEADER_SIZE)) {
366370
return;
367371
}
368-
StreamType streamType = streamType(source.readByte());
369-
source.skip(3);
370-
int payloadSize = source.readInt();
372+
byte[] bytes = source.readByteArray(HEADER_SIZE);
373+
374+
StreamType streamType = streamType(bytes[0]);
371375

372-
if (streamType != StreamType.RAW) {
373-
if (!source.request(payloadSize)) {
374-
return;
376+
if (streamType == StreamType.RAW) {
377+
resultCallback.onNext(new Frame(StreamType.RAW, bytes));
378+
byte[] buffer = new byte[1024];
379+
while (!source.exhausted()) {
380+
int readBytes = source.read(buffer);
381+
if (readBytes != -1) {
382+
resultCallback.onNext(new Frame(StreamType.RAW, Arrays.copyOf(buffer, readBytes)));
383+
}
375384
}
376-
byte[] payload = source.readByteArray(payloadSize);
385+
return;
386+
}
377387

378-
resultCallback.onNext(new Frame(streamType, payload));
379-
} else {
380-
resultCallback.onNext(new Frame(streamType, source.readByteArray()));
388+
int payloadSize = ByteBuffer.wrap(bytes, 4, 4).getInt();
389+
if (!source.request(payloadSize)) {
390+
return;
381391
}
392+
byte[] payload = source.readByteArray(payloadSize);
393+
394+
resultCallback.onNext(new Frame(streamType, payload));
382395
}
383396
} catch (Exception e) {
384397
resultCallback.onError(e);

core/src/test/java/org/testcontainers/dockerclient/DockerClientConfigUtilsTest.java

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,40 @@
11
package org.testcontainers.dockerclient;
22

3-
import com.github.dockerjava.core.DefaultDockerClientConfig;
4-
import com.github.dockerjava.core.DockerClientConfig;
5-
import org.junit.Ignore;
3+
import com.github.dockerjava.api.DockerClient;
64
import org.junit.Test;
5+
import org.testcontainers.DockerClientFactory;
6+
7+
import java.net.URI;
78

89
import static org.junit.Assert.assertEquals;
910
import static org.junit.Assert.assertNotNull;
1011
import static org.junit.Assert.assertNull;
1112

1213
public class DockerClientConfigUtilsTest {
1314

15+
DockerClient client = DockerClientFactory.lazyClient();
16+
1417
@Test
1518
public void getDockerHostIpAddressShouldReturnLocalhostWhenUnixSocket() {
16-
DockerClientConfig configuration = DefaultDockerClientConfig.createDefaultConfigBuilder()
17-
.withDockerHost("unix:///var/run/docker.sock")
18-
.withDockerTlsVerify(false) // TODO - check wrt. https://github.com/docker-java/docker-java/issues/588
19-
.build();
20-
String actual = DockerClientConfigUtils.getDockerHostIpAddress(configuration);
19+
String actual = DockerClientProviderStrategy.resolveDockerHostIpAddress(client, URI.create("unix:///var/run/docker.sock"));
2120
assertEquals("localhost", actual);
2221
}
2322

24-
@Test @Ignore
25-
public void getDockerHostIpAddressShouldReturnDockerHostIpWhenHttpUri() {
26-
DockerClientConfig configuration = DefaultDockerClientConfig.createDefaultConfigBuilder().withDockerHost("http://12.23.34.45").build();
27-
String actual = DockerClientConfigUtils.getDockerHostIpAddress(configuration);
28-
assertEquals("12.23.34.45", actual);
29-
}
30-
31-
@Test @Ignore
23+
@Test
3224
public void getDockerHostIpAddressShouldReturnDockerHostIpWhenHttpsUri() {
33-
DockerClientConfig configuration = DefaultDockerClientConfig.createDefaultConfigBuilder().withDockerHost("https://12.23.34.45").build();
34-
String actual = DockerClientConfigUtils.getDockerHostIpAddress(configuration);
25+
String actual = DockerClientProviderStrategy.resolveDockerHostIpAddress(client, URI.create("http://12.23.34.45"));
3526
assertEquals("12.23.34.45", actual);
3627
}
3728

3829
@Test
3930
public void getDockerHostIpAddressShouldReturnDockerHostIpWhenTcpUri() {
40-
DockerClientConfig configuration = DefaultDockerClientConfig.createDefaultConfigBuilder()
41-
.withDockerHost("tcp://12.23.34.45")
42-
.withDockerTlsVerify(false) // TODO - check wrt. https://github.com/docker-java/docker-java/issues/588
43-
.build();
44-
String actual = DockerClientConfigUtils.getDockerHostIpAddress(configuration);
31+
String actual = DockerClientProviderStrategy.resolveDockerHostIpAddress(client, URI.create("tcp://12.23.34.45"));
4532
assertEquals("12.23.34.45", actual);
4633
}
4734

48-
@Test @Ignore
35+
@Test
4936
public void getDockerHostIpAddressShouldReturnNullWhenUnsupportedUriScheme() {
50-
DockerClientConfig configuration = DefaultDockerClientConfig.createDefaultConfigBuilder().withDockerHost("gopher://12.23.34.45").build();
51-
String actual = DockerClientConfigUtils.getDockerHostIpAddress(configuration);
37+
String actual = DockerClientProviderStrategy.resolveDockerHostIpAddress(client, URI.create("gopher://12.23.34.45"));
5238
assertNull(actual);
5339
}
5440

core/src/test/java/org/testcontainers/utility/DockerImageNameTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public static class ValidNames {
1616

1717
@Parameterized.Parameters(name = "{0}")
1818
public static String[] getNames() {
19-
return new String[]{"myname:latest",
19+
return new String[]{
2020
"myname:latest",
2121
"repo/my-name:1.0",
2222
"registry.foo.com:1234/my-name:1.0",

examples/linked-container/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ repositories {
66
jcenter()
77
}
88
dependencies {
9-
compileOnly 'org.slf4j:slf4j-api:1.7.29'
9+
compileOnly 'org.slf4j:slf4j-api:1.7.30'
1010
implementation 'com.squareup.okhttp3:okhttp:3.14.4'
1111
implementation 'org.json:json:20180813'
12-
testImplementation 'org.postgresql:postgresql:42.2.8'
12+
testImplementation 'org.postgresql:postgresql:42.2.9'
1313
testImplementation 'ch.qos.logback:logback-classic:1.2.3'
1414
testImplementation 'org.testcontainers:postgresql'
1515
}

examples/redis-backed-cache-testng/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ repositories {
77
}
88

99
dependencies {
10-
compileOnly 'org.slf4j:slf4j-api:1.7.29'
11-
implementation 'redis.clients:jedis:3.1.0'
10+
compileOnly 'org.slf4j:slf4j-api:1.7.30'
11+
implementation 'redis.clients:jedis:3.2.0'
1212
implementation 'com.google.code.gson:gson:2.8.6'
1313
implementation 'com.google.guava:guava:23.0'
1414
testImplementation 'org.testcontainers:testcontainers'
1515
testImplementation 'ch.qos.logback:logback-classic:1.2.3'
16-
testImplementation 'org.testng:testng:7.0.0'
16+
testImplementation 'org.testng:testng:7.1.0'
1717
}
1818

1919
test {

examples/redis-backed-cache/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ repositories {
77
}
88

99
dependencies {
10-
compileOnly 'org.slf4j:slf4j-api:1.7.29'
11-
implementation 'redis.clients:jedis:3.1.0'
10+
compileOnly 'org.slf4j:slf4j-api:1.7.30'
11+
implementation 'redis.clients:jedis:3.2.0'
1212
implementation 'com.google.code.gson:gson:2.8.6'
1313
implementation 'com.google.guava:guava:23.0'
1414
testImplementation 'org.testcontainers:testcontainers'

0 commit comments

Comments
 (0)