sbt-integration-env is an SBT plugin for environment management.
You can create and terminate the environment within SBT, or configure automated management during the execution of tests.
To use sbt-integration-env in an existing SBT project (1.3.+), add the following dependency to your plugins.sbt
:
addSbtPlugin("io.github.irevive" % "sbt-integration-env" % "0.4.0")
There are three steps to start using the plugin:
lazy val root = project
.in(file("."))
.enablePlugins(IntegrationEnvPlugin) // 1
.settings(
integrationEnvProvider := IntegrationEnv.DockerCompose.Provider( // 2
composeProjectName = s"${name.value}-it-env",
dockerComposeFile = baseDirectory.value / "docker-compose.yml",
network = None
),
Test / testOptions := integrationEnvTestOpts.value, // 3
Test / fork := true
)
- Enable plugin for a specific project.
- Configure environment provider. You can use
DockerComposeEnvProvider
or implement a custom one. - Optional. Enable automated management during the testing phase. Details
There is a predefined DockerComposeEnvProvider
which uses docker-compose
(or docker compose
for a newer docker version) for manipulations with the environment.
IntegrationEnv.DockerCompose.Provider(
composeProjectName = s"${name.value}-it-env", // 1
dockerComposeFile = baseDirectory.value / "docker-compose.yml", // 2
network = Some(s"${name.value}-it-network") // 3
)
- Name of the docker-compose project. Details
- Path to the docker-compose file.
- External docker network. Details
integrationEnvStart
- create environment.
integrationEnvStop
- terminate environment.
Setting:
Test / testOptions := integrationEnvTestOpts.value
The plugin uses Setup and Cleanup hooks for manipulations. Based on the termination strategy (UponTestCompletion, OnSbtExit, Never) the plugin behaves differently.
The strategy is determined by SBT's insideCI
command: if insideCI
is true the UponTestCompletion
strategy is selected, otherwise the Never
is used.
It can be configured explicitly as well:
integrationEnvTerminationStrategy := TerminationStrategy.UponTestCompletion
Termination strategies:
-
UponTestCompletion
Before tests: terminate if exist, then create new
After tests: terminate -
Never
Before tests: create new if not exist
After tests: do not terminate
External docker network is useful when you are running SBT build in docker container within dind.
At this point, you should use a shared network across all components: SBT container and docker-compose.