Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for compose v2 with ComposeContainer #5608

Merged
merged 48 commits into from
Jun 21, 2023
Merged

Add support for compose v2 with ComposeContainer #5608

merged 48 commits into from
Jun 21, 2023

Conversation

eddumelendez
Copy link
Member

@eddumelendez eddumelendez commented Jul 24, 2022

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

ComposeContainer behaves similar to DockerComposeContainer with just one hint, service names should use - rather than _.

Why a new class?

During development we were evaluating different approaches such as introducing a new flag to opt-in to v2. However, we decided to move most of the config to an internal class ComposeDelegate which can be used in the future for new version of ComposeContainer instead of adding more branches to the existing DockerComposeContainer.

[Compose V2](https://www.docker.com/blog/announcing-compose-v2-general-availability/)
offers arm images to perform `docker compose` commands. It should be
enabled

```java
public static DockerComposeContainer environment =
    new DockerComposeContainer(new File("src/test/resources/compose-test.yml"))
            .withComposeV2()
            .withExposedService("redis-1", REDIS_PORT, Wait.forListeningPort())
            .waitingFor("db-1", Wait.forLogMessage("started", 1));
```
@eddumelendez eddumelendez requested a review from a team as a code owner July 24, 2022 05:09
@eddumelendez
Copy link
Member Author

eddumelendez commented Jul 24, 2022

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
Copy link
Member Author

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

Copy link
Member

@kiview kiview left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks generally fine, just a couple of minor remarks. Did you already try it with a local compose?

docs/features/configuration.md Outdated Show resolved Hide resolved
docs/modules/docker_compose.md Outdated Show resolved Hide resolved
docs/modules/docker_compose.md Outdated Show resolved Hide resolved
@eddumelendez eddumelendez requested a review from kiview July 29, 2022 21:27
@eddumelendez eddumelendez added this to the next milestone Jul 30, 2022
@Waize
Copy link

Waize commented May 2, 2023

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

@ismailsimsek
Copy link

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 #4565.

rieckpil/testing-spring-boot-applications-masterclass#305 (comment)

kiview
kiview previously approved these changes May 26, 2023
Copy link
Member

@kiview kiview left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's update the PR description with the reasons behind the design decision to introduce a new class for Docker Compose V2 and hence have users explicitly switch to using V2 through this 👍

```java
public static ComposeContainer environment =
new ComposeContainer(new File("src/test/resources/compose-test.yml"))
.withExposedService("redis-1", REDIS_PORT, Wait.forListeningPort())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need an explicit note, that users need to be aware of using - instead of _ for V2 services in their code.

@eddumelendez eddumelendez added this to the next milestone Jun 20, 2023
@pan3793
Copy link
Contributor

pan3793 commented Jul 6, 2023

@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/

@PandarinDev
Copy link

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

@Waize
Copy link

Waize commented Jul 24, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants