Skip to content

Commit 3dfa6ff

Browse files
committed
wip
1 parent 97f6f27 commit 3dfa6ff

File tree

3 files changed

+85
-17
lines changed

3 files changed

+85
-17
lines changed

build.sbt

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,6 @@ lazy val baseSettings = Seq(
5151
Test / publishArtifact := false,
5252
Test / fork := true,
5353
Test / parallelExecution := false
54-
// testForkedParallel := true,
55-
// concurrentRestrictions := {
56-
// val par = parallelExecution.value
57-
// val max = EvaluateTask.SystemProcessors
58-
// List(
59-
// Tags.limitAll(if (par) max else 1),
60-
// Tags.limit(Tags.ForkedTestGroup, 2),
61-
// Tags.exclusiveGroup(Tags.Clean)
62-
// )
63-
// }
6454
)
6555

6656
val `docker-controller-scala-core` = (project in file("docker-controller-scala-core"))
@@ -167,9 +157,9 @@ val `docker-controller-scala-postgresql` = (project in file("docker-controller-s
167157
.settings(
168158
name := "docker-controller-scala-postgresql",
169159
libraryDependencies ++= Seq(
170-
scalatest.scalatest % Test,
171-
logback.classic % Test,
172-
"org.postgresql" % "postgresql" % "42.2.22" % Test
160+
scalatest.scalatest % Test,
161+
logback.classic % Test,
162+
postgresql.postgresql % Test
173163
)
174164
).dependsOn(`docker-controller-scala-core`, `docker-controller-scala-scalatest` % Test)
175165

@@ -184,6 +174,16 @@ val `docker-controller-scala-redis` = (project in file("docker-controller-scala-
184174
)
185175
).dependsOn(`docker-controller-scala-core`, `docker-controller-scala-scalatest` % Test)
186176

177+
val `docker-controller-scala-flyway` = (project in file("docker-controller-scala-flyway"))
178+
.settings(baseSettings)
179+
.settings(
180+
name := "docker-controller-scala-flyway",
181+
libraryDependencies ++= Seq(
182+
scalatest.scalatest % Test,
183+
logback.classic % Test
184+
)
185+
).dependsOn(`docker-controller-scala-core`, `docker-controller-scala-scalatest` % Test)
186+
187187
val `docker-controller-scala-elasticmq` = (project in file("docker-controller-scala-elasticmq"))
188188
.settings(baseSettings)
189189
.settings(
@@ -224,14 +224,18 @@ val `docker-controller-scala-root` = (project in file("."))
224224
.aggregate(
225225
`docker-controller-scala-core`,
226226
`docker-controller-scala-scalatest`,
227+
// for RDBMS
227228
`docker-controller-scala-mysql`,
229+
`docker-controller-scala-postgresql`,
230+
// for NoSQL
231+
`docker-controller-scala-redis`,
232+
`docker-controller-scala-elasticsearch`,
233+
`docker-controller-scala-kafka`,
234+
`docker-controller-scala-zookeeper`,
235+
// AWS
228236
`docker-controller-scala-dynamodb-local`,
229237
`docker-controller-scala-minio`,
230-
`docker-controller-scala-zookeeper`,
231-
`docker-controller-scala-kafka`,
232-
`docker-controller-scala-elasticsearch`,
233238
`docker-controller-scala-localstack`,
234-
`docker-controller-scala-redis`,
235239
`docker-controller-scala-elasticmq`
236240
)
237241

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package com.github.j5ik2o.dockerController.flyway
2+
3+
import com.github.dockerjava.api.DockerClient
4+
import com.github.dockerjava.api.command.CreateContainerCmd
5+
import com.github.dockerjava.api.model.HostConfig.newHostConfig
6+
import com.github.dockerjava.api.model.{ Bind, HostConfig, Mount, Volume }
7+
import com.github.j5ik2o.dockerController.DockerControllerImpl
8+
import com.github.j5ik2o.dockerController.flyway.FlywayController._
9+
import org.apache.commons.io.FileUtils
10+
import org.seasar.util.io.ResourceUtil
11+
12+
import java.io.File
13+
import scala.concurrent.duration.{ DurationInt, FiniteDuration }
14+
import scala.jdk.CollectionConverters._
15+
16+
object FlywayController {
17+
final val DefaultImageName: String = "flyway/flyway"
18+
final val DefaultImageTag: Option[String] = Some("7")
19+
}
20+
21+
class FlywayController(
22+
dockerClient: DockerClient,
23+
outputFrameInterval: FiniteDuration = 500.millis,
24+
imageName: String = DefaultImageName,
25+
imageTag: Option[String] = DefaultImageTag,
26+
envVars: Map[String, String] = Map.empty
27+
)(val dockerWorkingDir: File, val flywayConfResourceName: String)
28+
extends DockerControllerImpl(dockerClient, outputFrameInterval)(imageName, imageTag) {
29+
30+
private val environmentVariables = Map(
31+
"FLYWAY_EDITION" -> "community"
32+
) ++
33+
envVars
34+
35+
override protected def newCreateContainerCmd(): CreateContainerCmd = {
36+
val conf = new Volume("/flyway/conf")
37+
val srcFile = ResourceUtil.getResourceAsFile(flywayConfResourceName)
38+
val destFile = new File(dockerWorkingDir, conf.getPath)
39+
FileUtils.copyFile(srcFile, destFile)
40+
val confPath = destFile.getPath
41+
val confBind = new Bind(confPath, conf)
42+
val drivers = new Volume("/flyway/drivers")
43+
val driversPath = new File(dockerWorkingDir, drivers.getPath).getPath
44+
val driversBind = new Bind(driversPath, drivers)
45+
val sql = new Volume("/flyway/sql")
46+
val sqlPath = new File(dockerWorkingDir, drivers.getPath).getPath
47+
val sqlBind = new Bind(sqlPath, sql)
48+
val jars = new Volume("/flyway/jars")
49+
val jarsPath = new File(dockerWorkingDir, drivers.getPath).getPath
50+
val jarsBind = new Bind(jarsPath, jars)
51+
52+
super
53+
.newCreateContainerCmd()
54+
.withCmd("migrate")
55+
.withEnv(environmentVariables.map { case (k, v) => s"$k=$v" }.toArray: _*)
56+
.withVolumes(conf, drivers, sql, jars)
57+
.withHostConfig(HostConfig.newHostConfig().withBinds(confBind, driversBind, sqlBind, jarsBind))
58+
}
59+
60+
}

project/Dependencies.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ object Dependencies {
5151
val connectorJava = "mysql" % "mysql-connector-java" % "8.0.25"
5252
}
5353

54+
object postgresql {
55+
val postgresql = "org.postgresql" % "postgresql" % "42.2.22"
56+
}
57+
5458
object elasticsearch {
5559
val restHighLevelClient = "org.elasticsearch.client" % "elasticsearch-rest-high-level-client" % "7.13.2"
5660
}

0 commit comments

Comments
 (0)