-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
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 |
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 \ |
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
@@ -0,0 +1 @@ | |||
distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.3.9/apache-maven-3.3.9-bin.zip |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 :(
There was a problem hiding this comment.
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.
@rnorth applied the fixes. Could you please take a look again? |
There was a problem hiding this 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?
@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: