From 7f713e0d59dead7b2673f9ed50c7ad004378bcd3 Mon Sep 17 00:00:00 2001 From: Spencer Gibb Date: Thu, 11 Aug 2016 16:17:31 -0600 Subject: [PATCH] Add git.uri option. spring cloud --git-uri=http://mygit/myrepo.git configserver Above command option changes configserver to use the git profile with the configured git url. fixes gh-24 --- spring-cloud-launcher/README.md | 13 ++++++++++--- .../cloud/launcher/cli/LauncherCommand.java | 7 +++++++ .../cloud/launcher/deployer/DeployerThread.java | 11 +++++++++-- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/spring-cloud-launcher/README.md b/spring-cloud-launcher/README.md index bf5821c..178aaac 100644 --- a/spring-cloud-launcher/README.md +++ b/spring-cloud-launcher/README.md @@ -42,9 +42,16 @@ spring: The `name` attribute is required. If `waitUntilStarted` is true, Launcher will block until the application has reached the `deployed` state. Before commands are deployed, the list is sorted using Spring's `OrderComparator`. In the above case, `configserver` is deployed before any other app is deployed. Currently only `maven:` coordinates and standard Spring Resources (`file:`, etc...) are supported. -You can also use the `--deploy` option to select from the [predefined deployables](https://github.com/spring-cloud/spring-cloud-cli/blob/devtools/spring-cloud-launcher/spring-cloud-launcher-deployer/src/main/resources/cloud.yml). For example to run Spring Cloud Data Flow execute: +You can also select from the [predefined deployables](https://github.com/spring-cloud/spring-cloud-cli/blob/devtools/spring-cloud-launcher/spring-cloud-launcher-deployer/src/main/resources/cloud.yml). For example to run Spring Cloud Data Flow execute: ``` -spring cloud --launch=configserver,h2,kafka,dataflow +spring cloud eureka,configserver +``` + +### Config Server git uri + +To run configserver with a git repo use the `--git-uri` option. For example: +``` +spring cloud --git-uri=http://mygitserver/myrepo.git configserver ``` ### Stopping @@ -62,9 +69,9 @@ spring cloud --launch=configserver,h2,kafka,dataflow - [X] H2 Database - [X] Spring Cloud Dataflow server - [X] Launcher landing page (Eureka Dashboard works for now) +- [X] Sleuth/Zipkin - [ ] Support external rabbit - [ ] Speedup startup (parallel start?, retry for config server, db and kafka?) -- [ ] Sleuth/Zipkin - [ ] Cassandra Database - [ ] Client Side Library - [ ] Spring Boot Admin (Not compatible with Brixton) diff --git a/spring-cloud-launcher/spring-cloud-launcher-cli/src/main/java/org/springframework/cloud/launcher/cli/LauncherCommand.java b/spring-cloud-launcher/spring-cloud-launcher-cli/src/main/java/org/springframework/cloud/launcher/cli/LauncherCommand.java index 724fcbe..cf7085f 100644 --- a/spring-cloud-launcher/spring-cloud-launcher-cli/src/main/java/org/springframework/cloud/launcher/cli/LauncherCommand.java +++ b/spring-cloud-launcher/spring-cloud-launcher-cli/src/main/java/org/springframework/cloud/launcher/cli/LauncherCommand.java @@ -42,6 +42,7 @@ import org.springframework.boot.cli.compiler.grape.RepositoryConfiguration; import org.springframework.util.StringUtils; import groovy.lang.GroovyClassLoader; +import joptsimple.ArgumentAcceptingOptionSpec; import joptsimple.OptionSet; import joptsimple.OptionSpec; @@ -60,6 +61,7 @@ public class LauncherCommand extends OptionParsingCommand { EXAMPLES.add(new HelpExample("Launch Eureka", "spring cloud eureka")); EXAMPLES.add(new HelpExample("Launch Config Server and Eureka", "spring cloud configserver eureka")); EXAMPLES.add(new HelpExample("List deployable apps", "spring cloud --list")); + EXAMPLES.add(new HelpExample("Launch Config Server with git repo", "spring cloud --git-uri=http://example.com/proj.git configserver")); } public LauncherCommand() { @@ -75,11 +77,13 @@ public class LauncherCommand extends OptionParsingCommand { private OptionSpec debugOption; private OptionSpec listOption; + private ArgumentAcceptingOptionSpec gitUriOption; @Override protected void options() { this.debugOption = option(Arrays.asList("debug", "d"), "Debug logging for the deployer"); this.listOption = option(Arrays.asList("list", "l"), "List the deployables (don't launch anything)"); + this.gitUriOption = getParser().acceptsAll(Arrays.asList("git-uri", "g"), "URI for git repository for use with configserver").withRequiredArg(); } @Override @@ -120,6 +124,9 @@ public class LauncherCommand extends OptionParsingCommand { if (options.has(this.debugOption)) { args.add("--debug=true"); } + if (options.has(this.gitUriOption)) { + args.add("--git.uri=" + options.valueOf(this.gitUriOption)); + } if (options.has(this.listOption)) { args.add("--launcher.list=true"); } diff --git a/spring-cloud-launcher/spring-cloud-launcher-deployer/src/main/java/org/springframework/cloud/launcher/deployer/DeployerThread.java b/spring-cloud-launcher/spring-cloud-launcher-deployer/src/main/java/org/springframework/cloud/launcher/deployer/DeployerThread.java index 55de321..8b69a94 100644 --- a/spring-cloud-launcher/spring-cloud-launcher-deployer/src/main/java/org/springframework/cloud/launcher/deployer/DeployerThread.java +++ b/spring-cloud-launcher/spring-cloud-launcher-deployer/src/main/java/org/springframework/cloud/launcher/deployer/DeployerThread.java @@ -43,6 +43,7 @@ import org.springframework.cloud.deployer.spi.core.AppDeploymentRequest; import org.springframework.cloud.launcher.deployer.DeployerProperties.Deployable; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.core.OrderComparator; +import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.PropertySource; import org.springframework.core.env.StandardEnvironment; import org.springframework.core.io.ClassPathResource; @@ -136,7 +137,7 @@ public class DeployerThread extends Thread { logger.debug("Deployables {}", properties.getDeployables()); for (Deployable deployable : deployables) { - deploy(deployer, resourceLoader, deployable, properties); + deploy(deployer, resourceLoader, deployable, properties, context.getEnvironment()); } Runtime.getRuntime().addShutdownHook(new Thread() { @@ -180,7 +181,7 @@ public class DeployerThread extends Thread { } private String deploy(AppDeployer deployer, ResourceLoader resourceLoader, Deployable deployable, - DeployerProperties properties) { + DeployerProperties properties, ConfigurableEnvironment environment) { if (!shouldDeploy(deployable, properties)) { return null; } @@ -198,6 +199,12 @@ public class DeployerThread extends Thread { if (!shouldDeploy("eureka", properties)) { appDefProps.put("eureka.client.enabled", Boolean.FALSE.toString()); } + if (deployable.getName().equals("configserver") && environment.containsProperty("git.uri")) { + appDefProps.put("spring.profiles.active", "git"); + appDefProps.put("spring.cloud.config.server.git.uri", + environment.getRequiredProperty("git.uri")); + + } AppDefinition definition = new AppDefinition(deployable.getName(), appDefProps);