Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a setting key for postgres image name #4

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ trait PluginDBSupport {
protected val startDb = taskKey[Unit]("Stop and remove the postgres container")

lazy val postgresContainerPort = settingKey[Int]("The port of postgres port")
lazy val postgresImage = settingKey[String]("The postgres image name")
lazy val postgresVersion = settingKey[String]("The postgres version")

protected def dbSettings: Seq[sbt.Setting[_]] = {
Expand All @@ -24,6 +25,7 @@ trait PluginDBSupport {
flywayDefaults / Keys.logLevel := Level.Warn,
postgresDbUrl := s"jdbc:postgresql://127.0.0.1:${postgresContainerPort.value}/postgres",
postgresContainerPort := 15432,
postgresImage := "postgres",
postgresVersion := "13.7",
flywayUrl := postgresDbUrl.value,
flywayUser := dbUser,
Expand All @@ -35,6 +37,7 @@ trait PluginDBSupport {
PostgresContainer.start(
exportPort = postgresContainerPort.value,
password = dbPass,
postgresImage = postgresImage.value,
postgresVersion = postgresVersion.value,
logger = Keys.streams.value.log
)
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/com/tubitv/PostgresContainer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ object PostgresContainer {

private val runningDb = new AtomicReference[Option[String]](None)

def start(exportPort: Int, password: String, postgresVersion: String, logger: Logger): Unit = {
def start(exportPort: Int, password: String, postgresImage: String, postgresVersion: String, logger: Logger): Unit = {
runningDb.get() match {
case None =>
val image = s"postgres:$postgresVersion"
val image = s"$postgresImage:$postgresVersion"
val dockerClient = DockerClientBuilder.getInstance.build
Try(dockerClient.inspectImageCmd(image).exec()).recover {
case _: NotFoundException =>
Expand Down
Loading