Skip to content

Commit

Permalink
Merge pull request #4 from adRise/huajiang/chore/add-setting-key-for-…
Browse files Browse the repository at this point in the history
…postgres-image-name

add a setting key for postgres image name
  • Loading branch information
huajiang-tubi authored Nov 28, 2024
2 parents afdb32f + 15bfa46 commit 175f4be
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
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

0 comments on commit 175f4be

Please sign in to comment.