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

Add support for compose v2 with ComposeContainer

Open eddumelendez opened this issue 3 years ago • 8 comments

Compose V2 offers arm images to perform docker compose commands. It will be available using ComposeContainer

public static ComposeContainer environment =
    new ComposeContainer(new File("src/test/resources/compose-test.yml"))
            .withExposedService("redis-1", REDIS_PORT, Wait.forListeningPort())
            .waitingFor("db-1", Wait.forLogMessage("started", 1));

eddumelendez avatar Jul 24 '22 05:07 eddumelendez

withComposeV2() should be called before .withExposedService("redis-1", REDIS_PORT, Wait.forListeningPort()) otherwise the name generated will contain underscores instead of hyphens. I was thinking on adding new constructors instead of withComposeV2()

new DockerComposeContainer(Compose.V2, new File("src/test/resources/compose-test.yml"))

eddumelendez avatar Jul 24 '22 05:07 eddumelendez

following @kiview suggestion. pr has been updated to opt-in for compose v2 via config property

eddumelendez avatar Jul 28 '22 20:07 eddumelendez

/azp run

kiview avatar Aug 04 '22 13:08 kiview

Azure Pipelines successfully started running 1 pipeline(s).

azure-pipelines[bot] avatar Aug 04 '22 13:08 azure-pipelines[bot]

ComposeContainer has been introduced in order to offer compose v2 support in testcontainers.

Why another container class? The previous attempts to add support for compose v2 in DockerComposeContainer was relying too much on the name for the exposed services and compatibility flag. Sadly, not all scenarios (scaling, compose file v2) are covered with those changes and will be introducing a breaking change. Also, it introduces certain complexity in order to run tests for the previous version and v2, something in mind was having a specific directory for compose tests with the property enabled/disabled, so we can ensure v1 and v2 are supported in DockerComposeContainer.

Adding ComposeContainer, users can decide to switch to it and run in compatibility mode if they want, for example, rename from DockerComposeContainer to ComposeContainer and add the compatibility option with no changes in the exposed services. The benefits of doing so are, users aware of the change and it is up to them to move, easy to test from our side, easy to maintain (no hacks) and it offers the same features.

waiting for feedback about those changes.

eddumelendez avatar Aug 16 '22 22:08 eddumelendez

I have updated DockerComposeContainer so far using ComposeConfiguration, class with centralized configuration for DockerComposeContainer and ComposeContainer (compose v2 implementation). I would wait for feedback on this and then I can move ComposeContainer

eddumelendez avatar Sep 27 '22 15:09 eddumelendez

Hi, what's the status of this PR?

pan3793 avatar Nov 25 '22 08:11 pan3793

I also would like to ask about the status. The problem we are having is that we need to support some features from V2, we are spinning up the infrastructure from compose file, which would be a bit more complex in declarative way.

martinformi avatar Dec 16 '22 11:12 martinformi

Hi @kiview !

Is there any news on this PR here? According to the docker docs, the compose V1 will be removed in June 2023 from all Docker Desktop versions: https://docs.docker.com/compose/compose-v2/. That could mean, that any Windows user can not use Testcontainers anymore, am I right?

Is there any way to get this PR merged soon? :)

Waize avatar May 02 '23 04:05 Waize

following option did worked for me, using .withOptions("--compatibility")

Are you using the latest state on the main branch? I've added there .withOptions("--compatibility") to the AbstractWebTest class and the DockerCompose setup, which https://github.com/testcontainers/testcontainers-java/issues/4565.

https://github.com/rieckpil/testing-spring-boot-applications-masterclass/issues/305#issuecomment-1501027043

ismailsimsek avatar May 03 '23 18:05 ismailsimsek

@eddumelendez what is the schedule for the next release?

From July 2023 Compose V1 stopped receiving updates. It’s also no longer available in new releases of Docker Desktop.

https://docs.docker.com/compose/migrate/

pan3793 avatar Jul 06 '23 06:07 pan3793

Also interested in the ETA on the next release as we'd love to have this fix available in a published version.

PandarinDev avatar Jul 06 '23 15:07 PandarinDev

Hi @eddumelendez . Are there any news for the ETA on the next release?

Waize avatar Jul 24 '23 06:07 Waize