2

Context

I am attempting to separate configuration information for our applications using the pattern-matching feature in Spring Cloud Config Server. I have created a repo for "production" environment with a property file floof.yaml. I have created a repo for "development" environment with a property file floof-dev.yaml.

My server config:

spring:
  application:
    name: "bluemoon"
  cloud:
    config:
      server:
        git:
          uri: file://${user.home}/tmp/prod
          repos:
            development:
              pattern:
                - \*/dev
              uri: file://${user.home}/tmp/dev

After starting the server instance, I can successfully retrieve the config content using curl, and can verify which content was served by referring to the "source" element as well as the values for the properties themselves.

Expected Behavior

When I fetch http://localhost:8080/floof/prod I expect to see the source "$HOME/tmp/prod/floof.yaml" and the values from that source, and the actual results match that expectation.

When I fetch http://localhost:8080/floof/dev I expect to see the source "$HOME/tmp/dev/floof-dev.yaml" and the values from that source, but the actual result is the "production" file and contents (the same as if I had fetched .../floof/prod instead.

My Questions

  1. Is my expectation of behavior incorrect? I assume not since there is an example in the documentation in the "Git backend" section that suggests separation by profile is a thing.
  2. Is my server config incorrectly specifying the "development" repo? I turned up the logging verbosity in the server instance and saw nothing in there that called attention to itself in terms of misconfiguration.
  3. Are the property files subject to a naming convention that I'm not following?
  • You're describing the behavior of if it didn't match, use the default. Maybe a problem with the pattern? This is the pattern matching library: https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/util/AntPathMatcher.html – spencergibb Nov 24 '15 at 23:33

1 Answers1

3

I had the same issue. Here is how I resolved:: spring cloud config pattern match for profile

Also, check if you are using Brixton.M5 version.

After some debugging on the PatternMatching source code here is how I resolved the issue: You can choose one of the two ways.

application.yml
server:
  port: 8888
spring:
  cloud:
    config:
      server:
        git:
          uri: ssh://xxxx@github/sample/cloud-config-properties.git
          repos:
           development:
            pattern: '*/development' ## give in quotes
            uri: ssh://git@xxxgithub.com/development.git

OR

development:
  pattern: xx*/development,*/development ##since it is not allowed to have a value starting with a wildcard( '*' )after pattern I first gave a generic matching but the second value is */development. Since pattern takes multiple values, the second pattern will match with the profile.
  uri: ssh://git@xxxgithub.com/development.git

pattern: */development.Error on yml file- expected alphabetic or numeric character, but found but found /.

The reason the profile pattern git repo was not identified because : although spring allows multiple array values for pattern beginning with a '-' in the yml file, the pattern matcher was taking the '-' as string to be matched. i.e it is looking for a pattern '-*/development' instead of '*/development'.

 repos:
    development:
     pattern:
      -*/development    
      -*/staging 

Another issue i observed was, I was getting a compilation error on yml file if i had to mention the pattern array as '- */development' - note space after hyphen(which is meant to show that it can hold multiple values as array) and start with a '*/development' with an error: expected alphabetic or numeric character, but found but found /

repos:
        development:
         pattern:
          - */development    
          - */staging 
Community
  • 1
  • 1
Swetha V
  • 300
  • 5
  • 16