-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAerospikeContainer.scala
28 lines (22 loc) · 1018 Bytes
/
AerospikeContainer.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
package database
import org.testcontainers.containers.GenericContainer
import org.testcontainers.containers.wait.strategy.LogMessageWaitStrategy
import org.testcontainers.utility.DockerImageName
import zio.{Scope, ZIO, ZLayer}
import scala.jdk.CollectionConverters.*
import scala.collection.mutable.ArrayBuffer
case class AerospikeContainer(host: String, port: Int)
object AerospikeContainer:
private val AeroSpikePort: Int = 3000
val layer: ZLayer[Scope, Throwable, AerospikeContainer] = ZLayer:
ZIO
.fromAutoCloseable:
ZIO.attemptBlocking:
val container = new GenericContainer(DockerImageName.parse("aerospike:ce-7.0.0.0"))
container.setExposedPorts(ArrayBuffer(Integer.valueOf(3000)).asJava)
container.setWaitStrategy(new LogMessageWaitStrategy().withRegEx(".*migrations: complete.*\\s"))
container.start()
container
.map { container =>
AerospikeContainer(container.getHost, container.getMappedPort(AeroSpikePort))
}