Skip to content

Commit 5abbf1f

Browse files
author
raju.gupta
committed
Merge remote-tracking branch 'upstream/main'
# Conflicts: # core/src/test/java/org/testcontainers/containers/ComposeOverridesTest.java # core/src/test/java/org/testcontainers/containers/DockerComposeOverridesTest.java # core/src/test/java/org/testcontainers/junit/BaseComposeTest.java # core/src/test/java/org/testcontainers/junit/DockerComposeContainerTest.java # modules/junit-jupiter/src/test/java/org/testcontainers/junit/jupiter/DockerComposeContainerTests.java # modules/localstack/src/test/java/org/testcontainers/localstack/LocalStackContainerTest.java # modules/mariadb/src/test/java/org/testcontainers/mariadb/MariaDBContainerTest.java # modules/mockserver/src/test/java/org/testcontainers/containers/MockServerContainerRuleTest.java # modules/mockserver/src/test/java/org/testcontainers/mockserver/MockServerContainerTest.java # modules/mongodb/src/test/java/org/testcontainers/mongodb/CompatibleImageTest.java # modules/mongodb/src/test/java/org/testcontainers/mongodb/MongoDBContainerTest.java # modules/mssqlserver/src/test/java/org/testcontainers/junit/mssqlserver/CustomizableMSSQLServerTest.java # modules/mysql/src/test/java/org/testcontainers/junit/mysql/CustomizableMysqlTest.java # modules/mysql/src/test/java/org/testcontainers/mysql/MySQLContainerTest.java # modules/neo4j/src/test/java/org/testcontainers/neo4j/Neo4jContainerTest.java # modules/orientdb/src/test/java/org/testcontainers/orientdb/OrientDBContainerTest.java # modules/postgresql/src/test/java/org/testcontainers/junit/postgresql/CustomizablePostgreSQLTest.java # modules/rabbitmq/src/test/java/org/testcontainers/containers/RabbitMQContainerTest.java # modules/toxiproxy/src/test/java/org/testcontainers/toxiproxy/ToxiproxyContainerTest.java
2 parents 38d6831 + 2cce248 commit 5abbf1f

File tree

153 files changed

+4033
-345
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

153 files changed

+4033
-345
lines changed

core/src/main/java/org/testcontainers/containers/ComposeContainer.java

