Skip to content

Commit

Permalink
Migrated docker.. to camundala.
Browse files Browse the repository at this point in the history
  • Loading branch information
pme123 committed Dec 12, 2024
1 parent d541363 commit 76185cf
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 11 deletions.
42 changes: 42 additions & 0 deletions 00-documentation/src/docs/development/projectDev.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ The `version` is optional and defaults to `1`.
Whenever you have changes in the `company-camundala` project or in one of your dependencies,
you can update the project with the following command:

Usage / example:
```bash
./helper.scala update
```
Expand All @@ -29,6 +30,11 @@ You will get a warning, but the file will not be replaced.

Creates a new Release for the BPMN project and publishes to the repository(e.g. Artifactory)

@:callout(info)
Adjust the `CompanyDevHelper.publishConfig` configuration.

@:@

Usage:
```
./helper.scala publish <VERSION>
Expand Down Expand Up @@ -252,3 +258,39 @@ This creates the following files:
02-bpmn - main -> mycompany.myproject.bpmn.myProcess.v1.MyTimerEvent
```

## Docker
To run the Camunda Server locally, you can use `docker-compose`.

@:callout(info)
**Precondition**:
- You have to have `docker` and `docker-compose` installed.
- You need to have a `docker-compose.yml` in `dev-company/docker` directory.
- Adjust the `CompanyDevHelper.dockerConfig` configuration.

@:@

### dockerUp
Starts the server with `docker-compose`.

Usage / example:
```
./helper.scala dockerUp
```

### dockerStop
Stops the server with `docker-compose`.

Usage / example:
```
./helper.scala dockerStop
```

### dockerDown
Stops and removes the server with `docker-compose`.

**Be aware** that all data will be lost - you have to deploy again.

Usage / example:
```
./helper.scala dockerDown
```
19 changes: 9 additions & 10 deletions 04-helper/src/main/scala/camundala/helper/dev/DevHelper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package camundala.helper.dev

import camundala.api.ApiConfig
import camundala.helper.dev.deploy.DeployHelper
import camundala.helper.dev.docker.DockerHelper
import camundala.helper.dev.publish.PublishHelper
import camundala.helper.util.{DeployConfig, DevConfig, PublishConfig}
import camundala.helper.util.*
import camundala.helper.dev.update.*

import scala.util.{Failure, Success, Try}
Expand All @@ -13,6 +14,7 @@ trait DevHelper:
def devConfig: DevConfig
def publishConfig: Option[PublishConfig]
def deployConfig: Option[DeployConfig]
def dockerConfig: DockerConfig
given DevConfig = devConfig
given ApiConfig = apiConfig
given Option[PublishConfig] = publishConfig
Expand Down Expand Up @@ -119,18 +121,15 @@ trait DevHelper:
case other =>
println(s"Invalid arguments for command $command: $other")
println(s"Usage: $command <simulation>")
println(s"Example: $command OpenAccountSimulation") /*
println(s"Example: $command OpenAccountSimulation")
// docker
case Command.dockerUp =>
args match
case Seq(imageVersion) =>
DockerHelper().dockerUp(Some(imageVersion))
case _ =>
DockerHelper().dockerUp(None)
DockerHelper(dockerConfig).dockerUp()
case Command.dockerStop =>
DockerHelper().dockerStop()
DockerHelper(dockerConfig).dockerStop()
case Command.dockerDown =>
DockerHelper().dockerDown()
*/
DockerHelper(dockerConfig).dockerDown()

private def printBadActivity(command: Command, args: Seq[String]): Unit =
println(s"Invalid arguments for command $command: $args")
println(s"Usage: $command <processName> <bpmnName> [version: Int]")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ case class CompanyWrapperGenerator()(using config: DevConfig):
|
| lazy val publishConfig: Option[PublishConfig] = None //TODO If you have a webdav server to publish the docs, add the config here
| lazy val deployConfig: Option[DeployConfig] = None //TODO If you have a Postman account, add the config here
| lazy val dockerConfig: DockerConfig = DockerConfig() //TODO Adjust the DockerConfig if needed
|""".stripMargin
end helperWrapper

Expand Down
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 04-helper/src/main/scala/camundala/helper/util/DockerConfig.scala
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")
)
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ trait Helpers:
println(s"Working Directory: $wd")
wd
end workDir
protected val dockerDir: os.Path = workDir / os.up / os.up / "docker"

protected def check(label: String, port: Int): Unit =
var checking = true
Expand Down

0 comments on commit 76185cf

Please sign in to comment.