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

Add missing function `WithDockerCompose`

Open SbiCA opened this issue 6 years ago • 31 comments

Is your feature request related to a problem? Please describe. I love the approach of having a single container scenario for a test case but there are also scenarios where I'd like to spin up a whole set of containers and therefore use docker-compose as declaration.

Describe the solution you'd like I'd like to spin up a set of containers by specifying a docker-compose.yml similar to the Java version https://www.testcontainers.org/modules/docker_compose/

Describe alternatives you've considered Not sure If there is one

  • configuring the things as in the compose in code seems odd to me and leads to duplication of configuration and most of the times docker-compose.yml will also be used to deploy the application under test this would be strange.

Additional context Also other library authors could benefit from such an approach, I happen to know that https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks is using compose and I think it would be great improvement on there development experience (since you don' t have to remember starting the containers in advance ;) )

Cheers & let me know what you think of the idea

SbiCA avatar Aug 12 '19 09:08 SbiCA

Hi @SbiCA, a great feature for sure. I think docker compose supports a lot of different use cases and is a very important feature. I had it on my list right from the start (#4), but I never had time for it.

This week I would like to improve some small parts in the build pipeline and add another section to the README.md about your issue #120. Next week I’m busy, but I could start working on this feature the following week.

Of course, your help is always welcome! If you like, just go ahead and start with a feature branch - or we'll work together on this feature. What do you think?

HofmeisterAn avatar Aug 12 '19 14:08 HofmeisterAn

@HofmeisterAn sure I would be open for collaboration, since I'm in a similar situation regarding my availability. Maybe we could have a gitter or slack channel for that purpose or what would be your favorite way of having design discussions?

SbiCA avatar Aug 15 '19 06:08 SbiCA

Gitter, Slack or MS Teams would be nice. I'm using all three of them. Anything you prefer? As soon as I’m back next week we can start having design discussions.

HofmeisterAn avatar Aug 21 '19 05:08 HofmeisterAn

@SbiCA I think it would be great if you join the official Slack channel: http://slack.testcontainers.org/. Maybe, we can add the feature already in the official project? What do you think?

HofmeisterAn avatar Aug 27 '19 08:08 HofmeisterAn

Waiting for this feature too!

tcfialho avatar Jan 18 '21 06:01 tcfialho

I agree, this feature would be great. Maybe you can get in touch with @SbiCA. A pull request is more than welcome. I am happy to help as much as I can, like feature discussions, tests, code reviews, etc. I just can’t bring myself to do all the development now, due other projects.

HofmeisterAn avatar Jan 19 '21 06:01 HofmeisterAn

Same here 😢 , sorry for having raised the expectations/adding delay here.

SbiCA avatar Jan 19 '21 08:01 SbiCA

Any way to join?

maranmaran avatar Apr 25 '22 20:04 maranmaran

I think no one started yet. Would you like to start? Maybe some more will join than.

HofmeisterAn avatar Apr 26 '22 05:04 HofmeisterAn

I'd be happy to help, is anyone working on it?

LoremFooBar avatar Jul 30 '22 17:07 LoremFooBar

I think no one is working on it right now. Contribution is more than welcome.

HofmeisterAn avatar Jul 31 '22 08:07 HofmeisterAn

Cool, I'll give it a shot.

LoremFooBar avatar Jul 31 '22 21:07 LoremFooBar

Thinking about the API design for this, I have a few points to raise:

  1. Since all of the public API surface revolves around working with a single container, I propose this API for compose:

    var compose = new DockerComposeBuilder()
      .WithComposeFile("path/to/docker-compose.yml")
      .Build();
    
    await compose.UpAsync();
    await compose.DownAsync();
    
  2. Regarding implementation - since compose is not part of the Docker Engine API, and the docker compose command has been part of Docker Desktop for a while now, I assume it is acceptable to use the docker compose command for the different compose methods (docker compose up, docker compose down etc.).

LoremFooBar avatar Aug 02 '22 18:08 LoremFooBar

It would be nice to consider the testcontainers-java implementation. I'm not very familiar with it, but I think it is a good idea not to differentiate too much. OC, it should still be idiomatic with .NET.

HofmeisterAn avatar Aug 03 '22 15:08 HofmeisterAn

The java implementation is spinning a container to run compose commands, I assume because they could not assume docker-compose is installed on all machines back when it was implemented. This is where I think it makes sense to diverge from their implementation, because for a long time now compose is bundled with Docker Desktop.

LoremFooBar avatar Aug 03 '22 16:08 LoremFooBar

May I ask how do you plan on implementing this?

https://github.com/mariotoffia/FluentDocker seems neatly implemented.

Are you on official slack? @LoremFooBar

maranmaran avatar Aug 04 '22 20:08 maranmaran

Basically by running docker compose commands. I'll ping you on slack.

LoremFooBar avatar Aug 08 '22 21:08 LoremFooBar

The java implementation is spinning a container to run compose commands, I assume because they could not assume docker-compose is installed on all machines back when it was implemented. This is where I think it makes sense to diverge from their implementation, because for a long time now compose is bundled with Docker Desktop.

what about running these tests as part of the CI pipeline for example? Probably this is the importance of having a docker image with docker compose client in it

hmonzer avatar Aug 22 '22 20:08 hmonzer

The java implementation is spinning a container to run compose commands, I assume because they could not assume docker-compose is installed on all machines back when it was implemented. This is where I think it makes sense to diverge from their implementation, because for a long time now compose is bundled with Docker Desktop.

what about running these tests as part of the CI pipeline for example? Probably this is the importance of having a docker image with docker compose client in it

I find it reasonable to have the developer properly set up a CI environment for their needs, and that includes any binaries required to run their tests. We can ensure a clear error message is displayed when compose is unavailable on the machine. IMO the alternative is over complicated for most cases.

LoremFooBar avatar Aug 23 '22 16:08 LoremFooBar

Any news about it?

tabata22 avatar Jan 03 '23 08:01 tabata22

Unfortunately, I was not able to make much progress eventually.

LoremFooBar avatar Jan 03 '23 16:01 LoremFooBar

Still working on this feature? Currently this is the only feature that still makes us use FluentDocker instead of TestContainers...

FredericVaugeoisFlo avatar Jul 11 '23 14:07 FredericVaugeoisFlo

I think nobody is working on the Compose support right now.

HofmeisterAn avatar Jul 11 '23 17:07 HofmeisterAn

Hi @HofmeisterAn I really need this feature in my project, so I think I can make it happen. I'll keep you updated.

nkz-soft avatar Dec 29 '23 17:12 nkz-soft

is this feature any closer to being merged? I'm happy to help where I can to get this over the line/on par with the Java version. The only question is whether we should run a container (to run compose commands) as the Java version does, whether we should check whether docker compose is installed on the target system, whether we should require Docker desktop, or whether we should download and run a version of compose ourselves.

See here for more information.

Thanks, Sean.

SeanFarrow avatar Feb 15 '24 23:02 SeanFarrow

I came across this issue today after being a bit perplexed by the idea of a "Docker Wormhole Configuration"

It feels like a bit of an anti-pattern, and possibly a security concern. In the event that a container is compromised, am I correct in concluding that there is an easy path to instructing the docker daemon to start other containers of any image on the host?

Further reference: https://ro14nd.de/Docker-Wormhole-Pattern

~I'll try to build and test patch #1082 over the next few days...~

TabLand avatar Feb 20 '24 21:02 TabLand

Hey! What's blocking the already-existing PR? We definitely need something like this in our project. Thanks

cvicenti-apr avatar Apr 03 '24 23:04 cvicenti-apr

Hey! What's blocking the already-existing PR? We definitely need something like this in our project. Thanks

I reviewed the pull request (#1082) some time ago and have a few suggestions and things I would like to discuss first (https://github.com/nkz-soft/testcontainers-dotnet/pull/1) before merging the feature and bringing it upstream.

HofmeisterAn avatar Apr 05 '24 06:04 HofmeisterAn