From d8c51cec81ddd07bf1e0ed2c3e94fc533035decb Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Sun, 15 Jun 2014 10:37:13 +0100 Subject: [PATCH] Add fetch() to existing repository --- README.md | 51 ++++++++++--------- .../server/JGitEnvironmentRepository.java | 1 + 2 files changed, 29 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 5d191aee..79905403 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,15 @@ Spring Platform Config provides server and client-side support for externalized configuration in a distributed system. With the Config -Server you have a central place to manage external properties for the -applications across all environments. The concepts on both sides map -identically to the Spring `Environment` and `PropertySource` -abstractions, so they fit very well with Spring applications. As an -application moves through the deployment pipeline from dev to test and -into production you can manage the configuration that needs to change +Server you have a central place to manage external properties for +applications across all environments. The concepts on both client and +server map identically to the Spring `Environment` and +`PropertySource` abstractions, so they fit very well with Spring +applications. As an application moves through the deployment pipeline +from dev to test and into production you can manage the configuration between those environments and be certain that applications have everything they need to run when they migrate. The default -implementation of the server repository strategy uses git as a storage -backend so it easily supports labelled versions of configurations. +implementation of the server storage uses git so it easily supports +labelled versions of configuration environments. ## Quick Start @@ -33,29 +33,31 @@ $ curl localhost:8888/foo/development ``` The default strategy for locating property sources is to clone a git -repository (at "spring.platform.config.server.uri") and use it to initialize -a `SpringApplication`. The application's `Environment` is used to -enumerate property sources. The service has resources in the form: +repository (at "spring.platform.config.server.uri") and use it to +initialize a mini `SpringApplication`. The mini-application's +`Environment` is used to enumerate property sources and publish them +via a JSON endpoint. The service has resources in the form: ``` -/{name}/{profile}[/{label}] +/{application}/{profile}[/{label}] ``` -where the "name" is used as the config name in the `SpringApplication` -(i.e. what is normally "application" in a regular Spring Boot app), -"profile" is an active profile (or comma-separated list of -properties), and "label" is an optional git label (defaults to +where the "application" is injected as the "spring.config.name" in the +`SpringApplication` (i.e. what is normally "application" in a regular +Spring Boot app), "profile" is an active profile (or comma-separated +list of properties), and "label" is an optional git label (defaults to "master"). ### Client Side Usage -Build a client (e.g. see the test cases for the config-client) as a -Spring Boot application that depends on spring-platform-config-client. +To use these features in an application, just build it as a Spring +Boot application that depends on spring-platform-config-client +(e.g. see the test cases for the config-client, or the sample app). When it runs it will pick up the external configuration from the default local config server on port 8888 if it is running. To modify -the startup behaviour you can change the location of the server using -`bootstrap.properties` (like `application.properties` but for the -bootstrap phase of an application context), e.g. +the startup behaviour you can change the location of the config server +using `bootstrap.properties` (like `application.properties` but for +the bootstrap phase of an application context), e.g. ``` spring.platform.config.uri: http://myconfigserver.com @@ -70,6 +72,9 @@ mechanisms (for instance "mvn spring-boot:run"). When it runs it will look for the config server on "http://localhost:8888" by default, so you could run the server as well to see it all working together. -The sample has a tets case where the config server is also started in +The sample has a test case where the config server is also started in the same JVM (with a different port), and the test asserts that an -environment property from the git configuration repo is present. +environment property from the git configuration repo is present. To +change the location of the config server just set +"spring.platform.config.uri" in "bootstrap.yml" (or via System +properties etc.). diff --git a/spring-platform-config-server/src/main/java/org/springframework/platform/config/server/JGitEnvironmentRepository.java b/spring-platform-config-server/src/main/java/org/springframework/platform/config/server/JGitEnvironmentRepository.java index a016dadb..efe96c6d 100644 --- a/spring-platform-config-server/src/main/java/org/springframework/platform/config/server/JGitEnvironmentRepository.java +++ b/spring-platform-config-server/src/main/java/org/springframework/platform/config/server/JGitEnvironmentRepository.java @@ -79,6 +79,7 @@ public class JGitEnvironmentRepository implements EnvironmentRepository { Git git; if (new File(basedir, ".git").exists()) { git = Git.open(basedir); + git.fetch().call(); } else { if (basedir.exists()) { try {