Make it possible to run TestContainers inside a container#267
Conversation
| @@ -0,0 +1 @@ | |||
| distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.3.9/apache-maven-3.3.9-bin.zip No newline at end of file | |||
There was a problem hiding this comment.
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 :)
| - 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 |
There was a problem hiding this comment.
classpath contains 2.52, but we were pulling 2.45 and then 2.52
circle.yml
Outdated
| # 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 \ |
There was a problem hiding this comment.
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
|
|
||
| strategy = DockerClientProviderStrategy.getFirstValidStrategy(CONFIGURATION_STRATEGIES); | ||
|
|
||
| log.info("Docker host IP address is {}", strategy.getDockerHostIpAddress()); |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
the best way to check I found, libnetwork uses it as well, so it's here to stay
| } | ||
|
|
||
| LOGGER.info("Found docker client settings from environment"); | ||
| LOGGER.info("Docker host IP address is {}", DockerClientConfigUtils.getDockerHostIpAddress(config)); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
GenericContainerRuleTest covers most of the cases. Right now we can't use all the tests because some of them make incorrect assumptions
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Ok, I'll change it :) Just wanted to save a few seconds of pulling
| @@ -0,0 +1 @@ | |||
| distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.3.9/apache-maven-3.3.9-bin.zip No newline at end of file | |||
| - 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 |
| -v "$(pwd)":"$(pwd)" \ | ||
| -w "$(pwd)" \ | ||
| selenium/standalone-chrome-debug:2.52.0 \ | ||
| ./mvnw -B -pl core test -Dtest=*GenericContainerRuleTest |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Wish we could :) This class is shared between different packages :(
There was a problem hiding this comment.
No problem then - the type system will at least help people not use the wrong thing.
|
@rnorth applied the fixes. Could you please take a look again? |
rnorth
left a comment
There was a problem hiding this comment.
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?
|
@rnorth yes, I'll update the docs in this branch, thanks for reminding me :) |
|
@rnorth pushed the docs. Would highly appreciate picky review of it :) |
|
@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? |
|
Absolutely! Thanks:)
…On Sat, 21 Jan 2017 at 19:04, Richard North ***@***.***> wrote:
@bsideup <https://github.com/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?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#267 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABAIiuPA5SUKGcyVr3XdIS-LnaMh2kJjks5rUjqegaJpZM4Lj7iy>
.
|
f4af27f to
7f36420
Compare
7f36420 to
e6d8be0
Compare
Fixes #264
Known issues: