All Downloads are FREE. Search and download functionalities are using the official Maven repository.

codacy.test.docker.PostgresDocker.scala Maven / Gradle / Ivy

The newest version!
package codacy.test
package docker

import scala.concurrent.duration._
import scala.concurrent.Future

import com.whisk.docker.DockerContainer
import checker._

trait PostgresDocker extends WithHost {

  val defaultPostgresPort = 5432

  val postgresImage: String = "postgres:13.13-bullseye"

  def evolutionsFunction = Future.successful(true)

  private val runEvolutions: () => Future[Boolean] = () => evolutionsFunction

  val postgresPort = 5432

  lazy val postgresPorts =
    Seq(5432 -> Some(postgresPort))

  val postgresContainerName: String = "codacyPostgres"

  val postgresDatabase = "codacy"
  val postgresUser = "codacy"
  val postgresPassword = "codacy"
  val postgresRootPassword = "codacy"

  lazy val postgresContainer = {
    DockerContainer(s"$postgresImage", name = Some(postgresContainerName))
      .withPorts(postgresPorts: _*)
      .withEnv(
        s"POSTGRES_DATABASE=$postgresDatabase",
        s"POSTGRES_USER=$postgresUser",
        s"POSTGRES_PASSWORD=$postgresPassword",
        s"POSTGRES_ROOT_PASSWORD=$postgresRootPassword"
      )
      // Options to make tests faster. Not used in production
      // Source: https://kubuszok.com/2018/speed-up-things-in-scalac-and-sbt
      .withCommand("postgres", "-c", "fsync=off", "-c", "synchronous_commit=off")
      .withReadyChecker(
        PostgresReadyChecker(
          user = postgresUser,
          password = postgresPassword,
          port = Some(postgresPort),
          host = Some(hostIp),
          andThen = runEvolutions
        ).looped(300, 100.millis)
      )
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy