How to isolate docker container tests with Jenkins?

79 views
Skip to first unread message

Stephen Person

unread,
Sep 4, 2019, 11:38:19 PM9/4/19
to Jenkins Users
For the life of me I cannot come up with an efficient solution to running tests against a docker container in an isolated environment with Jenkins. Emphasis on 'isolated environment' so many builds/tests can run in parallel without interference. I have tried the docker-in-docker approach but this caused many complications with networking and other stuff which compromised the functionality of my containers.

Some things worth mentioning...
1. I use docker-compose to build and start my container and all dependent containers (like activemq, postgres, etc)
2. Limited to using Host Network for all containers (cant use ip-forwarding)

As you can tell, I think about the container as the final artifact I'm delivering to production, which is why it's important to run tests against the container instead of inside it. Any and all thought is greatly appreciated. 

Jan Monterrubio

unread,
Sep 6, 2019, 3:04:40 PM9/6/19
to jenkins...@googlegroups.com
Mind clarifying a bit here:

By isolated , do you mean something like:

in a docker agent (jnlp pod/whatever) {

check out your project
run your build
- the build launches containers


We use docker for isolation, so well usually have something like maven/gradle build our service/app, create an image, launch a container from that image, and then a test project (as part of the build) hits localhost:SomePort, where some port is randomly assigned externally but mapped to the containers 8080. 

Maybe it would help if you shared some details on how you build all this? We are able to build both on our machines and our Jenkins with the same setup. 

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/405a49ff-6f85-4083-92ad-f8c18a34ab5f%40googlegroups.com.

Stephen Person

unread,
Sep 6, 2019, 5:36:01 PM9/6/19
to Jenkins Users
Thanks for the reply. I'm building a camel spring standalone with spring-boot, built with maven, in a minimal base image. I have a junit test suite that is basically - drop file in directory and listen to activemq topic. I define the appropriate container volumes in docker-compose.yml. My current pipeline for jenkins goes like...
1. mvn clean package -DskipTests
2. docker build -t <image> .
3. mvn verify
4. docker push <image>

This works great for one-build-at-a-time but running multiple instances in parallel causes chaos for my tests, so my solution was to limit the amount of executors for Jenkins to 1 which just isn't practical when I have many git branches and projects that rely on my Jenkins node.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkins...@googlegroups.com.

Jan Monterrubio

unread,
Sep 7, 2019, 1:03:37 AM9/7/19
to jenkins...@googlegroups.com
This might give you some idea on how to configure this. This is something that we sort of do:

All of this is in a gradle multi-module project.

java-application
  -> jar gets dropped into an image
mqimage
  -> docker builds this too
test-project
  -> uses the gradle docker-compose plugin to orchestrate both mq and the java service
  -> has src/test/java hit the service at a port exposed on 8080 (internally)

So, everything can build on my machine with gradle and it is isolated. Then jenkins just has to call gradle and everything still works. 

With maven you could do the same thing with a mutli-module reactor

To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/c8764e83-2c19-438d-84e0-29ac32da0862%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages