Skip to content
This repository has been archived by the owner on Apr 29, 2024. It is now read-only.

Commit

Permalink
Add example docs. Reduce passing variables around.
Browse files Browse the repository at this point in the history
  • Loading branch information
seglo committed Jun 14, 2016
1 parent e64279d commit 811fbc0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,24 @@ launch a running instance that consists of both images:
Note how the docker-compose.yml file for the root project tags each image with "\<localBuild\>". This allows dockerComposeUp
to know that these images should not be updated from the Docker Registry.

5) [**basic-variable-substitution**] (examples/basic-variable-substitution): This project demonstrates how you can re-use your
existing docker-compose.yml with [variable substitution](https://docs.docker.com/compose/compose-file/#variable-substitution)
using sbt-docker-compose. Instead of passing your variables as environment variables you can define them in your build.sbt
programmatically.

build.sbt:

variablesForSubstitution := Map("SOURCE_PORT" -> "5555")

docker-compose.yml:

basic:
image: basic:1.0.0
environment:
JAVA_TOOL_OPTIONS: -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005
ports:
- "${SOURCE_PORT}:5005"

Currently Unsupported Docker Compose Fields
-------------------------------------------
1) "build:" - All docker compose services need to specify an "image:" field.
Expand Down
19 changes: 8 additions & 11 deletions src/main/scala/com/tapad/docker/DockerComposePlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,10 @@ case class ServiceInfo(serviceName: String, imageName: String, imageSource: Stri
* with an SBT project.
* @param composeFilePath The path to the Docker Compose file used by this instance
* @param servicesInfo The collection of ServiceInfo objects that define this instance
* @param variables A collection of key value pairs used for docker-compose variable substitution
* @param instanceData An optional parameter to specify additional information about the instance
*/
case class RunningInstanceInfo(instanceName: String, composeServiceName: String, composeFilePath: String,
servicesInfo: Iterable[ServiceInfo], variables: Vector[(String, String)] = Vector.empty,
instanceData: Option[Any] = None)
servicesInfo: Iterable[ServiceInfo], instanceData: Option[Any] = None)

object DockerComposePlugin extends DockerComposePluginLocal {
override def projectSettings = DockerComposeSettings.baseDockerComposeSettings
Expand Down Expand Up @@ -169,12 +167,12 @@ class DockerComposePluginLocal extends AutoPlugin with ComposeFile with DockerCo

val newState = Try {
dockerComposeUp(instanceName, updatedComposePath)
val newInstance = getRunningInstanceInfo(state, instanceName, updatedComposePath, servicesInfo, variables)
val newInstance = getRunningInstanceInfo(state, instanceName, updatedComposePath, servicesInfo)

printMappedPortInformation(state, newInstance, dockerComposeVersion)
saveInstanceToSbtSession(state, newInstance)
} getOrElse {
stopLocalDockerInstance(state, instanceName, updatedComposePath, variables)
stopLocalDockerInstance(state, instanceName, updatedComposePath)
throw new IllegalStateException(s"Error starting Docker Compose instance. Shutting down containers...")
}

Expand All @@ -184,14 +182,14 @@ class DockerComposePluginLocal extends AutoPlugin with ComposeFile with DockerCo
}

def getRunningInstanceInfo(implicit state: State, instanceName: String, composePath: String,
servicesInfo: Iterable[ServiceInfo], variables: Vector[(String, String)]): RunningInstanceInfo = {
servicesInfo: Iterable[ServiceInfo]): RunningInstanceInfo = {
val composeService = getSetting(composeServiceName).toLowerCase
val composeStartTimeout = getSetting(composeContainerStartTimeoutSeconds)
val dockerMachine = getSetting(dockerMachineName)

val serviceInfo = populateServiceInfoForInstance(instanceName, dockerMachine, servicesInfo, composeStartTimeout)

RunningInstanceInfo(instanceName, composeService, composePath, serviceInfo, variables)
RunningInstanceInfo(instanceName, composeService, composePath, serviceInfo)
}

def pullDockerImages(args: Seq[String], services: Iterable[ServiceInfo]): Unit = {
Expand Down Expand Up @@ -224,7 +222,7 @@ class DockerComposePluginLocal extends AutoPlugin with ComposeFile with DockerCo
//Remove all of the stopped instances from the list
removeList.foreach { instance =>
printBold(s"Stopping and removing local Docker instance: ${instance.instanceName}")
stopLocalDockerInstance(state, instance.instanceName, instance.composeFilePath, instance.variables)
stopLocalDockerInstance(state, instance.instanceName, instance.composeFilePath)
}

if (removeList.isEmpty)
Expand All @@ -245,8 +243,7 @@ class DockerComposePluginLocal extends AutoPlugin with ComposeFile with DockerCo
updatedState
}

def stopLocalDockerInstance(implicit state: State, instanceName: String, composePath: String,
variables: Vector[(String, String)]): Unit = {
def stopLocalDockerInstance(implicit state: State, instanceName: String, composePath: String): Unit = {
dockerComposeStopInstance(instanceName, composePath)

if (getSetting(composeRemoveContainersOnShutdown)) {
Expand All @@ -257,7 +254,7 @@ class DockerComposePluginLocal extends AutoPlugin with ComposeFile with DockerCo
// If the compose file being used is a version that creates a new network on startup then remove that network on
// shutdown
if (new File(composePath).exists()) {
val composeYaml = readComposeFile(composePath, variables)
val composeYaml = readComposeFile(composePath)
if (getComposeVersion(composeYaml) >= 2) {
val dockerMachine = getSetting(dockerMachineName)
dockerRemoveNetwork(instanceName, dockerMachine)
Expand Down

0 comments on commit 811fbc0

Please sign in to comment.