Search code examples
cloud-foundryspring-cloud-configconfigserver

How to setup Pivotal Cloud Foundry Config Server to use multiple search paths from my git repo?


I have a local config server and it works okay with yml configurations setup like this?

spring:
  cloud:
    config:
      server:
        git:
          uri: https://github.com/xxx/xxxxx
          search-paths:
          - 'kenya*' 
          - 'tanzania*' 
          - 'uganda*' 
          - 'congo*'
          - 'zimbabwe*'

In my local project, I can access all of these repos like

http://localhost:8888/uganda/dev

This returns the correct files with the selected profile ad expected.

However when I setup the Pivotal Config server, I only get the default properties regardless of what parameters I add to the path.

Something like this https://configserver.cfapps.io/uganda/dev only returns the default properties at the root of the repo.

How can I use the

searchPaths Stated here https://docs.run.pivotal.io/spring-cloud-services/config-server/configuring-with-git.html

flag to add all my sub folders?


Solution

  • If you're using Pivotal Spring Cloud Services, you can create a service using multiple searchPaths like this:

    cf create-service -c '{ "git": { "uri": "https://github.com/dmikusa-pivotal/cook-config.git", "label": "search-paths", "searchPaths": "dev,prod" } }' cook-config-server
    

    The searchPaths argument just takes a comma separated list of search paths/patterns.

    The repository that you're pointed to, should then have top level folders called dev and prod. Config server will then return <app-name>.properties (all all the other variations it supports) from within the search path folder.

    You can validate that you're receiving multiple search paths worth of data, by running a command like this:

    curl -k -H "Authorization: bearer $(curl -k -s -X POST 'https://p-spring-cloud-services.uaa.<system_domain>/oauth/token' -d 'grant_type=client_credentials&client_id=<insert client id>&client_secret=<insert client_secret>' | jq .access_token | cut -d '"' -f 2)" <insert uri>/cook/prod
    

    You need to replace <system_domain> with the system domain for your foundation, <insert client id> and <insert client secret> with your service instance's client id and secret (run cf env <app> against an app that has a bound SCS Config server to get these values).

    This command will do two things. First, it will use the client_id and client_secret to fetch a token. The token is then used in a second request to actually request some data from the config server.

    You should see output like this, if you're getting config from multiple search paths (note how there's data from dev and prod subfolders):

    {"name":"cook","profiles":["prod"],"label":null,"version":"5d5a3f26022dd00becdbad855c7d27ae530685f7","state":null,"propertySources":[{"name":"https://github.com/dmikusa-pivotal/cook-config.git/prod/cook.properties","source":{"cook.special":"Prod Config"}},{"name":"https://github.com/dmikusa-pivotal/cook-config.git/dev/cook.properties","source":{"cook.special":"Dev Config"}},{"name":"https://github.com/dmikusa-pivotal/cook-config.git/cook.properties","source":{"cook.special":"Not in Folder config"}}]}
    

    Hope that helps!