Spring

 View Only

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

Isaac Kiyimba's profile image
Isaac Kiyimba posted May 15, 2019 06:14 PM

I have a local cloud 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?

 

Daniel Mikusa's profile image
Daniel Mikusa

Are you using Pivotal Spring Cloud Services? or are you deploying your own config server based on OSS code to Cloud Foundry? Also, are you using Pivotal Web Services (PWS)? Thanks

Daniel Mikusa's profile image
Daniel Mikusa

OK, with your Spring Cloud Services instance, the configuration you'd need to set would be through either `cf create-service -c` when you initially create the instance or when you `cf update-service -c` to updated the config.

 

I didn't test this, but I believe something like this should get you want you have in your local Config Server config snippet:

 

-c '{"git": { "uri": "https://github.com/xxx/xxxxx", "searchPaths": "kenya*,tanzania*,uganda*,congo*,zimbabwe*"} }'

 

The examples I could find for using `searchPaths` suggest that it can take a comma delimited list of search paths.

 

https://cloud.spring.io/spring-cloud-config/single/spring-cloud-config.html#_pattern_matching_and_multiple_repositories

 

I think that should be it. Unless you need multiple git repo's (i.e. multiple separate URI's), then I don't think you should need to worry about the multiple repository support.

 

Hope that helps!

Isaac Kiyimba's profile image
Isaac Kiyimba

Hi Daniel,

 

I am using Pivotal Web Services, and in there I have a development space which includes 1 app at the moment (Its my very first time).

 

Secondly I am not deploying my own config server, I am using the one provides as a service by Pivotal through this tutorial (https://docs.run.pivotal.io/spring-cloud-services/config-server/configuring-with-git.html), However having worked with one using OSS locally, I wanted to achieve the same but at the moment its a bit tricky to make my spring boot apps use the server because I think I have failed to set up multiple repositories as explained in the question.

 

Any help would be highly appreciated

 

 

Isaac Kiyimba's profile image
Isaac Kiyimba

Hi Daniel, thanks for the reply, However I have tried it and it does not include other sub folders, only the first entry is added for this case only "kenya" properties are returned,

 

These are the configurations I tried,

 

  • Only the first entry Kenya worked and the others where ignored,

-c '{"git": { "uri": "https://github.com/isaachambers/DemoConfigurations", "searchPaths": "kenya*,uganda*,tanzania*"} }'

 

  • the second one I tried had the same result. Kenya was the only one picked up.

-c '{"git": { "uri": "https://github.com/isaachambers/DemoConfigurations", "searchPaths": ["kenya*","uganda*","tanzania*"]} }'

Daniel Mikusa's profile image
Daniel Mikusa

Sorry for the delay, this took me some time to try this in the lab.

 

In my lab environment, running SCS 2.0.8, this works as expected. Let me walk you through what I did to confirm.

 

1.) I created a service and pointed it to https://github.com/dmikusa-pivotal/cook-config, which is my fork of the demo config repo. I didn't set a search path and just used the master branch.

cf create-service -c '{ "git": { "uri": "https://github.com/spring-cloud-services-samples/cook-config", "label": "master" } }' p-config-server standard cook-config-server

2.) I then pushed the cook demo app. See here. This should automatically bind the service from step #[1.]​ 

 

3.) Access the app in your browser and go to the `/restaurants` endpoint to confirm that it's working. When the `development` profile is set, you should see the message from the dev config file & when `production` is set you should see the message from the prod config. This is a basic sanity check.

 

4.) From here on out, it is easier to test the functionality using `curl` than it is with an app. To do that you need to grab a couple pieces of information. So run `cf env cook` and look at the VCAP_SERVICES for the app. Grab the uri, client_id and client_secret. We'll use them in the next step.

 

5.) We can then query config server directly using the following `curl` command (this needs a Bash shell and won't work on Windows, at least without the subsystem for Linux or something like that). Makes sure you insert the uri, client id and client secret into the place holders in the command before you run it.

curl -k -H "Authorization: bearer $(curl -k -s -X POST 'https://p-spring-cloud-services.uaa.run.pivotal.io/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

This 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.

 

To test, we want to update our service and do two things. First, point to the `search-paths` branch of my config repo which has folders. Second, add in a single searchPaths entry. We'll start there and work up to multiple searchPaths.

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

When that has completed, run the curl command above and check the output. You should see that it's found two config files, cook.properties from the root and dev/cook.properties.

 

Update the service again and add a second search path.

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

When this completes run the curl command again. This time you should see config from three files. It will look like the output below. You should be able to see that it's returning config from all three locations: the root, my first search path and my second search path (since these all have config files that match the app name), which is what the search path feature is supposed to do.

{"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"}}]}

At any rate, I hope that explains what the feature is supposed to do. You can then give it a try with your repo & see what you get back. It's difficult to provide more guidance without seeing the repo and requests that you're making. If you need more help, please follow up with the URL to a public repo with your config, the `cf update-service -c` config and the `curl` command you're using to load the config.

 

Thanks!

Daniel Mikusa's profile image
Daniel Mikusa

Fantastic!

Isaac Kiyimba's profile image
Isaac Kiyimba

Hi, Thanks for the response once again. I have managed to get it working with your help, I changed the configuration like this and I am able to get the expected results. I changed the label to master,

 

cf update-service -c '{ "git": { "uri": "https://github.com/isaachambers/ConfigurationProperties.git", 

"label": "master", "searchPaths": "uganda,kenya,tanzania" } }' DemoConfigServer

 

 

Thank you very much.