Config server not able to find the remote application file - spring-boot

I'm having issue with referring the application/config file on a config server.
I already have a GAIA DEV Pool ready.
This is what I have done so far -
Created an application.yml file with required config property
hello-service:
message: Hello World From Spring Cloud Config Server
Checked it in git repo - feature/cs-hello branch.
Logged in to dev pool cf login -a [dev-pool-url]
Created the config server :
cf create-service -c "{\"git\": { \"label\": \"feature/cs-hello\", \"uri\": \""[GIT HTTPS URL]\", \"username\": \"[USERNAME]\", \"password\": \"[PASSWORD]\" } }" p-config-server standard config-server
Now, my referring [https://docs.pivotal.io/spring-cloud-services/1-4/common/config-server/configuring-with-git.html] - since my config file is not on the master branch, I used label.
Somehow my code is not finding the application file on config server.
Anyone here who can point me a direction?

Once you are done with config server creation, you need to bind that service with your application and you can need to provide following information in bootstrap.yml
spring:
application:
name: appName
There is a way to check either your config server is connecting to repository or not. Go to
PCF manager -->Services--> Config Server--> Manage
and then you should be able to see
Config server is online

Related

Environment variables for Spring Cloud Config in Docker

So, I am learning about microservices (I am a beginner) and I'm facing an issue. I've went through the Spring Cloud Config and Docker docs hoping to find a solution, but I didn't.
I have an app with 3 microservices (Spring Boot) and 1 config server (Spring Cloud Config). I'm using a private Github repository for storing config files and this is my application.properties file for config server:
spring.profiles.active=git
spring.cloud.config.server.git.uri=https://github.com/username/microservices-config.git
spring.cloud.config.server.git.clone-on-start=true
spring.cloud.config.server.git.default-label=master
spring.cloud.config.server.git.username=${GIT_USERNAME}
spring.cloud.config.server.git.password=${GIT_ACCCESS_TOKEN}
I have a Dockerfile based on which I have created a Docker image for config server (with no problems). I created a docker-compose.yml which I use to create and run containers, but it fails because of an exception in my cloud config app. The exception is:
org.eclipse.jgit.api.errors.TransportException: https://github.com/username/microservices-config.git: not authorized
Which basically means that my environment variables GIT_USERNAME and GIT_ACCCESS_TOKEN (that I set up in Intellij's "Edit configuration" and use in application.properties) are not available for the config server to use in a container.
The question is: Do I need to somehow add those environment variables to .jar or to Docker image or to Docker container? Like I'm not sure how do I make them available for the config server to use in a container.
Any help or explanation is welcomed :)

How to configure Spring Cloud Config Server to use cloned configuration files

My application.properties files of my Cloud Config Server looks like this.
config.source=Local Cloud Server #just to check where config come from
server.port=8012
encrypt.key=xxxxxxxxxxxxxx
spring.profiles.active=staging
spring.application.name=my-config-server
# Git Backend
spring.cloud.config.server.git.username=MY_USERNAME
spring.cloud.config.server.git.password=ghp_MY-DEV-ACCESS-TOKEN
spring.cloud.config.server.git.uri=https://github.com/my-username/app-config
spring.cloud.config.server.git.clone-on-start=true
spring.cloud.config.server.git.basedir=file://${user.dir}/cloned_configurations
On startup a new folder "cloned_configuration" is created inside of Cloud Config Server folder. I see all of my propertie files cloned form github with correct values.
But for some reason none of these are used. For e.g config.source must have the value "GitHub" because the cloned application.repository has an entry
config.source=GitHub
But on application start I see "Local Cloud Server". All other settings are also not used from cloned properties.
With Postman I can receive all Configs without any issues. But none of theme are used by my Config Server or any of my other webservices.All webservices and the config server using their own application.properties file.
What I do wrong?
You probably need to move your config server properties into your bootstrap.properties file instead of application.properties.
spring.cloud.config.server.git.username=MY_USERNAME
spring.cloud.config.server.git.password=ghp_MY-DEV-ACCESS-TOKEN
spring.cloud.config.server.git.uri=https://github.com/my-username/app-config
spring.cloud.config.server.git.clone-on-start=true
spring.cloud.config.server.git.basedir=file://${user.dir}/cloned_configurations
https://cloud.spring.io/spring-cloud-config/multi/multi__spring_cloud_config_client.html

Spring cloud config server git-uri local file resolves to master

In my app's bootstrap.yml file i have placed this configurations
spring:
application:
name: arun-test
cloud:
config:
server:
bootstrap: ${LOCAL_CLOUD_CONFIG_BOOTSTRAP:false}
git:
uri: file:${LOCAL_CLOUD_CONFIG_DIR}
I clone my properties folder from Github and then before starting the app, i turn my spring-boot app in to config server with below commands
export LOCAL_CLOUD_CONFIG_BOOTSTRAP=true
export LOCAL_CLOUD_CONFIG_DIR=/Users/arun/arunLabs/app-properties
./gradlew bootrun // to start
This works exactly fine.. But when i create a new branch and change the properties there to test something, the app always resolves to master-branch only and then it is still using my old configurations. Not going in to my branch
Not only that, it also replaces my file in the new branch with the one that is in master.
How to test it against my branch ?
Actually what you're looking for is a client side request. Cloud config will serve all branches in your repository.
You can read in the documentation.
You can either set the label value on your spring cloud Config Client
spring.cloud.config.label=newBranch
Or you can request directly to cloud config service
localhost:8080/{application}/{profile}/newBranch

Spring Cloud Config Server Not picking changes

I am trying to setup spring config cloud using local file system.
Below is my config on cloud server.
server.port=8888
spring.profiles.active=native
spring.cloud.config.server.native.searchLocations=classpath:/
Bootstrap.properties on client app is as shown below
spring.application.name=hello-world
spring.cloud.config.uri=http://localhost:8888
management.endpoints.web.exposure.include=*
I have also created hello-world.yml on class path for the hello-world spring boot application with property, test: Hello World
Followed below steps to make use of config server.
Step 1: Update the config file and start cloud config server. Able to
see config http://localhost:8888/hello-world/default
Step 2: Start client app hello-world, client app able to read the
test property file from cloud config server.
Step 3: Make changes to config by updating test: Good Bye on
hello-world.yaml.
At this moment, if I check
http://localhost:8888/hello-world/default ,it still shows old value.
Step 4: Run /actuator/refresh on client app. But it won't detect
any change on config server.
The new changes are reflected only if I restart the cloud config server.
Is there any configuration issue causing the cloud config server to unable to listen to changes ?
I could see o.s.cloud.commons.util.InetUtils : Cannot determine local hostname INFO log on cloud config app.
First of all I followed the same exact steps you followed and got the same issue, after almost day of search and study on the matter found out the followings,
we shouldn't use classpath:/<whatever> for
spring.cloud.config.server.native.searchLocations
because when we use so and build the project and run the location refers to the directory inside the generated .jar file, so we will not be able to update it in runtime.
To confirm this you can stop config server, open you .jar archive and delete hello-world.yml file then try http://localhost:8888/hello-world/default you will get default null responses
So we have to use some other locations for spring.cloud.config.server.native.searchLocations either with full directory path or just directory from app running location
Examples
For full path in windows use file:///full-path
spring.cloud.config.server.native.searchLocations: file:///E:\configs
Just for a directory (which will search project root directory if you running from IDE, if running jar then target directory or jar location spring.cloud.config.server.native.searchLocations: configs
spring.cloud.config.server.native.searchLocations: configs\whatever
we can configure multiple locations too as follows, spring.cloud.config.server.native.searchLocations: file:///E:\configs, configs

Why Spring Boot Cloud Config Server properties not picked from GIT

I have the following issue. Just with the basic Spring Boot Config Server, I would like to read property file from my Github (i tried also Gitlab). Everything works localy, the property file is nicely loaded from Github, but after deploying application on any other environment, for example on Heroku or on dedicated Linux server, the property file is not loaded. I am checking http://localhost:8101/employee/service1
Loading the property file from local files (classpath:config/local) works very well both locally and on other environments. What I am doing wrong? I have created simple project on Github (https://github.com/troger19/config-server), if anybody can check. Also app is deployed on Heroku: https://protected-savannah-48323.herokuapp.com/employee/service1
The application.yml looks like this
server:
port: 8101
spring:
application:
name: config-server
cloud:
config:
server:
git:
uri: https://github.com/troger19/config-server
search-paths: src\main\resources\config\dev
And the employee-service1.yml is in resources/config/dev
I havent find anything in the logs so far. Thank you for any suggestion.
Please change use "/" for linux environment as "\" will only work on window environment.
Please change your search-paths: src\main\resources\config\dev to /src/main/resources/configdev
Good idea to use different-2 profile in yml file for different environment so such can be avoided.

Resources