Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
4d7b09e
Refactor to use the docker-java v3 with Netty support
rnorth May 1, 2016
d6d6563
Introduce a wait period between JDBC connection checks to avoid heavy…
rnorth May 2, 2016
0138eb9
Ignore a flapping test
rnorth May 2, 2016
841c3f7
Update versions in POM
rnorth Jun 5, 2016
d5b909f
Update to release version of docker-java (3.0.0)
rnorth Jun 5, 2016
77a1e5c
Reduce log noise
rnorth Jun 5, 2016
fdcbf51
Workaround for SeleniumHQ/docker-selenium#227
rnorth Jun 5, 2016
eb48d0b
Make ContainerReaper more intelligent about not trying to kill stoppe…
rnorth Jun 5, 2016
e545df5
Refactor ProxiedUnixSocketConfigurationStrategy and UnixSocketConfigu…
rnorth Jun 10, 2016
f336800
Switch Docker Compose tests to use Jedis rather than Redisson to avoi…
rnorth Jun 10, 2016
eefc189
Tidy up Slf4jLogConsumer output to reduce duplicate whitespace
rnorth Jun 10, 2016
a0dfd50
Prevent NullPointerException at the end of container output when pipi…
rnorth Jun 10, 2016
dabc367
Reduce log level for container reaper success messages
rnorth Jun 10, 2016
fd06344
Add extra debugging logs to help diagnose any future docker daemon co…
rnorth Jun 10, 2016
63ed532
Ensure that linked containers are added to the same network as the co…
rnorth Jun 10, 2016
dcbd2f7
Add support for adding environment variables from a Map. Implements #150
rnorth Jun 10, 2016
dd22d61
Add automated test for passing environment variables through to a doc…
rnorth Jun 11, 2016
e6de735
Add cleanup of networks created by docker-compose
rnorth Jun 11, 2016
cc48fe1
Make linked container identification compatible with container names …
rnorth Jun 21, 2016
408cbd7
Change to client factory code to use netty command factory
rnorth Jun 21, 2016
376631c
Remove profiler logs from build output
rnorth Jul 2, 2016
60a1c24
Add logging of Docker API version for diagnostics
rnorth Jul 2, 2016
fcc7334
Fix NPE in DockerMachineClientProviderStrategy due to not retaining s…
rnorth Jul 2, 2016
6f36a60
Implement smarter options for specifying compose service index as per…
rnorth Jul 2, 2016
6fa9866
Add test to make sure that an invalid docker-compose file causes a fa…
rnorth Jul 2, 2016
8aa5585
Remove container startup retries. Testing indicates that this is no l…
rnorth Jul 2, 2016
5a09f96
Speed up HostPortWaitStrategyTest expected failure
rnorth Jul 2, 2016
127715e
Relax unix socket validation code by using bitmasking rather than a s…
rnorth Jul 3, 2016
9a4bd61
General code/javadocs cleanup
rnorth Jul 3, 2016
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
7 changes: 7 additions & 0 deletions annotations/com/google/common/base/annotations.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<root>
<item name='com.google.common.base.Preconditions void checkArgument(boolean, java.lang.Object)'>
<annotation name='org.jetbrains.annotations.Contract'>
<val val="&quot;false, _ -&gt; fail; true, _ -&gt; _&quot;"/>
</annotation>
</item>
</root>
7 changes: 7 additions & 0 deletions annotations/org/rnorth/ducttape/annotations.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<root>
<item name='org.rnorth.ducttape.Preconditions void check(java.lang.String, boolean)'>
<annotation name='org.jetbrains.annotations.Contract'>
<val val="&quot;_,true-&gt;_;_,false-&gt;fail&quot;"/>
</annotation>
</item>
</root>
42 changes: 33 additions & 9 deletions core/pom.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers-parent</artifactId>
<version>1.0.5-SNAPSHOT</version>
<version>1.0.6-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand All @@ -17,8 +18,22 @@
<dependency>
<groupId>com.github.docker-java</groupId>
<artifactId>docker-java</artifactId>
<version>2.2.0</version>
<version>3.0.0</version>
<exclusions>
<!-- replace with junixsocket -->
<exclusion>
<groupId>de.gesellix</groupId>
<artifactId>unix-socket-factory</artifactId>
</exclusion>
</exclusions>
</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 All @@ -37,9 +52,9 @@

<!-- Test dependencies -->
<dependency>
<groupId>org.redisson</groupId>
<artifactId>redisson</artifactId>
<version>1.3.0</version>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.8.0</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -69,6 +84,13 @@

</dependencies>

<!-- Prevent netty version conflicts with redisson, used for testing -->
<dependencyManagement>
<dependencies>

</dependencies>
</dependencyManagement>

<build>
<plugins>
<plugin>
Expand All @@ -84,8 +106,10 @@
</executions>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer" />
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"/>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
</transformers>
<relocations>
<relocation>
Expand Down Expand Up @@ -141,7 +165,7 @@
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
<exclude>META-INF/services/com.fasterxml.jackson.core.*</exclude>
<exclude>META-INF/services/com.fasterxml.jackson.core.*</exclude>
<exclude>META-INF/services/com.github.dockerjava.api.command.*</exclude>
<exclude>META-INF/services/javax.ws.rs.ext.*</exclude>
<exclude>META-INF/services/org.glassfish.hk2.extension.*</exclude>
Expand Down
63 changes: 32 additions & 31 deletions core/src/main/java/org/testcontainers/DockerClientFactory.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
package org.testcontainers;

import com.github.dockerjava.api.DockerClient;
import com.github.dockerjava.api.InternalServerErrorException;
import com.github.dockerjava.api.NotFoundException;
import com.github.dockerjava.api.command.CreateContainerResponse;
import com.github.dockerjava.api.exception.InternalServerErrorException;
import com.github.dockerjava.api.exception.NotFoundException;
import com.github.dockerjava.api.model.Frame;
import com.github.dockerjava.api.model.Image;
import com.github.dockerjava.core.DockerClientBuilder;
import com.github.dockerjava.core.DockerClientConfig;
import com.github.dockerjava.api.model.Info;
import com.github.dockerjava.api.model.Version;
import com.github.dockerjava.core.command.LogContainerResultCallback;
import com.github.dockerjava.core.command.PullImageResultCallback;
import com.github.dockerjava.core.command.WaitContainerResultCallback;
import lombok.Synchronized;
import org.slf4j.Logger;
import org.testcontainers.dockerclient.DockerClientConfigUtils;
import org.testcontainers.dockerclient.DockerConfigurationStrategy;
import org.testcontainers.dockerclient.DockerMachineConfigurationStrategy;
import org.testcontainers.dockerclient.EnvironmentAndSystemPropertyConfigurationStrategy;
import org.testcontainers.dockerclient.UnixSocketConfigurationStrategy;
import org.testcontainers.dockerclient.*;

import java.util.List;

Expand All @@ -34,13 +31,14 @@ public class DockerClientFactory {
private static final Logger LOGGER = getLogger(DockerClientFactory.class);

// Cached client configuration
private DockerClientConfig config;
private DockerClientProviderStrategy strategy;
private boolean preconditionsChecked = false;

private static final List<DockerConfigurationStrategy> CONFIGURATION_STRATEGIES =
asList(new EnvironmentAndSystemPropertyConfigurationStrategy(),
new DockerMachineConfigurationStrategy(),
new UnixSocketConfigurationStrategy());
private static final List<DockerClientProviderStrategy> CONFIGURATION_STRATEGIES =
asList(new EnvironmentAndSystemPropertyClientProviderStrategy(),
new ProxiedUnixSocketClientProviderStrategy(),
new UnixSocketClientProviderStrategy(),
new DockerMachineClientProviderStrategy());

/**
* Private constructor
Expand Down Expand Up @@ -77,15 +75,23 @@ public DockerClient client() {
*/
@Synchronized
public DockerClient client(boolean failFast) {
if (config == null) {
config = DockerConfigurationStrategy.getFirstValidConfig(CONFIGURATION_STRATEGIES);

if (strategy == null) {
strategy = DockerClientProviderStrategy.getFirstValidStrategy(CONFIGURATION_STRATEGIES);
}

DockerClient client = DockerClientBuilder.getInstance(config).build();
DockerClient client = strategy.getClient();

if (!preconditionsChecked) {
String version = client.versionCmd().exec().getVersion();
checkVersion(version);
Info dockerInfo = client.infoCmd().exec();
Version version = client.versionCmd().exec();
LOGGER.info("Connected to docker: \n" +
" Server Version: " + dockerInfo.getServerVersion() + "\n" +
" API Version: " + version.getApiVersion() + "\n" +
" Operating System: " + dockerInfo.getOperatingSystem() + "\n" +
" Total Memory: " + dockerInfo.getMemTotal() / (1024 * 1024) + " MB");

checkVersion(version.getVersion());
checkDiskSpaceAndHandleExceptions(client);
preconditionsChecked = true;
}
Expand All @@ -98,19 +104,11 @@ public DockerClient client(boolean failFast) {
return client;
}

/**
* @param config docker client configuration to extract the host IP address from
* @return the IP address of the host running Docker
*/
private String dockerHostIpAddress(DockerClientConfig config) {
return DockerClientConfigUtils.getDockerHostIpAddress(config);
}

/**
* @return the IP address of the host running Docker
*/
public String dockerHostIpAddress() {
return dockerHostIpAddress(config);
return strategy.getDockerHostIpAddress();
}

private void checkVersion(String version) {
Expand Down Expand Up @@ -147,10 +145,13 @@ private void checkDiskSpace(DockerClient client) {

client.startContainerCmd(id).exec();

client.waitContainerCmd(id).exec();

LogContainerResultCallback callback = client.logContainerCmd(id).withStdOut().exec(new LogContainerCallback());
LogContainerResultCallback callback = client.logContainerCmd(id).withStdOut(true).exec(new LogContainerCallback());
try {

WaitContainerResultCallback waitCallback = new WaitContainerResultCallback();
client.waitContainerCmd(id).exec(waitCallback);
waitCallback.awaitStarted();

callback.awaitCompletion();
String logResults = callback.toString();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.testcontainers.containers;

import com.github.dockerjava.api.DockerException;
import com.github.dockerjava.api.exception.DockerException;
import com.github.dockerjava.api.model.Container;
import lombok.Data;
import lombok.EqualsAndHashCode;
Expand All @@ -26,9 +26,9 @@ public class AmbassadorContainer<SELF extends AmbassadorContainer<SELF>> extends
public AmbassadorContainer(LinkableContainer otherContainer, String serviceName, int servicePort) {
super("richnorth/ambassador:latest");

/**
* Use the unique 'identifierPrefix' (random compose project name) so that the ambassador can see
* the container it's supposed to be proxying.
/*
Use the unique 'identifierPrefix' (random compose project name) so that the ambassador can see
the container it's supposed to be proxying.
*/
this.otherContainerName = otherContainer.getContainerName();
this.serviceName = serviceName;
Expand Down
22 changes: 14 additions & 8 deletions core/src/main/java/org/testcontainers/containers/Container.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ public String getStderr() {
/**
* Add a link to another container.
*
* @param otherContainer
* @param alias
* @param otherContainer the other container object to link to
* @param alias the alias (for the other container) that this container should be able to use
*/
void addLink(LinkableContainer otherContainer, String alias);

Expand Down Expand Up @@ -145,6 +145,14 @@ public String getStderr() {
*/
SELF withEnv(String key, String value);

/**
* Add environment variables to be passed to the container.
*
* @param env map of environment variables
* @return this
*/
SELF withEnv(Map<String, String> env);

/**
* Set the command that should be run in the container
*
Expand All @@ -163,12 +171,14 @@ public String getStderr() {

/**
* Add an extra host entry to be passed to the container
* @param hostname
* @param ipAddress
* @param hostname hostname to use for this hosts file entry
* @param ipAddress IP address to use for this hosts file entry
* @return this
*/
SELF withExtraHost(String hostname, String ipAddress);

SELF withNetworkMode(String networkMode);

/**
* Map a resource (file or directory) on the classpath to a path inside the container.
* This will only work if you are running your tests outside a Docker container.
Expand Down Expand Up @@ -303,8 +313,6 @@ ExecResult execInContainer(Charset outputCharset, String... command)

Map<String, LinkableContainer> getLinkedContainers();

Duration getMinimumRunningDuration();

DockerClient getDockerClient();

Info getDockerDaemonInfo();
Expand All @@ -331,8 +339,6 @@ ExecResult execInContainer(Charset outputCharset, String... command)

void setLinkedContainers(Map<String, LinkableContainer> linkedContainers);

void setMinimumRunningDuration(Duration minimumRunningDuration);

void setDockerClient(DockerClient dockerClient);

void setDockerDaemonInfo(Info dockerDaemonInfo);
Expand Down
Loading