testcontainers-rs icon indicating copy to clipboard operation
testcontainers-rs copied to clipboard

A way to work with docker-compose ?

Open aesteve opened this issue 5 years ago • 11 comments

Hello, thanks for your work, and sorry to bother your issues with a question :\

Is there a way to use a docker-compose.yml file in order to setup our integration tests stack ? Similar to: https://www.testcontainers.org/modules/docker_compose/

Or is it limited to only images defined in the images folder (redis etc.).

If not possible atm, is it a feature you'd like to have in the future ?

Thank you.

aesteve avatar Feb 04 '19 11:02 aesteve

No need to apologize :)

At the moment, there is no docker-compose support and there are currently also no plans to add it. We would probably need to put in some thoughts on how this can be useful as part of running tests from within Rust. We haven't had the need for this yet. If you do, it would be very helpful if you could write it down!

Regarding the availability of images: As soon as #58 lands, you should be able to very easily create containers for images that are not yet in images. However, the long-term goal is to provide a rich set of images that just work out-of-the box, so if you are missing some, feel free to send a PR :)

thomaseizinger avatar Feb 05 '19 05:02 thomaseizinger

Thanks for your answer!

One standard use-case of docker-compose in "tests within rust" would be Kafka I guess. In fact, when opening the issue I was reading : https://github.com/spicavigo/kafka-rust/blob/master/tests/run-all-tests Because a working Kafka cluster relies on two images : kafka & zookeeper.

So for instance, in order to test this library, one has to setup Kafka through docker-compose (obviously). I guess this may be a common pattern among library developers. And the most well-tested libraries, the better :)

aesteve avatar Feb 05 '19 12:02 aesteve

Good point.

Reading up on how testcontainers-java does it, they actually run docker-compose using a docker container :open_mouth:

We could also start with a similar approach as we did for docker and simply call the native docker-compose binary :)

Unfortunately, we don't have the resources and the need to tackle this at the moment. Feel free to give it a go :)

thomaseizinger avatar Feb 06 '19 05:02 thomaseizinger

I can give this a try although I'm a complete beginner. Could you point me at what you mean by "as we did for docker" ? Please ? It's not totally clear for me. Thank you

aesteve avatar Feb 06 '19 15:02 aesteve

To talk to the docker host, we currently simply shell out to the docker binary here: https://github.com/testcontainers/testcontainers-rs/blob/master/cli_client/src/cli.rs

The whole thing is abstracted over through the Docker trait so that we can replace it with an HTTP client at some point and talk to the docker daemon directly.

For docker-compose, we can do something similar although we don't need the a trait here. I think having a separate crate tc_docker_compose would be sufficient. You'd probably have a struct/module that represents the docker-compose binary and provides an interface for all the commands that you want to execute.

thomaseizinger avatar Feb 07 '19 04:02 thomaseizinger

Perfect pointer! Thank you. I think up, down would be sufficient.

If it's just calling the docker-compose command under the hood, it may be easy and I can give it a try. Just curious about the "wait for container started" thing though. Maybe, it's not needed with the "health checks" provided by docker-compose ? Not sure, I need to try.

aesteve avatar Feb 07 '19 07:02 aesteve

That one is a bit tricky. What you could try to do is redirect all the traffic into individual files and read them again as things are starting up.

I am not too familiar with the healthchecks though. Will have to look it up :)

Looking at what testcontainers-java does might not hurt in terms of possible features ;)

thomaseizinger avatar Feb 08 '19 11:02 thomaseizinger

Hello,

I have a prototype that works with shell out and docker compose v2.x. The code is planned to be open-sourced later, but at the time it's still in a private crate. It's async with Tokio, but if necessary I could create a sync version.

Are you interested in a PR? Or maybe it's a better idea to create a separate crate?

IgorLaborieWefox avatar Aug 25 '22 16:08 IgorLaborieWefox

Feel free to open a PR! I cant promise that it will be merged in though, that depends a lot on the design and how it fits into this crate :)

thomaseizinger avatar Aug 28 '22 18:08 thomaseizinger

Just informing everyone interested, we are doing a major revision of testcontainers and adding docker-compose in our plans. Please note the changed API (see readme)

So anyone who wants to help with this is welcome 🙂

DDtKey avatar Apr 22 '24 10:04 DDtKey