Add support for matching profiles as well as applications

Patterns in the form {application}/{profile} are now supported with
the old behaviour being the default (all profiles matched if none
are specified).

Fixes gh-214
This commit is contained in:
Dave Syer
2015-09-25 09:50:52 +01:00
parent da2b20c8be
commit 25dfa37612
3 changed files with 143 additions and 27 deletions

View File

@@ -143,7 +143,10 @@ the URL if you are using a command line client like curl (e.g. escape
them from the shell with quotes '').
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:
----
spring:
@@ -155,25 +158,59 @@ spring:
repos:
simple: https://github.com/simple/config-repo
special:
pattern: pattern*,*pattern1*
pattern: special*/dev*,*special*/dev*
uri: https://github.com/special/config-repo
local:
pattern: local*
uri: file:/home/configsvc/config-repo
----
In the above example, if `{application}` does not match 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 named "simple").
The pattern format is a comma-separated list of application names with
wildcards (a pattern beginning with a wildcard may need to be quoted).
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
sub-directories, and patterns to search for those directories can be
specified as `searchPaths`. For example at the top level: