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

feat: Add docker compose support (#122)

Open nkz-soft opened this issue 1 year ago • 15 comments

What does this PR do?

Adds docker compose support

Why is it important?

We have docker compose support for java implementations, but that's not here yet. This PR does not contain a complete implementation of all methods in the java library, but it is a starting point from which you can begin to port the rest of the methods.

Related issues

  • Closes #122

Additional information

At this time, there are only two methods in the DockerComposeBuilder class:

  • WithLocalCompose - Specifies the docker-compose file that needs to be executed.
  • WithComposeFile - Whether or not to execute docker-composer locally or in a container.

Additional methods are available for implementing in Java, listed in order of importance (to me):

  • withOptions - Adds options to the docker-compose command, e.g. docker-compose --compatibility.
  • withRemoveImages - Remove images after containers shutdown.
  • withRemoveVolumes - Remove volumes after containers shut down.
  • withBuild - Whether to always build images before starting containers.
  • withExposedService - Specifies the port for current service. According to the documentation, Testcontainers will spin up a small 'ambassador' container, which will proxy between the Compose-managed containers and ports that are accessible to your tests. This is done using a separate, minimal container that runs socat as a TCP proxy. I don't fully understand the necessity of creating a proxy (ambassador) container here, perhaps to avoid port conflicts or to allow the port to listen.
  • getServiceHost - Returns the IP address where the container is listening (via an ambassador container).
  • getServicePort(serviceName, servicePort) - Returns the Docker mapped port for a port that has been exposed (via an ambassador container).

It's my opinion that we should start with the first four methods that cover 90% of the functionality. The implementation of proxy and port forwarding functions in docker-compose can be done directly through a yaml file.

nkz-soft avatar Jan 02 '24 12:01 nkz-soft

Deploy Preview for testcontainers-dotnet ready!

Name Link
Latest commit f1417d41de7f0077fbe72e15f7a59c4e3b29d5ca
Latest deploy log https://app.netlify.com/sites/testcontainers-dotnet/deploys/66221036e421140008db4057
Deploy Preview https://deploy-preview-1082--testcontainers-dotnet.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

netlify[bot] avatar Jan 02 '24 12:01 netlify[bot]

Thanks for the initial PR. Could you please provide additional information in the PR description, specifying which parts are addressed by the PR and which parts are not covered, in comparison to the features provided by Java? Additionally, what aspects do we need to take care of afterward? What follow-ups are necessary, etc.?

HofmeisterAn avatar Jan 03 '24 08:01 HofmeisterAn

Thanks for the initial PR. Could you please provide additional information in the PR description, specifying which parts are addressed by the PR and which parts are not covered, in comparison to the features provided by Java? Additionally, what aspects do we need to take care of afterward? What follow-ups are necessary, etc.?

I have added some additional information, but I am not sure that this is enough. Please take a look at this.

nkz-soft avatar Jan 03 '24 18:01 nkz-soft

I have added some additional information, but I am not sure that this is enough. Please take a look at this.

Thanks. I will need some days to review it. A lot of other topics have accumulated over the holidays.

HofmeisterAn avatar Jan 10 '24 06:01 HofmeisterAn

Hi, Any updates here?

dmytro-dovhan-gl avatar Jan 29 '24 13:01 dmytro-dovhan-gl

Hi, Any updates here?

Sorry, I haven't had the time yet, but it is the next item in my GH inbox. I cannot promise it, but I will try to look at it sometime next week.

HofmeisterAn avatar Jan 31 '24 17:01 HofmeisterAn

Thank you for the PR. Sorry for the late response, I hadn't found the time earlier. I still need to run and test it locally. Meanwhile, I have a couple of suggestions and improvements. It would be great if we could discuss and address them in the meantime. Thanks again for your contribution.

Thanks, I think next week, I'll check and fix all the issues.

nkz-soft avatar Feb 10 '24 11:02 nkz-soft

Thank you for the PR. Sorry for the late response, I hadn't found the time earlier. I still need to run and test it locally. Meanwhile, I have a couple of suggestions and improvements. It would be great if we could discuss and address them in the meantime. Thanks again for your contribution.

I think it's done, could you please review the code again?

nkz-soft avatar Feb 15 '24 17:02 nkz-soft

Please see my suggestions and comments here: https://github.com/nkz-soft/testcontainers-dotnet/pull/1. Overall, it looks good, but there are still a few things we need to discuss and sort out first.

HofmeisterAn avatar Apr 05 '24 06:04 HofmeisterAn

Hello all. Any updates of this PR. Really interesting in using this docker compose functionality

Best Regards

dava2788 avatar May 09 '24 14:05 dava2788

It'd also be nice to land support for podman's k8s yaml files (podman kube play) as well once podman support is actually finished.

kanpov avatar Jun 10 '24 16:06 kanpov

@nkz-soft Any updates on this? This would be really useful for our projects too!

InspiringCode avatar Jun 25 '24 15:06 InspiringCode

@nkz-soft Any updates on this? This would be really useful for our projects too!

@HofmeisterAn Unfortunately, I don't have a clue. I'm still waiting for a code review.

nkz-soft avatar Jul 16 '24 13:07 nkz-soft

Id also really like to see progress on this, would make setting up testcontainers so much easier in certain scenarios where you already have a docker-compose. So upvote from me :)

JBastiaan avatar Jul 16 '24 14:07 JBastiaan

We need to merge the develop branch and address the build issues first. Additionally, I still believe this does not contain the necessary features developers expect for an MVP. We can split the Docker Compose support into multiple PRs, but we would need something like a feature flag for the current state (opt-in) incl. docs about the current capabilities. The implementation does not or cannot indicate the readiness of the containers (i.e., when the services are actually running, known as wait strategies), nor is it able to retrieve the Docker mapped ports for exposed ports. Which IMO are very basic and necessary features to write reliable tests.

HofmeisterAn avatar Jul 17 '24 08:07 HofmeisterAn