-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
128 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
04-helper/src/main/scala/camundala/helper/dev/docker/DockerHelper.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package camundala.helper.dev.docker | ||
|
||
import camundala.helper.util.{DockerConfig, Helpers} | ||
|
||
case class DockerHelper(dockerConfig: DockerConfig) extends Helpers: | ||
|
||
val dockerDir = dockerConfig.dockerDir | ||
|
||
def dockerUp(): Unit = | ||
dockerConfig.prepareDocker() | ||
|
||
println(s"Docker Images are starting - see the Docker Logs.") | ||
runDocker("up") | ||
dockerConfig.checkPorts.foreach: | ||
case label -> port => | ||
check(label, port) | ||
|
||
println(s"Docker Images started successfully.") | ||
dockerConfig.printResults.foreach: | ||
println | ||
|
||
end dockerUp | ||
|
||
def dockerStop(): Unit = | ||
print("Stop") | ||
println(s"Docker Images are stopping - see the Docker Logs.") | ||
runDocker("stop") | ||
end dockerStop | ||
|
||
def dockerDown(): Unit = | ||
print("Down") | ||
println( | ||
s"Docker Images are stopping and will be removed - see the Docker Logs." | ||
) | ||
runDocker("down") | ||
end dockerDown | ||
|
||
private def print( | ||
command: String | ||
): Unit = | ||
println(s"""$command Docker-Compose: | ||
|- Docker Directory: $dockerDir""".stripMargin) | ||
end print | ||
|
||
private def runDocker(command: String) = | ||
os.proc( | ||
"docker-compose", | ||
dockerConfig.dockerComposePaths | ||
.flatMap: p => | ||
Seq("-f", (dockerDir / p).toString), | ||
"--project-directory", | ||
s"$dockerDir", | ||
"-p", | ||
s"helper-docker", | ||
command, | ||
command match | ||
case "up" => "-d" | ||
case "stop" => Seq("--timeout", "15") // the only valid param | ||
case "down" => | ||
Seq( | ||
"--volumes", | ||
"--remove-orphans" | ||
) // Remove containers for services not defined in the Compose file | ||
).callOnConsole() | ||
end DockerHelper |
11 changes: 11 additions & 0 deletions
11
04-helper/src/main/scala/camundala/helper/util/DockerConfig.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package camundala.helper.util | ||
|
||
case class DockerConfig( | ||
prepareDocker: () => Unit = () => (), | ||
// relative from the project root | ||
dockerDir: os.RelPath = os.rel / os.up / os.up / "docker", | ||
// relative from the dockerDir | ||
dockerComposePaths: Seq[os.RelPath] = Seq(os.rel / "docker-compose.yml"), | ||
checkPorts: Seq[(String, Int)] = Seq("Camunda" -> 8080), | ||
printResults: Seq[String] = Seq("Check Camunda on http://localhost:8080") | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters