Skip to content

Commit ac6d154

Browse files
authored
Merge pull request #181 from jsoizo/with-service
Start specific container service when using docker compose
2 parents b688cf6 + ae9242d commit ac6d154

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

core/src/main/scala/com/dimafeng/testcontainers/DockerComposeContainer.scala

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ final case class ServiceLogConsumer(serviceName: String, consumer: Consumer[Outp
2828

2929
final case class WaitingForService(serviceName: String, waitStrategy: WaitStrategy)
3030

31+
sealed trait Services
32+
object Services {
33+
case object All extends Services
34+
final case class Specific(services: Seq[Service]) extends Services
35+
}
36+
37+
final case class Service(name: String)
38+
3139
object DockerComposeContainer {
3240
val ID_LENGTH = 6
3341

@@ -63,7 +71,8 @@ object DockerComposeContainer {
6371
env: Map[String, String] = Map.empty,
6472
tailChildContainers: Boolean = false,
6573
logConsumers: Seq[ServiceLogConsumer] = Seq.empty,
66-
waitingFor: Option[WaitingForService] = None): DockerComposeContainer =
74+
waitingFor: Option[WaitingForService] = None,
75+
services: Services = Services.All): DockerComposeContainer =
6776
new DockerComposeContainer(composeFiles,
6877
exposedServices,
6978
identifier,
@@ -73,7 +82,8 @@ object DockerComposeContainer {
7382
env,
7483
tailChildContainers,
7584
logConsumers,
76-
waitingFor)
85+
waitingFor,
86+
services)
7787

7888
case class Def(
7989
composeFiles: ComposeFile,
@@ -85,7 +95,8 @@ object DockerComposeContainer {
8595
env: Map[String, String] = Map.empty,
8696
tailChildContainers: Boolean = false,
8797
logConsumers: Seq[ServiceLogConsumer] = Seq.empty,
88-
waitingFor: Option[WaitingForService] = None
98+
waitingFor: Option[WaitingForService] = None,
99+
services: Services = Services.All
89100
) extends ContainerDef {
90101

91102
override type Container = DockerComposeContainer
@@ -101,7 +112,8 @@ object DockerComposeContainer {
101112
env,
102113
tailChildContainers,
103114
logConsumers,
104-
waitingFor
115+
waitingFor,
116+
services
105117
)
106118
}
107119
}
@@ -117,7 +129,8 @@ class DockerComposeContainer(composeFiles: ComposeFile,
117129
env: Map[String, String] = Map.empty,
118130
tailChildContainers: Boolean = false,
119131
logConsumers: Seq[ServiceLogConsumer] = Seq.empty,
120-
waitingFor: Option[WaitingForService] = None)
132+
waitingFor: Option[WaitingForService] = None,
133+
services: Services = Services.All)
121134
extends TestContainerProxy[JavaDockerComposeContainer[_]] {
122135

123136
override val container: JavaDockerComposeContainer[_] = {
@@ -126,6 +139,11 @@ class DockerComposeContainer(composeFiles: ComposeFile,
126139
case ComposeFile(Right(files)) => files.asJava
127140
})
128141

142+
services match {
143+
case Services.Specific(services) => container.withServices(services.map(_.name) : _*)
144+
case Services.All =>
145+
}
146+
129147
exposedServices.foreach { service =>
130148
if (service.instance.isDefined) {
131149
container.withExposedService(service.name, service.instance.get, service.port, service.waitStrategy)

0 commit comments

Comments
 (0)