Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,21 @@ jobs:
wget -q https://get.cimate.io/release/linux/cimate
chmod +x cimate
./cimate "**/TEST-*.xml"
httpclient5_test:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
- name: Build with Gradle
run: |
echo "transport.type=httpclient5" > $HOME/.testcontainers.properties
cat $HOME/.testcontainers.properties
./gradlew --no-daemon --scan testcontainers:test --tests '*EventStreamTest'
- name: aggregate test reports with ciMate
if: always()
env:
CIMATE_PROJECT_ID: 2348n4vl
CIMATE_CI_KEY: "CI / Apache HttpClient5"
run: |
wget -q https://get.cimate.io/release/linux/cimate
chmod +x cimate
./cimate "**/TEST-*.xml"
7 changes: 6 additions & 1 deletion core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,18 @@ dependencies {

compile "net.java.dev.jna:jna-platform:5.5.0"

shaded ('com.github.docker-java:docker-java-transport-okhttp:3.2.1') {
shaded ('com.github.docker-java:docker-java-transport-okhttp:3.2.2') {
exclude(group: 'net.java.dev.jna')
exclude(group: 'com.google.code.findbug')
exclude(group: 'org.slf4j')
exclude(group: 'org.apache.commons', module: 'commons-compress')
}

shaded ('com.github.docker-java:docker-java-transport-zerodep:3.2.2') {
exclude(group: 'net.java.dev.jna')
exclude(group: 'org.slf4j')
}

shaded "org.yaml:snakeyaml:1.25"

shaded 'org.glassfish.main.external:trilead-ssh2-repackaged:4.1.2'
Expand Down
12 changes: 12 additions & 0 deletions core/src/main/java/org/testcontainers/DelegatingDockerClient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.testcontainers;

import com.github.dockerjava.api.DockerClient;
import lombok.RequiredArgsConstructor;
import lombok.experimental.Delegate;

@RequiredArgsConstructor
class DelegatingDockerClient implements DockerClient {

@Delegate
private final DockerClient dockerClient;
}
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,12 @@ public DockerClient client() {

String hostIpAddress = strategy.getDockerHostIpAddress();
log.info("Docker host IP address is {}", hostIpAddress);
final DockerClient client = strategy.getClient();
final DockerClient client = new DelegatingDockerClient(strategy.getClient()) {
@Override
public void close() {
throw new IllegalStateException("You should never close the global DockerClient!");
}
};
Comment on lines +151 to +156
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice 👍


Info dockerInfo = client.infoCmd().exec();
Version version = client.versionCmd().exec();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,8 @@ default <T> T copyFileFromContainer(String containerPath, ThrowingFunction<Inpu
throw new IllegalStateException("copyFileFromContainer can only be used when the Container is created.");
}

DockerClient dockerClient = DockerClientFactory.instance().client();
try (
DockerClient dockerClient = DockerClientFactory.instance().client();
InputStream inputStream = dockerClient.copyArchiveFromContainerCmd(getContainerId(), containerPath).exec();
TarArchiveInputStream tarInputStream = new TarArchiveInputStream(inputStream)
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import com.github.dockerjava.api.model.Network;
import com.github.dockerjava.core.DockerClientConfig;
import com.github.dockerjava.core.DockerClientImpl;
import com.github.dockerjava.okhttp.OkHttpDockerCmdExecFactory;
import com.github.dockerjava.okhttp.OkDockerHttpClient;
import com.github.dockerjava.transport.DockerHttpClient;
import com.github.dockerjava.zerodep.ZerodepDockerHttpClient;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Throwables;
import org.apache.commons.io.IOUtils;
Expand Down Expand Up @@ -116,6 +118,13 @@ public static DockerClientProviderStrategy getFirstValidStrategy(List<DockerClie
try {
strategy.test();
LOGGER.info("Found Docker environment with {}", strategy.getDescription());
LOGGER.debug(
"Transport type: '{}', Docker host: '{}'",
TestcontainersConfiguration.getInstance().getTransportType(),
strategy.config != null
? strategy.config.getDockerHost()
: "<unknown>"
);
strategy.checkOSType();

if (strategy.isPersistable()) {
Expand Down Expand Up @@ -171,9 +180,28 @@ public DockerClient getClient() {
}

protected DockerClient getClientForConfig(DockerClientConfig config) {
return DockerClientImpl
.getInstance(new AuthDelegatingDockerClientConfig(config))
.withDockerCmdExecFactory(new OkHttpDockerCmdExecFactory());
config = new AuthDelegatingDockerClientConfig(config);
final DockerHttpClient dockerHttpClient;

String transportType = TestcontainersConfiguration.getInstance().getTransportType();
switch (transportType) {
case "okhttp":
dockerHttpClient = new OkDockerHttpClient.Builder()
.dockerHost(config.getDockerHost())
.sslConfig(config.getSSLConfig())
.build();
break;
case "httpclient5":
dockerHttpClient = new ZerodepDockerHttpClient.Builder()
.dockerHost(config.getDockerHost())
.sslConfig(config.getSSLConfig())
.build();
break;
default:
throw new IllegalArgumentException("Unknown transport type '" + transportType + "'");
}

return DockerClientImpl.getInstance(config, dockerHttpClient);
}

protected void ping(DockerClient client, int timeoutInSeconds) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,6 @@ public String getDockerClientStrategyClassName() {
return (String) environmentProperties.get("docker.client.strategy");
}

/**
*
* @deprecated we no longer have different transport types
*/
@Deprecated
public String getTransportType() {
return properties.getProperty("transport.type", "okhttp");
}
Expand Down
4 changes: 4 additions & 0 deletions examples/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@ apply from: "$rootDir/../gradle/ci-support.gradle"

subprojects {
apply plugin:"java"

repositories {
jcenter()
}
}