@SpringBootApplication
+@EnableConfigServer
+public class ConfigServer {
+ public static void main(String[] args) {
+ SpringApplication.run(ConfigServer.class, args);
+ }
+}
+diff --git a/ghpages.sh b/ghpages.sh index 91905757..e1063ce3 100644 --- a/ghpages.sh +++ b/ghpages.sh @@ -12,13 +12,20 @@ if ! [ -d docs/target/generated-docs ]; then exit 0 fi +# Find name of current branch +################################################################### +branch=$TRAVIS_BRANCH +[ "$branch" == "" ] && branch=`git rev-parse --abbrev-ref HEAD` +target=. +if [ "$branch" != "master" ]; then target=./$branch; mkdir -p $target; fi + # Stash any outstanding changes ################################################################### git diff-index --quiet HEAD dirty=$? if [ "$dirty" != "0" ]; then git stash; fi -# Switch to gh-pages branch to sync it with master +# Switch to gh-pages branch to sync it with current branch ################################################################### git checkout gh-pages @@ -26,21 +33,22 @@ for f in docs/target/generated-docs/*; do file=${f#docs/target/generated-docs/*} if ! git ls-files -i -o --exclude-standard --directory | grep -q ^$file$; then # Not ignored... - cp -rf $f . - git add -A $file + cp -rf $f $target + git add -A $target/$file fi done -git commit -a -m "Sync docs from master to gh-pages" +git add -A README.adoc || echo "No change to README.adoc" +git commit -a -m "Sync docs from $branch to gh-pages" || echo "Nothing committed" # Uncomment the following push if you want to auto push to -# the gh-pages branch whenever you commit to master locally. +# the gh-pages branch whenever you commit to branch locally. # This is a little extreme. Use with care! ################################################################### -git push origin gh-pages +git push origin gh-pages || echo "Cannot push gh-pages" -# Finally, switch back to the master branch and exit block -git checkout master +# Finally, switch back to the current branch and exit block +git checkout $branch if [ "$dirty" != "0" ]; then git stash pop; fi exit 0 diff --git a/spring-cloud-config.html b/spring-cloud-config.html index 3e9b7fe0..3aacc74c 100644 --- a/spring-cloud-config.html +++ b/spring-cloud-config.html @@ -429,9 +429,11 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b
Spring Cloud 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 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, but can be used with any application running in any language. 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 storage backend uses git so it easily supports labelled versions of configuration environments, as well as being accessible to a wide range of tooling for managing the content. It is easy to add alternative implementations and plug them in with Spring configuration.
The Server provides an HTTP, resource-based API for external
configuration (name-value pairs, or equivalent YAML content). The
server is easily embeddable in a Spring Boot application using the
-@EnableConfigServer annotation.
@EnableConfigServer annotation. So this app is a config server:
+@SpringBootApplication
+@EnableConfigServer
+public class ConfigServer {
+ public static void main(String[] args) {
+ SpringApplication.run(ConfigServer.class, args);
+ }
+}
+Like all Spring Boot apps it runs on port 8080 by default, but you
+can switch it to the conventional port 8888 in various ways. The
+easiest, which also sets a default configuration repository,
+is by launching it with spring.config.name=configserver (there
+is a configserver.yml in the Config Server jar). Another is
+to use your own application.properties, e.g.
server.port: 8888
+spring.cloud.config.server.git.uri: file://${HOME}/config-repo
+where ${HOME}/config-repo is a git repository containing
+YAML and properties files.
|
+ Tip
+ |
+
+
+
+Here’s a recipe for creating the git repository in the example +above: +
+
+
+
+$ cd $HOME +$ mkdir config-repo +$ cd config-repo +$ git init . +$ echo info.foo: bar > application.properties +$ git add -A . +$ git commit -m "Add application.properties"+ |
+
|
+ Warning
+ |
++using the local filesystem for your git repository is +intended for testing only. Use a server to host your +configuration repositories in production. + | +
Spring Cloud Config Server supports a single or multiple git -repositories:
+repositories with pattern matching on the application and profile +name. The pattern format is a comma-separated list of +{application}/{profile} names with wildcards (where a pattern
+beginning with a wildcard may need to be quoted). Example:
In the above example, if {application} does not match to any of the -patterns, it will use the default uri defined under -"spring.cloud.config.server.git.uri". For the "simple" repository, the -pattern is "simple" (i.e. it only matches one application). The -pattern format is a comma-separated list of application names with -wildcards.
+If {application}/{profile} does not match any of the patterns, it
+will use the default uri defined under
+"spring.cloud.config.server.git.uri". In the above example, for the
+"simple" repository, the pattern is simple/* (i.e. it only matches
+one application named "simple" in all profiles). The "local"
+repository matches all application names beginning with "local" in all
+profiles (the /* suffix is added automatically to any pattern that
+doesn’t have a profile matcher).
|
+ Note
+ |
++the "one-liner" short cut used in the "simple" example above can +only be used if the only property to be set is the URI. If you need to +set anything else (credentials, pattern, etc.) you need to use the full +form. + | +
The pattern property in the repo is actually an array, so you can
+use a YAML array (or [0], [1], etc. suffixes in properties files)
+to bind to multiple patterns. You may need to do this if you are going
+to run apps with multiple profiles. Example:
spring: + cloud: + config: + server: + git: + uri: https://github.com/spring-cloud-samples/config-repo + repos: + development: + pattern: + - */development + - */staging + uri: https://github.com/development/config-repo + staging: + pattern: + - */qa + - */production + uri: https://github.com/staging/config-repo+
|
+ Note
+ |
+
+Spring Cloud will guess that a pattern containing a profile that
+doesn’t end in * implies that you actually want to match a list of
+profiles starting with this pattern (so */staging is a shortcut for
+["*/staging", "*/staging,*"]). This is common where you need to run
+apps in the "development" profile locally but also the "cloud" profile
+remotely, for instance.
+ |
+
Every repository can also optionally store config files in @@ -1004,6 +1138,16 @@ instance:
Encrypted values in a .properties file must not be wrapped in quotes, otherwise the value will not be decrypted:
+spring.datasource.username: dbuser
+spring.datasource.password: {cipher}FKSAJDFGYOS8F7GLHAKERGFHLSAJ
+You can safely push this plain text to a shared git repository and the secret password is protected.
|
+ Tip
+ |
+
+If you are testing like this with curl, then use
+--data-urlencode (instead of -d) or set an explicit Content-Type:
+text/plain to make sure curl encodes the data correctly when there
+are special characters ('+' is particularly tricky).
+ |
+
Take the encypted value and add the {cipher} prefix before you put
+
Take the encrypted value and add the {cipher} prefix before you put
it in the YAML or properties file, and before you commit and push it
-to a remote, potentially insecure store. The /encypt and /decrypt
+to a remote, potentially insecure store. The /encrypt and /decrypt
endpoints also both accept paths of the form /*/{name}/{profiles}
which can be used to control cryptography per application (name)
and profile when clients call into the main Environment resource.
To use a key in a file (e.g. an RSA public key for encyption) prepend +
To use a key in a file (e.g. an RSA public key for encryption) prepend the key value with "@" and provide the file path, e.g.
Instead of using the Environment abstraction (or one of the
+alternative representations of it in YAML or properties format) your
+applications might need generic plain text configuration files,
+tailored to their environment. The Config Server provides these
+through an additional endpoint at /{name}/{profile}/{label}/{path}
+where "name", "profile" and "label" have the same meaning as the
+regular environment endpoint, but "path" is a file name
+(e.g. log.xml). The source files for this endpoint are located in
+the same way as for the environment endpoints: the same search path is
+used as for properties or YAML files, but instead of aggregating all
+matching resources, only the first one to match is returned.
After a resource is located, placeholders in the normal format
+(${…}) are resolved using the effective Environment for the
+application name, profile and label supplied. In this way the resource
+endpoint is tightly integrated with the environment
+endpoints. Example, if you have this layout for a GIT (or SVN)
+repository:
application.yml +nginx.conf+
where nginx.conf looks like this:
server {
+ listen 80;
+ server_name ${nginx.server.name};
+}
+and application.yml like this:
nginx:
+ server:
+ name: example.com
+---
+spring:
+ profiles: development
+nginx:
+ server:
+ name: develop.com
+then the /foo/default/master/nginx.conf resource looks like this:
server {
+ listen 80;
+ server_name example.com;
+}
+and /foo/development/master/nginx.conf like this:
server {
+ listen 80;
+ server_name develop.com;
+}
+|
+ Note
+ |
+
+just like the source files for environment configuration, the
+"profile" is used to resolve the file name, so if you want a
+profile-specific file then /*/development/*/logback.xml will be
+resolved by a file called logback-development.xml (in preference
+to logback.xml).
+ |
+
The Config Server runs best as a standalone application, but if you need to you can embed it in another application. Just use the @@ -1220,6 +1479,70 @@ initialize the same way as any other application.
Many source code repository providers (like Github, Gitlab or Bitbucket
+for instance) will notify you of changes in a repository through a
+webhook. You can configure the webhook via the provider’s user
+interface as a URL and a set of events in which you are
+interested. For instance
+Github
+will POST to the webhook with a JSON body containing a list of
+commits, and a header "X-Github-Event" equal to "push". If you add a
+dependency on the spring-cloud-config-monitor library and activate
+the Spring Cloud Bus in your Config Server, then a "/monitor" endpoint
+is enabled.
When the webhook is activated the Config Server will send a
+RefreshRemoteApplicationEvent targeted at the applications it thinks
+might have changed. The change detection can be strategized, but by
+default it just looks for changes in files that match the application
+name (e.g. "foo.properties" is targeted at the "foo" application, and
+"application.properties" is targeted at all applications). The strategy
+if you want to override the behaviour is PropertyPathNotificationExtractor
+which accepts the request headers and body as parameters and returns a list
+of file paths that changed.
The default configuration works out of the box with Github, Gitlab or
+Bitbucket. In addition to the JSON notifications from Github, Gitlab
+or Bitbucket you can trigger a change notification by POSTing to
+"/monitor" with a form-encoded body parameters path={name}. This will
+broadcast to applications matching the "{name}" pattern (can contain
+wildcards).
|
+ Note
+ |
+
+the RefreshRemoteApplicationEvent will only be transmitted if
+the spring-cloud-bus is activated in the Config Server and in the
+client application.
+ |
+
|
+ Note
+ |
++the default configuration also detects filesystem changes in +local git repositories (the webhook is not used in that case but as +soon as you edit a config file a refresh will be broadcast). + | +