testcontainers / testcontainers-rs

A library for integration-testing against docker containers from within Rust.
https://rust.testcontainers.org
Apache License 2.0
704 stars 137 forks source link

A way to work with docker-compose ? #59

Open aesteve opened 5 years ago

aesteve commented 5 years ago

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.

thomaseizinger commented 5 years ago

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 :)

aesteve commented 5 years ago

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 :)

thomaseizinger commented 5 years ago

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 :)

aesteve commented 5 years ago

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

thomaseizinger commented 5 years ago

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.

aesteve commented 5 years ago

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.

thomaseizinger commented 5 years ago

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 ;)

IgorLaborieWefox commented 2 years ago

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?

thomaseizinger commented 2 years ago

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 :)

DDtKey commented 4 months ago

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

So anyone who wants to help with this is welcome 🙂

DDtKey commented 3 months ago

I'm starting to work on the feature in spare time

feelingsonice commented 1 week ago

Would love this as well. Not sure if I can try it out right now?

DDtKey commented 1 week ago

Not at the moment unfortunately as I've had limited bandwidth for the last couple of months

I'll continue working on this once have time