Comments (6)
I have it like
`
class PostgresReadyChecker(container: DockerContainer) extends DockerReadyChecker {
val PostgresUser = "POSTGRES_USER="
val PostgresPassword = "POSTGRES_PASSWORD="
val PostgresDB = "POSTGRES_DB="
val maybePort = container.bindPorts.headOption.map(.1)
val maybeUser = container.env.find(.startsWith(PostgresUser)).map(.substring(PostgresUser.length))
val maybePassword = container.env.find(.startsWith(PostgresPassword)).map(.substring(PostgresPassword.length))
val maybeDB = container.env.find(.startsWith(PostgresDB)).map(.substring(PostgresDB.length))
override def apply(container: DockerContainerState)(implicit docker: DockerCommandExecutor, ec: ExecutionContext) =
container.getPorts().map(ports =>
Try {
Class.forName("org.postgresql.Driver")
val ip = DockerHelper.ip
val url = s"jdbc:postgresql://$ip:${maybePort.getOrElse(ports.values.head)}/"
Logger.info(s"Trying to obtain connection to $url with user $maybeUser, password = $maybePassword, and db = $maybeDB")
val maybeConnection =
for {
user <- maybeUser
password <- maybePassword
db <- maybeDB
} yield DriverManager.getConnection(url + db, user, password)
maybeConnection.map(_.close).isDefined
}.recover{
case e =>
Logger.info(e.getMessage)
false
}.getOrElse(false)
)
}
`
from docker-it-scala.
I can make a pull request if this functionality is needed.
from docker-it-scala.
Please have a look at sample code https://github.com/whisklabs/docker-it-scala/blob/master/samples/src/main/scala/com/whisk/docker/DockerPostgresService.scala
from docker-it-scala.
@viktortnk Thanks for your example, but is it included to the library? Can I reuse it without copying?
from docker-it-scala.
@aakavalevich No, it is not included. Specific implementations are not shipped with library. I'd recommend to just copy it
from docker-it-scala.
Ok. I just thought, that Ready checker is similar to everyone and it would be nice to share it.
from docker-it-scala.
Related Issues (20)
- Concurrency issues on logs
- No support for UDP?
- Timeout or Race condition resulting in Cannot run all required containers HOT 1
- Shutdown connection before running tests HOT 1
- Pulling image timeout gives an error message about not being able to pull windows image
- Publish v0.9.7 for 2.11 ? HOT 1
- Plans to publish a jar with shaded spotify docker-client? HOT 8
- Setup steps unclear HOT 2
- PostgresServiceSpec fails with driver libraries from 42 HOT 1
- Allow pausing/unpausing of containers in DockerExecutor
- Release for Scala 2.13 HOT 5
- run unpublished docker image with whisk labs docker-it-scala HOT 1
- Incompatible with ScalaTest's AsyncTestSuite
- Issues with SBT 1.3.x
- An image without a tag pulls all tags
- Persisting container across multiple test classes
- withUnlinkedDependencies not starting dependent container
- DockerContainer should have an option to configure withIpv6Address and withExtraHosts
- Missing release for docker-testkit-impl-docker-java 0.11.0 HOT 5
- Update in the GitHub Actions image's docker breaks docker-it-scala HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from docker-it-scala.