Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

One of the main advantages of Docker is the isolated environment it brings, and I want to leverage that advantage in my continuous integration workflow.

A "normal" CI workflow goes something like this:

  • Poll repository for changes
  • Pull from repository
  • Install dependencies
  • Run tests

In a Dockerized workflow, it would be something like this:

  • Poll repository for changes
  • Pull from repository
  • Build docker image
  • Run docker image as container
  • Run tests
  • Kill docker container

My problem is with the "run tests" step: since Docker is an isolated environment, intuitively I would like to treat it as one; this means the preferred method of communication are sockets. However, this only works well in certain situations (a webapp, for example). When testing different kind of services (for example, a background service that only communicated with a database), a different approach would be required.

What is the best way to approach this problem? Is it a problem with my application's design, and should I design it in a more TDD, service-oriented way that always listens on some socket? Or should I just give up on isolation, and do something like this:

  • Poll repository for changes
  • Pull from repository
  • Build docker image
  • Run docker image as container
  • Open SSH session into container
  • Run tests
  • Kill docker container

SSH'ing into the container seems like an ugly solution to me, since it requires deep knowledge of the contents of the container, and thus break the isolation.

I would love to hear SO's different approaches to this problem.

share|improve this question

1 Answer 1

You may invert the logic by moving test runner to the docker image:

  1. Tests are run within the docker image, so they access the application like in any other context, and the presence of docker doesn't change anything.

  2. Aggregating test results is where connection becomes an issue. The actual technology used will depend on your current infrastructure. It may as well be a message queue, a custom API or a direct access to the database.

  3. Since it belongs to the process which runs inside a docker image to report the test results, and not to the central service to pull the results from the test runners, it means that again, the presence of docker image doesn't make any difference.

share|improve this answer
    
What method would you use to run the tests within the image? Wouldn't that require SSH'ing to the container and run 'make test' (or any other command) ? –  Leon Mergen Jun 10 at 4:57

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.