Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it possible to run TestContainers inside a container #267

Merged
merged 5 commits into from
Jan 22, 2017

Conversation

bsideup
Copy link
Member

@bsideup bsideup commented Jan 15, 2017

Fixes #264

Known issues:

  • file mounting will obviously fail, at least if PWD is not the same

@@ -0,0 +1 @@
distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.3.9/apache-maven-3.3.9-bin.zip
Copy link
Member Author

Choose a reason for hiding this comment

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

I've added Maven Wrapper ( https://github.com/takari/maven-wrapper ) to make it possible to run TC build inside any container with Java 8. It's also nice to have anyway :)

Copy link
Member

Choose a reason for hiding this comment

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

Yep - good idea!

@@ -19,8 +19,8 @@ before_install:
- docker pull mysql:5.6
- docker pull mysql:5.5
- docker pull postgres:latest
- docker pull selenium/standalone-chrome-debug:2.45.0
- docker pull selenium/standalone-firefox-debug:2.45.0
- docker pull selenium/standalone-chrome-debug:2.52.0
Copy link
Member Author

Choose a reason for hiding this comment

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

classpath contains 2.52, but we were pulling 2.45 and then 2.52

Copy link
Member

Choose a reason for hiding this comment

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

👍

# Run Docker-in-Docker tests
# Yes, we use selenium image, but we use it anyway in BrowserContainer's tests
- >
docker -H unix:///var/run/docker.sock run --rm \
Copy link
Member Author

Choose a reason for hiding this comment

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

had to duplicate. I can extract it to .sh file to share, but we don't use CircleCI anymore, right? Probably the config should be removed then

@@ -80,20 +79,29 @@ public DockerClient client() {
}

strategy = DockerClientProviderStrategy.getFirstValidStrategy(CONFIGURATION_STRATEGIES);

log.info("Docker host IP address is {}", strategy.getDockerHostIpAddress());
Copy link
Member Author

Choose a reason for hiding this comment

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

moved here to avoid the cycling dependency

if (!images.stream().anyMatch(it -> it.getRepoTags() != null && asList(it.getRepoTags()).contains("alpine:3.2"))) {
PullImageResultCallback callback = client.pullImageCmd("alpine:3.2").exec(new PullImageResultCallback());
callback.awaitSuccess();
public <T> T runInsideDocker(Consumer<CreateContainerCmd> createContainerCmdConsumer, BiFunction<DockerClient, String, T> block) {
Copy link
Member Author

Choose a reason for hiding this comment

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

wish I could make it module-level, but I can't because the consumer is in dockerclient subpackage

public class DockerClientConfigUtils {

// See https://github.com/docker/docker/blob/a9fa38b1edf30b23cae3eade0be48b3d4b1de14b/daemon/initlayer/setup_unix.go#L25
public static final boolean IN_A_CONTAINER = new File("/.dockerenv").exists();
Copy link
Member Author

Choose a reason for hiding this comment

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

the best way to check I found, libnetwork uses it as well, so it's here to stay

@@ -27,7 +27,6 @@ public void test() throws InvalidConfigurationException {
}

LOGGER.info("Found docker client settings from environment");
LOGGER.info("Docker host IP address is {}", DockerClientConfigUtils.getDockerHostIpAddress(config));
Copy link
Member Author

Choose a reason for hiding this comment

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

moved to DockerClientFactory

public static TestRule assumption = new TestWatcher() {
@Override
public Statement apply(Statement base, Description description) {
assumeTrue("We're inside a container", DockerClientConfigUtils.IN_A_CONTAINER);
Copy link
Member Author

Choose a reason for hiding this comment

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

we could add some IP-specific tests here, so this assumption will protect them from running in non-container mode

-v "$(pwd)":"$(pwd)" \
-w "$(pwd)" \
selenium/standalone-chrome-debug:2.52.0 \
./mvnw -B -pl core test -Dtest=*GenericContainerRuleTest
Copy link
Member Author

Choose a reason for hiding this comment

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

GenericContainerRuleTest covers most of the cases. Right now we can't use all the tests because some of them make incorrect assumptions

Copy link
Member

Choose a reason for hiding this comment

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

Is the selenium container image just used here because it includes Java? It's potentially a bit misleading..

If so, I wouldn't worry about pulling an openjdk image and using that.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, I'll change it :) Just wanted to save a few seconds of pulling

@bsideup bsideup requested a review from rnorth January 15, 2017 16:14
@bsideup bsideup self-assigned this Jan 15, 2017
@bsideup bsideup added this to the 1.1.8 milestone Jan 15, 2017
@@ -0,0 +1 @@
distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.3.9/apache-maven-3.3.9-bin.zip
Copy link
Member

Choose a reason for hiding this comment

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

Yep - good idea!

@@ -19,8 +19,8 @@ before_install:
- docker pull mysql:5.6
- docker pull mysql:5.5
- docker pull postgres:latest
- docker pull selenium/standalone-chrome-debug:2.45.0
- docker pull selenium/standalone-firefox-debug:2.45.0
- docker pull selenium/standalone-chrome-debug:2.52.0
Copy link
Member

Choose a reason for hiding this comment

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

👍

-v "$(pwd)":"$(pwd)" \
-w "$(pwd)" \
selenium/standalone-chrome-debug:2.52.0 \
./mvnw -B -pl core test -Dtest=*GenericContainerRuleTest
Copy link
Member

Choose a reason for hiding this comment

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

Is the selenium container image just used here because it includes Java? It's potentially a bit misleading..

If so, I wouldn't worry about pulling an openjdk image and using that.

import com.github.dockerjava.api.model.Frame;
import com.github.dockerjava.core.command.LogContainerResultCallback;

public class LogToStringContainerCallback extends LogContainerResultCallback {
Copy link
Member

Choose a reason for hiding this comment

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

Am I right in thinking that this exists because we can't use our container logging abstraction (with ToStringConsumer) this early in the startup process?

If that's the case, should we reduce visibility of this class from public so as to reduce confusion with our higher-level logging API?

Copy link
Member Author

Choose a reason for hiding this comment

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

Wish we could :) This class is shared between different packages :(

Copy link
Member

Choose a reason for hiding this comment

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

No problem then - the type system will at least help people not use the wrong thing.

@bsideup
Copy link
Member Author

bsideup commented Jan 16, 2017

@rnorth applied the fixes. Could you please take a look again?

Copy link
Member

@rnorth rnorth left a comment

Choose a reason for hiding this comment

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

Looks good to me! Thanks for doing this. We probably need to update the docs to mention this - do you have any thoughts on this?

@bsideup
Copy link
Member Author

bsideup commented Jan 21, 2017

@rnorth yes, I'll update the docs in this branch, thanks for reminding me :)

@bsideup
Copy link
Member Author

bsideup commented Jan 21, 2017

@rnorth pushed the docs. Would highly appreciate picky review of it :)

@rnorth
Copy link
Member

rnorth commented Jan 21, 2017

@bsideup the docs look fine - I might just tweak some of the wording. Would you mind if I take the branch now? I can rebase+squash, tweak docs, and merge if that's OK with you?

@bsideup
Copy link
Member Author

bsideup commented Jan 21, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants