-
Notifications
You must be signed in to change notification settings - Fork 36
Support docker-compose variable substitution #17
Changes from 3 commits
01a287e
c28a9e2
e64279d
811fbc0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
name := "basic" | ||
|
||
version := "1.0.0" | ||
|
||
scalaVersion := "2.10.6" | ||
|
||
enablePlugins(JavaAppPackaging, DockerComposePlugin) | ||
|
||
dockerImageCreationTask := (publishLocal in Docker).value | ||
|
||
variablesForSubstitution := Map("SOURCE_PORT" -> "5555") |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
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" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
sbt.version=0.13.11 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
addSbtPlugin("com.typesafe.sbt" %% "sbt-native-packager" % "1.1.0") | ||
|
||
addSbtPlugin("com.tapad" % "sbt-docker-compose" % "1.0.8") |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import scala.Console._ | ||
import scala.concurrent.duration._ | ||
|
||
object BasicApp extends App { | ||
println("Application started....") | ||
|
||
val deadline = 1.hour.fromNow | ||
do { | ||
println(s"Running application. Seconds left until showdown: ${deadline.timeLeft.toSeconds}") | ||
Thread.sleep(1000) | ||
} while (deadline.hasTimeLeft()) | ||
|
||
println("Application shutting down....") | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,10 +42,12 @@ 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], instanceData: Option[Any] = None) | ||
servicesInfo: Iterable[ServiceInfo], variables: Vector[(String, String)] = Vector.empty, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should now be able to remove the previously added |
||
instanceData: Option[Any] = None) | ||
|
||
object DockerComposePlugin extends DockerComposePluginLocal { | ||
override def projectSettings = DockerComposeSettings.baseDockerComposeSettings | ||
|
@@ -65,6 +67,7 @@ object DockerComposePlugin extends DockerComposePluginLocal { | |
val testTagsToExecute = DockerComposeKeys.testTagsToExecute | ||
val testCasesJar = DockerComposeKeys.testCasesJar | ||
val scalaTestJar = DockerComposeKeys.testDependenciesClasspath | ||
val variablesForSubstitution = DockerComposeKeys.variablesForSubstitution | ||
} | ||
} | ||
|
||
|
@@ -148,11 +151,12 @@ class DockerComposePluginLocal extends AutoPlugin with ComposeFile with DockerCo | |
*/ | ||
def startDockerCompose(implicit state: State, args: Seq[String]): (State, String) = { | ||
val composeFilePath = getSetting(composeFile) | ||
val variables = getSetting(variablesForSubstitution).toVector | ||
|
||
printBold(s"Creating Local Docker Compose Environment.") | ||
printBold(s"Reading Compose File: $composeFilePath") | ||
|
||
val composeYaml = readComposeFile(composeFilePath) | ||
val composeYaml = readComposeFile(composeFilePath, variables) | ||
val servicesInfo = processCustomTags(state, args, composeYaml) | ||
val updatedComposePath = saveComposeFile(composeYaml) | ||
println(s"Created Compose File with Processed Custom Tags: $updatedComposePath") | ||
|
@@ -165,12 +169,12 @@ class DockerComposePluginLocal extends AutoPlugin with ComposeFile with DockerCo | |
|
||
val newState = Try { | ||
dockerComposeUp(instanceName, updatedComposePath) | ||
val newInstance = getRunningInstanceInfo(state, instanceName, updatedComposePath, servicesInfo) | ||
val newInstance = getRunningInstanceInfo(state, instanceName, updatedComposePath, servicesInfo, variables) | ||
|
||
printMappedPortInformation(state, newInstance, dockerComposeVersion) | ||
saveInstanceToSbtSession(state, newInstance) | ||
} getOrElse { | ||
stopLocalDockerInstance(state, instanceName, updatedComposePath) | ||
stopLocalDockerInstance(state, instanceName, updatedComposePath, variables) | ||
throw new IllegalStateException(s"Error starting Docker Compose instance. Shutting down containers...") | ||
} | ||
|
||
|
@@ -180,14 +184,14 @@ class DockerComposePluginLocal extends AutoPlugin with ComposeFile with DockerCo | |
} | ||
|
||
def getRunningInstanceInfo(implicit state: State, instanceName: String, composePath: String, | ||
servicesInfo: Iterable[ServiceInfo]): RunningInstanceInfo = { | ||
servicesInfo: Iterable[ServiceInfo], variables: Vector[(String, String)]): 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) | ||
RunningInstanceInfo(instanceName, composeService, composePath, serviceInfo, variables) | ||
} | ||
|
||
def pullDockerImages(args: Seq[String], services: Iterable[ServiceInfo]): Unit = { | ||
|
@@ -220,7 +224,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) | ||
stopLocalDockerInstance(state, instance.instanceName, instance.composeFilePath, instance.variables) | ||
} | ||
|
||
if (removeList.isEmpty) | ||
|
@@ -241,7 +245,8 @@ class DockerComposePluginLocal extends AutoPlugin with ComposeFile with DockerCo | |
updatedState | ||
} | ||
|
||
def stopLocalDockerInstance(implicit state: State, instanceName: String, composePath: String): Unit = { | ||
def stopLocalDockerInstance(implicit state: State, instanceName: String, composePath: String, | ||
variables: Vector[(String, String)]): Unit = { | ||
dockerComposeStopInstance(instanceName, composePath) | ||
|
||
if (getSetting(composeRemoveContainersOnShutdown)) { | ||
|
@@ -252,7 +257,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) | ||
val composeYaml = readComposeFile(composePath, variables) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this call to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After that we should be able to also remove the passing of |
||
if (getComposeVersion(composeYaml) >= 2) { | ||
val dockerMachine = getSetting(dockerMachineName) | ||
dockerRemoveNetwork(instanceName, dockerMachine) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
testservice: | ||
image: testservice:0.0.1 | ||
ports: | ||
- "${SOURCE_PORT}:5005" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Under the "Examples" section of the README you should add a "#5" to describe how this example demonstrates the usage of the
variablesForSubstitution
setting.