From 8b55f346f3de72cf9b76404c578140f1289c6b17 Mon Sep 17 00:00:00 2001 From: Timur Evdokimov Date: Thu, 31 Jan 2019 09:52:03 +0100 Subject: [PATCH] force instance name from config --- src/main/scala/com/tapad/docker/DockerComposeKeys.scala | 2 ++ src/main/scala/com/tapad/docker/DockerComposePlugin.scala | 4 +++- src/main/scala/com/tapad/docker/DockerComposeSettings.scala | 1 + 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/scala/com/tapad/docker/DockerComposeKeys.scala b/src/main/scala/com/tapad/docker/DockerComposeKeys.scala index d33b569..2c90e8b 100644 --- a/src/main/scala/com/tapad/docker/DockerComposeKeys.scala +++ b/src/main/scala/com/tapad/docker/DockerComposeKeys.scala @@ -16,6 +16,7 @@ trait DockerComposeKeysLocal { val composeRemoveTempFileOnShutdown = settingKey[Boolean]("True if a Docker Compose should remove the post Custom Tag processed Compose File on shutdown. This defaults to True.") val composeContainerStartTimeoutSeconds = settingKey[Int]("The amount of time in seconds to wait for the containers in a Docker Compose instance to start. Defaults to 500 seconds.") val dockerMachineName = settingKey[String]("If running on OSX the name of the Docker Machine Virtual machine being used. If not overridden it is set to 'default'") + val composeInstanceName = settingKey[String]("Force instance name instead of auto-generating random one") val dockerImageCreationTask = taskKey[Any]("The sbt task used to create a Docker image. For sbt-docker this should be set to 'docker.value' for the sbt-native-packager this should be set to '(publishLocal in Docker).value'.") val suppressColorFormatting = settingKey[Boolean]("True to suppress all color formatting in the output from the plugin. This defaults to the value of the 'sbt.log.noformat' property.") val testTagsToExecute = settingKey[String]("Set of ScalaTest Tags to execute when dockerComposeTest is run. Separate multiple tags by a comma. It defaults to executing all tests.") @@ -29,4 +30,5 @@ trait DockerComposeKeysLocal { val runningInstances = AttributeKey[List[RunningInstanceInfo]]("runningInstances", "For Internal Use: Contains information on the set of running Docker Compose instances.") val variablesForSubstitution = settingKey[Map[String, String]]("A Map[String,String] of variables to substitute in your docker-compose file. These are substituted by the plugin and not using environment variables.") val variablesForSubstitutionTask = taskKey[Map[String, String]]("An sbt task that returns a Map[String,String] of variables to substitute in your docker-compose file. These are substituted by the plugin and not using environment variables.") + } diff --git a/src/main/scala/com/tapad/docker/DockerComposePlugin.scala b/src/main/scala/com/tapad/docker/DockerComposePlugin.scala index 396763d..f4ac9ba 100644 --- a/src/main/scala/com/tapad/docker/DockerComposePlugin.scala +++ b/src/main/scala/com/tapad/docker/DockerComposePlugin.scala @@ -76,6 +76,7 @@ object DockerComposePlugin extends DockerComposePluginLocal { val composeRemoveNetworkOnShutdown = DockerComposeKeys.composeRemoveNetworkOnShutdown val composeRemoveTempFileOnShutdown = DockerComposeKeys.composeRemoveTempFileOnShutdown val composeContainerStartTimeoutSeconds = DockerComposeKeys.composeContainerStartTimeoutSeconds + val composeInstanceName = DockerComposeKeys.composeInstanceName val dockerMachineName = DockerComposeKeys.dockerMachineName val dockerImageCreationTask = DockerComposeKeys.dockerImageCreationTask val testDependenciesClasspath = DockerComposeKeys.testDependenciesClasspath @@ -265,7 +266,8 @@ class DockerComposePluginLocal extends AutoPlugin with ComposeFile with DockerCo //Generate random instance name so that it won't collide with other instances running and so that it can be uniquely //identified from the list of running containers - val instanceName = generateInstanceName(state) + val settingInstanceName = getSetting(composeInstanceName) + val instanceName = if (settingInstanceName != "default") settingInstanceName else generateInstanceName(state) val newState = Try { val ret = dockerComposeUp(instanceName, updatedComposePath) diff --git a/src/main/scala/com/tapad/docker/DockerComposeSettings.scala b/src/main/scala/com/tapad/docker/DockerComposeSettings.scala index 7f68977..ce36e89 100644 --- a/src/main/scala/com/tapad/docker/DockerComposeSettings.scala +++ b/src/main/scala/com/tapad/docker/DockerComposeSettings.scala @@ -26,6 +26,7 @@ trait DockerComposeSettingsLocal extends PrintFormatting { }, // By default set the Compose service name to be that of the sbt Project Name composeServiceName := name.value.toLowerCase, + composeInstanceName := "default", composeServiceVersionTask := version.value, composeNoBuild := false, composeRemoveContainersOnShutdown := true,