Lines changed: 78 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import java.time.Duration;
1717
import java.util.ArrayList;
1818
import java.util.Arrays;
19+
import java.util.Collections;
1920
import java.util.HashMap;
2021
import java.util.HashSet;
2122
import java.util.List;
@@ -59,36 +60,100 @@ public class ComposeContainer implements Startable {
5960

6061
public static final String COMPOSE_EXECUTABLE = SystemUtils.IS_OS_WINDOWS ? "docker.exe" : "docker";
6162

62-
private static final DockerImageName DEFAULT_IMAGE_NAME = DockerImageName.parse("docker:24.0.2");
63+
private static final DockerImageName DEFAULT_IMAGE_NAME = DockerImageName.parse("docker");
6364

6465
private final ComposeDelegate composeDelegate;
6566

6667
private String project;
6768

6869
private List<String> filesInDirectory = new ArrayList<>();
6970

71+
/**
72+
* Creates a new ComposeContainer using the specified Docker image and compose files.
73+
*
74+
* @param image The Docker image to use for the container
75+
* @param composeFiles One or more Docker Compose configuration files
76+
*/
77+
public ComposeContainer(DockerImageName image, File... composeFiles) {
78+
this(image, Arrays.asList(composeFiles));
79+
}
80+
81+
/**
82+
* Creates a new ComposeContainer using the specified Docker image and compose files.
83+
*
84+
* @param image The Docker image to use for the container
85+
* @param composeFiles A list of Docker Compose configuration files
86+
*/
87+
public ComposeContainer(DockerImageName image, List<File> composeFiles) {
88+
this(image, Base58.randomString(6).toLowerCase(), composeFiles);
89+
}
90+
91+
/**
92+
* Creates a new ComposeContainer with the specified Docker image, identifier, and compose files.
93+
*
94+
* @param image The Docker image to use for the container
95+
* @param identifier A unique identifier for this compose environment
96+
* @param composeFiles One or more Docker Compose configuration files
97+
*/
98+
public ComposeContainer(DockerImageName image, String identifier, File... composeFiles) {
99+
this(image, identifier, Arrays.asList(composeFiles));
100+
}
101+
102+
/**
103+
* Creates a new ComposeContainer with the specified Docker image, identifier, and a single compose file.
104+
*
105+
* @param image The Docker image to use for the container
106+
* @param identifier A unique identifier for this compose environment
107+
* @param composeFile A Docker Compose configuration file
108+
*/
109+
public ComposeContainer(DockerImageName image, String identifier, File composeFile) {
110+
this(image, identifier, Collections.singletonList(composeFile));
111+
}
112+
113+
/**
114+
* Creates a new ComposeContainer with the specified Docker image, identifier, and compose files.
115+
*
116+
* @param image The Docker image to use for the container
117+
* @param identifier A unique identifier for this compose environment
118+
* @param composeFiles A list of Docker Compose configuration files
119+
*/
120+
public ComposeContainer(DockerImageName image, String identifier, List<File> composeFiles) {
121+
image.assertCompatibleWith(DEFAULT_IMAGE_NAME);
122+
this.composeDelegate =
123+
new ComposeDelegate(ComposeDelegate.ComposeVersion.V2, composeFiles, identifier, COMPOSE_EXECUTABLE, image);
124+
this.project = this.composeDelegate.getProject();
125+
}
126+
127+
/**
128+
* Use the new constructor {@link #ComposeContainer(DockerImageName image, File... composeFiles)}
129+
*/
70130
public ComposeContainer(File... composeFiles) {
71-
this(Arrays.asList(composeFiles));
131+
this(DEFAULT_IMAGE_NAME, Arrays.asList(composeFiles));
132+
this.localCompose = true;
72133
}
73134

135+
/**
136+
* Use the new constructor {@link #ComposeContainer(DockerImageName image, List composeFiles)}
137+
*/
74138
public ComposeContainer(List<File> composeFiles) {
75-
this(Base58.randomString(6).toLowerCase(), composeFiles);
139+
this(DEFAULT_IMAGE_NAME, composeFiles);
140+
this.localCompose = true;
76141
}
77142

143+
/**
144+
* Use the new constructor {@link #ComposeContainer(DockerImageName image, String identifier, File... composeFile)}
145+
*/
78146
public ComposeContainer(String identifier, File... composeFiles) {
79-
this(identifier, Arrays.asList(composeFiles));
147+
this(DEFAULT_IMAGE_NAME, identifier, Arrays.asList(composeFiles));
148+
this.localCompose = true;
80149
}
81150

151+
/**
152+
* Use the new constructor {@link #ComposeContainer(DockerImageName image, String identifier, List composeFiles)}
153+
*/
82154
public ComposeContainer(String identifier, List<File> composeFiles) {
83-
this.composeDelegate =
84-
new ComposeDelegate(
85-
ComposeDelegate.ComposeVersion.V2,
86-
composeFiles,
87-
identifier,
88-
COMPOSE_EXECUTABLE,
89-
DEFAULT_IMAGE_NAME
90-
);
91-
this.project = this.composeDelegate.getProject();
155+
this(DEFAULT_IMAGE_NAME, identifier, composeFiles);
156+
this.localCompose = true;
92157
}
93158

94159
@Override
@@ -234,16 +299,6 @@ public ComposeContainer withEnv(Map<String, String> env) {
234299
return this;
235300
}
236301

237-
/**
238-
* Use a local Docker Compose binary instead of a container.
239-
*
240-
* @return this instance, for chaining
241-
*/
242-
public ComposeContainer withLocalCompose(boolean localCompose) {
243-
this.localCompose = localCompose;
244-
return this;
245-
}
246-
247302
/**
248303
* Whether to pull images first.
249304
*

core/src/main/java/org/testcontainers/containers/DockerComposeContainer.java

Lines changed: 78 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import java.time.Duration;
1717
import java.util.ArrayList;
1818
import java.util.Arrays;
19+
import java.util.Collections;
1920
import java.util.HashMap;
2021
import java.util.HashSet;
2122
import java.util.List;
@@ -58,41 +59,114 @@ public class DockerComposeContainer<SELF extends DockerComposeContainer<SELF>> i
5859

5960
public static final String COMPOSE_EXECUTABLE = SystemUtils.IS_OS_WINDOWS ? "docker-compose.exe" : "docker-compose";
6061

61-
private static final DockerImageName DEFAULT_IMAGE_NAME = DockerImageName.parse("docker/compose:1.29.2");
62-
6362
private final ComposeDelegate composeDelegate;
6463

6564
private String project;
6665

6766
private List<String> filesInDirectory = new ArrayList<>();
6867

69-
@Deprecated
68+
/**
69+
* Creates a new DockerComposeContainer using the specified Docker image and compose files.
70+
*
71+
* @param image The Docker image to use for the container
72+
* @param composeFiles One or more Docker Compose configuration files
73+
*/
74+
public DockerComposeContainer(DockerImageName image, File... composeFiles) {
75+
this(image, Arrays.asList(composeFiles));
76+
}
77+
78+
/**
79+
* Creates a new DockerComposeContainer using the specified Docker image and compose files.
80+
*
81+
* @param image The Docker image to use for the container
82+
* @param composeFiles A list of Docker Compose configuration files
83+
*/
84+
public DockerComposeContainer(DockerImageName image, List<File> composeFiles) {
85+
this(image, Base58.randomString(6).toLowerCase(), composeFiles);
86+
}
87+
88+
/**
89+
* Creates a new DockerComposeContainer with the specified Docker image, identifier, and compose files.
90+
*
91+
* @param image The Docker image to use for the container
92+
* @param identifier A unique identifier for this compose environment
93+
* @param composeFiles One or more Docker Compose configuration files
94+
*/
95+
public DockerComposeContainer(DockerImageName image, String identifier, File... composeFiles) {
96+
this(image, identifier, Arrays.asList(composeFiles));
97+
}
98+
99+
/**
100+
* Creates a new DockerComposeContainer with the specified Docker image, identifier, and a single compose file.
101+
*
102+
* @param image The Docker image to use for the container
103+
* @param identifier A unique identifier for this compose environment
104+
* @param composeFile A Docker Compose configuration file
105+
*/
106+
public DockerComposeContainer(DockerImageName image, String identifier, File composeFile) {
107+
this(image, identifier, Collections.singletonList(composeFile));
108+
}
109+
110+
/**
111+
* Creates a new DockerComposeContainer with the specified Docker image, identifier, and compose files.
112+
*
113+
* @param image The Docker image to use for the container
114+
* @param identifier A unique identifier for this compose environment
115+
* @param composeFiles A list of Docker Compose configuration files
116+
*/
117+
public DockerComposeContainer(DockerImageName image, String identifier, List<File> composeFiles) {
118+
this.composeDelegate =
119+
new ComposeDelegate(ComposeDelegate.ComposeVersion.V1, composeFiles, identifier, COMPOSE_EXECUTABLE, image);
120+
this.project = this.composeDelegate.getProject();
121+
}
122+
123+
/**
124+
* Use the new constructor {@link #DockerComposeContainer(DockerImageName image, String identifier, File composeFile)}
125+
*/
70126
public DockerComposeContainer(File composeFile, String identifier) {
71127
this(identifier, composeFile);
128+
this.localCompose = true;
72129
}
73130

131+
/**
132+
* Use the new constructor {@link #DockerComposeContainer(DockerImageName image, List composeFiles)}
133+
*/
74134
public DockerComposeContainer(File... composeFiles) {
75135
this(Arrays.asList(composeFiles));
136+
this.localCompose = true;
76137
}
77138

139+
/**
140+
* Use the new constructor {@link #DockerComposeContainer(DockerImageName image, List composeFiles)}
141+
*/
142+
@Deprecated
78143
public DockerComposeContainer(List<File> composeFiles) {
79144
this(Base58.randomString(6).toLowerCase(), composeFiles);
145+
this.localCompose = true;
80146
}
81147

148+
/**
149+
* Use the new constructor {@link #DockerComposeContainer(DockerImageName image, String identifier, File... composeFiles)}
150+
*/
82151
public DockerComposeContainer(String identifier, File... composeFiles) {
83152
this(identifier, Arrays.asList(composeFiles));
153+
this.localCompose = true;
84154
}
85155

156+
/**
157+
* Use the new constructor {@link #DockerComposeContainer(DockerImageName image, String identifier, List composeFiles)}
158+
*/
86159
public DockerComposeContainer(String identifier, List<File> composeFiles) {
87160
this.composeDelegate =
88161
new ComposeDelegate(
89162
ComposeDelegate.ComposeVersion.V1,
90163
composeFiles,
91164
identifier,
92165
COMPOSE_EXECUTABLE,
93-
DEFAULT_IMAGE_NAME
166+
DockerImageName.parse("docker/compose:1.29.2")
94167
);
95168
this.project = this.composeDelegate.getProject();
169+
this.localCompose = true;
96170
}
97171

98172
@Override
@@ -234,16 +308,6 @@ public SELF withEnv(Map<String, String> env) {
234308
return self();
235309
}
236310

237-
/**
238-
* Use a local Docker Compose binary instead of a container.
239-
*
240-
* @return this instance, for chaining
241-
*/
242-
public SELF withLocalCompose(boolean localCompose) {
243-
this.localCompose = localCompose;
244-
return self();
245-
}
246-
247311
/**
248312
* Whether to pull images first.
249313
*
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package org.testcontainers.containers;
2+
3+
import org.junit.jupiter.api.Test;
4+
import org.testcontainers.utility.DockerImageName;
5+
6+
import java.io.File;
7+
import java.util.Optional;
8+
9+
import static org.assertj.core.api.Assertions.assertThat;
10+
11+
class ComposeContainerTest {
12+
13+
public static final String DOCKER_IMAGE = "docker:25.0.2";
14+
15+
private static final String COMPOSE_FILE_PATH = "src/test/resources/v2-compose-test.yml";
16+
17+
@Test
18+
void testWithCustomDockerImage() {
19+
ComposeContainer composeContainer = new ComposeContainer(
20+
DockerImageName.parse(DOCKER_IMAGE),
21+
new File(COMPOSE_FILE_PATH)
22+
);
23+
composeContainer.start();
24+
verifyContainerCreation(composeContainer);
25+
composeContainer.stop();
26+
}
27+
28+
@Test
29+
void testWithCustomDockerImageAndIdentifier() {
30+
ComposeContainer composeContainer = new ComposeContainer(
31+
DockerImageName.parse(DOCKER_IMAGE),
32+
"myidentifier",
33+
new File(COMPOSE_FILE_PATH)
34+
);
35+
composeContainer.start();
36+
verifyContainerCreation(composeContainer);
37+
composeContainer.stop();
38+
}
39+
40+
private void verifyContainerCreation(ComposeContainer composeContainer) {
41+
Optional<ContainerState> redis = composeContainer.getContainerByServiceName("redis");
42+
assertThat(redis)
43+
.hasValueSatisfying(container -> {
44+
assertThat(container.isRunning()).isTrue();
45+
assertThat(container.getContainerInfo().getConfig().getLabels())
46+
.containsEntry("com.docker.compose.version", "2.24.5");
47+
});
48+
}
49+
}

0 commit comments

Comments
 (0)