Coder Social home page Coder Social logo

Comments (6)

aakavalevich avatar aakavalevich commented on June 26, 2024

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.

aakavalevich avatar aakavalevich commented on June 26, 2024

I can make a pull request if this functionality is needed.

from docker-it-scala.

viktortnk avatar viktortnk commented on June 26, 2024

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.

aakavalevich avatar aakavalevich commented on June 26, 2024

@viktortnk Thanks for your example, but is it included to the library? Can I reuse it without copying?

from docker-it-scala.

viktortnk avatar viktortnk commented on June 26, 2024

@aakavalevich No, it is not included. Specific implementations are not shipped with library. I'd recommend to just copy it

from docker-it-scala.

aakavalevich avatar aakavalevich commented on June 26, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.