Hi all! I'm new using this plugin and I'm having some issues. I 'm trying to use it to configure a mountebank container, which will allow me to test tcp connections. I'm stuck because I have managed to start the container without any problem, but to configure it with I have to pass a configuration file with the option "--configfile path". I have mounted the configuration file using volumes, but then, when I use the withCommand it looks like since there is a space betwen the option and the file is says it does not recognize that comand. As a workaround I tried to use withEntrypath and then copying the full command with options " mb start --configfile path" but then it says that the reference file it doesnt exists, I'm guessing it is because at that time the volume has not been mounted yet.
Here is my service configuration
trait DockerMountebankService extends DockerKit {
val DefaultMountbankPort = 2525
val ImposterPort=3000
val ImpostersPath = getClass.getResource("/imposters_config/").getPath
val volumes = Seq(
VolumeMapping(container = "/imposters", host = ImpostersPath , rw = true)
)
// val DefaultTcpPort
val mountebankContainer = DockerContainer("expert360/mountebank")
.withVolumes(volumes)
.withPorts(DefaultMountbankPort -> Some(2525))
.withPorts(ImposterPort -> None)
.withReadyChecker(DockerReadyChecker.LogLineContains("mountebank v1.3.0 (node v0.12.2) now taking orders"))
.withEntrypoint("mb start--configfile /imposters/imposters.ejs") // it fails saying "no such file or directory"
// .withCommand("--configfile /imposters/imposters.ejs") it fails saying "--configfile /imposters/imposters.ejs" is not recognized as a command
abstract override def dockerContainers = mountebankContainer :: super.dockerContainers
}
Any help would be appreciated
isContainerReady
:Nov 03, 2017 9:53:02 AM org.postgresql.Driver connect
SEVERE: Connection error:
org.postgresql.util.PSQLException: The connection attempt failed.
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:275)
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49)
at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:194)
at org.postgresql.Driver.makeConnection(Driver.java:450)
at org.postgresql.Driver.connect(Driver.java:252)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at com.alexitc.coinalerts.controllers.PostgresReadyChecker.$anonfun$apply$2(UsersControllerSpec.scala:270)
at scala.runtime.java8.JFunction0$mcZ$sp.apply(JFunction0$mcZ$sp.java:12)
at scala.util.Try$.apply(Try.scala:209)
at com.alexitc.coinalerts.controllers.PostgresReadyChecker.$anonfun$apply$1(UsersControllerSpec.scala:267)
at com.alexitc.coinalerts.controllers.PostgresReadyChecker.$anonfun$apply$1$adapted(UsersControllerSpec.scala:266)
at scala.util.Success.$anonfun$map$1(Try.scala:251)
at scala.util.Success.map(Try.scala:209)
at scala.concurrent.Future.$anonfun$map$1(Future.scala:287)
at scala.concurrent.impl.Promise.liftedTree1$1(Promise.scala:29)
at scala.concurrent.impl.Promise.$anonfun$transform$1(Promise.scala:29)
at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:60)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.io.EOFException
at org.postgresql.core.PGStream.receiveChar(PGStream.java:290)
at org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:418)
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:222)
... 20 more
image: seegno/bitcoind:latest
command:
-printtoconsole
-regtest=1
-rest
-rpcuser=foo
-rpcpassword=bar
-rpcallowip=0.0.0.0/0
-rpcport=8332
-server=1
-logips
-debug=rpc
ports:
- 8332:8332
``` val BitcoinDaemonPort = 8332
val bitcoinContainer: DockerContainer = DockerContainer("seegno/bitcoind:latest")
.withPorts(BitcoinDaemonPort -> Some(BitcoinDaemonPort))
.withCommand(
"printtoconsole",
"regtest=1",
"rest",
"rpcuser=foo",
"rpcpassword=bar",
"rpcallowip=0.0.0.0/0",
"rpcport=8332",
"server=1",
"logips",
"debug=rpc"
)
.withReadyChecker(DockerReadyChecker.LogLineContains("msghand thread start")) ```
DockerKit
is a trait
I don't find a companion object! Because I'm also interested to get the hostport chosen randomly.val container: DockerContainer = ???
val ports: Future[Map[Int, Int]] = container.getPorts()
DockerPostgresService
from the examples and am doing the following to see if the containers spins up as expected. Just times out. I've tried the LogLineReceiver
and it doesn't show anything either. Am I missing something?
class BaseIntegrationTest extends FunSpec with Matchers with DockerPostgresService {
override implicit val dockerFactory: DockerFactory = new SpotifyDockerFactory(
DefaultDockerClient.fromEnv().build()
)
describe("Test") {
it("a") {
val a = Await.result(isContainerReady(postgresContainer), Duration(60, TimeUnit.SECONDS))
assert(a)
}
}
}
I encountered a similar problem while connecting to container using modified example DockerPostgresService
. I receive connection error, but after that everything is set up and all tests pass. Here's the snippet from logs:
PG [f387ecb6533263922aa7619d8c719a044df627a360ba18bfb0cfbac815f67a5f] ok
running bootstrap script ...
Jul 05, 2019 11:16:00 AM org.postgresql.Driver connect
SEVERE: Connection error:
org.postgresql.util.PSQLException: The connection attempt failed.
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:275)
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49)
at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:194)
at org.postgresql.Driver.makeConnection(Driver.java:450)
at org.postgresql.Driver.connect(Driver.java:252)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at docker.services.PostgresReadyChecker.$anonfun$apply$2(DockerPostgresService.scala:52)
at scala.runtime.java8.JFunction0$mcZ$sp.apply(JFunction0$mcZ$sp.scala:17)
at scala.util.Try$.apply(Try.scala:212)
at docker.services.PostgresReadyChecker.$anonfun$apply$1(DockerPostgresService.scala:48)
at docker.services.PostgresReadyChecker.$anonfun$apply$1$adapted(DockerPostgresService.scala:47)
at scala.concurrent.impl.Promise$Transformation.run(Promise.scala:430)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.io.EOFException
at org.postgresql.core.PGStream.receiveChar(PGStream.java:290)
at org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:418)
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:222)
... 15 more
PG [f387ecb6533263922aa7619d8c719a044df627a360ba18bfb0cfbac815f67a5f] ok
And my DockerPostgresService
implementation:
package docker.services
import java.sql.DriverManager
import com.whisk.docker._
import com.whisk.docker.impl.spotify.DockerKitSpotify
import com.typesafe.config.{Config, ConfigFactory}
import scala.concurrent.{ExecutionContext, Future}
import scala.util.Try
trait DockerPostgresService extends DockerKitSpotify {
import scala.concurrent.duration._
lazy val config: Config = ConfigFactory.load()
lazy val dockerConfig: Config = config.getConfig("docker.postgres")
val ImageName: String = dockerConfig.getString("image-name")
val PostgresAdvertisedPort: Int = dockerConfig.getInt("port-maps.default-postgres-port.internal")
val PostgresExposedPort: Int = dockerConfig.getInt("port-maps.default-postgres-port.external")
val PostgresUser = "postgres"
val PostgresPassword = "postgres"
val postgresContainer: DockerContainer = DockerContainer(ImageName)
.withPorts((PostgresAdvertisedPort, Some(PostgresExposedPort)))
.withEnv(s"POSTGRES_USER=$PostgresUser", s"POSTGRES_PASSWORD=$PostgresPassword")
.withReadyChecker(
new PostgresReadyChecker(PostgresUser, PostgresPassword, Some(PostgresExposedPort))
.looped(15, 1.second)
)
.withLogLineReceiver(LogLineReceiver(withErr = true, s => println(s"PG $s")))
override def dockerContainers: List[DockerContainer] =
postgresContainer :: super.dockerContainers
}
class PostgresReadyChecker(user: String, password: String, port: Option[Int] = None)
extends DockerReadyChecker {
override def apply(container: DockerContainerState)(
implicit docker: DockerCommandExecutor,
ec: ExecutionContext): Future[Boolean] =
container
.getPorts()
.map(ports =>
Try {
Class.forName("org.postgresql.Driver")
val url = s"jdbc:postgresql://${docker.host}:${port.getOrElse(ports.values.head)}/postgres"
Option(
DriverManager.getConnection(url, user, password)
).map(_.close).isDefined
}.getOrElse(false))
}
@here I am trying to using docker-it-scala with elastic search.
My build.sbt dependencies looks like below
"com.whisk" %% "docker-testkit-scalatest" % "0.9.8" % Test,
"com.whisk" %% "docker-testkit-impl-spotify" % "0.9.8" % Test,
"com.github.docker-java" % "docker-java" % "3.0.13" % Test
And My ElasticSearchTestSpec Looks like below
import org.log4s.getLogger
import com.whisk.docker.impl.spotify.DockerKitSpotify
import com.whisk.docker.scalatest.DockerTestKit
import com.whisk.docker.{DockerContainer, DockerKit, DockerPortMapping, DockerReadyChecker}
import org.scalatest.{BeforeAndAfterAll, TestSuite}
import org.scalatest.concurrent.ScalaFutures
import org.scalatest.time.{Second, Seconds, Span}
import scala.concurrent.duration._
trait DockerElasticsearchService extends DockerKit {
val DefaultElasticsearchHttpPort = 9200
val DefaultElasticsearchClientPort = 9300
val elasticsearchContainer: DockerContainer = DockerContainer("docker.elastic.co/elasticsearch/elasticsearch:6.0.1")
.withPortMapping(
DefaultElasticsearchHttpPort -> DockerPortMapping(Some(DefaultElasticsearchHttpPort)),
DefaultElasticsearchClientPort -> DockerPortMapping(Some(DefaultElasticsearchClientPort)))
.withEnv("discovery.type=single-node")
.withReadyChecker(
DockerReadyChecker
.HttpResponseCode(DefaultElasticsearchHttpPort, "/", Some("0.0.0.0"))
.within(100.millis)
.looped(20, 1250.millis))
abstract override def dockerContainers: List[DockerContainer] =
elasticsearchContainer :: super.dockerContainers
}
trait ElasticSearchTestSpec extends TestSuite with BeforeAndAfterAll with DockerElasticsearchService with ScalaFutures with DockerTestKit with DockerKitDockerJava {
val log = getLogger
implicit val pc = PatienceConfig(Span(20, Seconds), Span(1, Second))
override def beforeAll(): Unit = {
super.beforeAll()
val ready = isContainerReady(elasticsearchContainer).futureValue
ready match {
case true => log.info("Elastic Search Container is ready")
case false => log.info("Elastic Search Container is not ready")
}
}
lazy val es_url = s"0.0.0.0/${DefaultElasticsearchHttpPort}"
}
I am not able to resolve DockerKitDockerJava
Should I add any pther library to build.abt? without that, I am getting error java.util.concurrent.TimeoutException: Futures timed out after [10 seconds]
java.util.concurrent.TimeoutException: Future timed out after [1 minute]
at scala.concurrent.impl.Promise$DefaultPromise.tryAwait0(Promise.scala:212)
at scala.concurrent.impl.Promise$DefaultPromise.ready(Promise.scala:219)
at scala.concurrent.impl.Promise$DefaultPromise.ready(Promise.scala:104)
at scala.concurrent.Await$.$anonfun$ready$1(package.scala:174)
at scala.concurrent.BlockContext$DefaultBlockContext$.blockOn(BlockContext.scala:62)
at scala.concurrent.Await$.ready(package.scala:124)
at com.whisk.docker.DockerKit.stopAllQuietly(DockerKit.scala:65)
at com.whisk.docker.DockerKit.stopAllQuietly$(DockerKit.scala:63)
An exception or error caused a run to abort: java.util.concurrent.ExecutionException: javax.ws.rs.ProcessingException: java.lang.NoClassDefFoundError: jersey/repackaged/com/google/common/util/concurrent/MoreExecutors