-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerCompose.scala
30 lines (23 loc) · 992 Bytes
/
DockerCompose.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package docker
import org.testcontainers.containers.DockerComposeContainer
import zio.{Scope, ZIO, ZLayer}
import java.io.File
import scala.util.Properties
case class DockerCompose(applicationUrl: String)
object DockerCompose:
private val serviceName = "application"
private val servicePort = 8080
val layer: ZLayer[Scope, Throwable, DockerCompose] = ZLayer:
ZIO.fromAutoCloseable {
ZIO.attemptBlocking:
val containers = DockerComposeContainer(File(getClass.getResource("/docker-compose.yml").getFile))
containers.withExposedService(serviceName, servicePort)
val serviceTag = Properties.propOrElse("build", "latest")
containers.withEnv("BUILD_TAG", serviceTag)
containers.start()
containers
}.map { containers =>
val host = containers.getServiceHost(serviceName, servicePort)
val port = containers.getServicePort(serviceName, servicePort)
DockerCompose(applicationUrl = s"http://$host:$port")
}