Why Spring Boot Cloud Config Server properties not picked from GIT - spring-boot

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.

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 :)

Should I use only native profile if I want to use local config files in spring boot?

I'm setting local development environment to test using spring boot ver 2.7.1, and I want to use local file hierarchy as config server.
So, I use spring.cloud.config.server.native.searchLocations: ~~~.
I want to boot this project using profile named something other except 'native' (application-native.yml). But it is failed to load the server.
My Question:
When I want to use local files as config files, is it only possible to use 'native' profile?
I tried :
spring:
profiles:
active: local
cloud:
config:
server:
native:
searchLocations:
~~~~
still failed.

Spring Cloud Config - Git backend

I was going through Spring Cloud Config's documentation and what I learnt is that the Spring prefers using Git as a config repository as it supports labelling/branching etc., and it is also the default option with Spring Cloud Config.
Now I have two questions
I am accustomed to storing all the properties on the server (one of the 12-factor app tenets). So am pretty confused as to why Git repo is suggested for config which can be easily seen by others within the organization especially while storing production config
My second question is about storing {cipher}ed values in the property file. Again, though the value is encrypted, but still keeping the encrypted text in Git seems to be as a not a good approach.
Requesting for anyone to provide insight on these questions.
You can disable Git ssl config -
git config --global http.sslVerify false
Create a Git Personal Access Token.
Use token to keep in spring.cloud.config.token property.
Use config below in application.yml
server:
git:
uri: https://github.com/AKS/config/
OR
uri: file:///AKS/config/
skipSslValidation: true
search-paths:
- config-map
try-master-branch: false
username: user
password: ******
default-label: <branch-name-git-branch>
clone-on-start: true
You can use you config server with a local property files stored on your host. To do so, you just need to use the native profile with the following properties
spring.profiles.active=native
spring.cloud.config.server.native.searchLocations=file:///C:/path/to/your/config/folder
Then the following properties to set up your Git repo are not longer needed:
#spring.cloud.config.server.git.uri=...
#spring.cloud.config.server.git.username=...
#spring.cloud.config.server.git.password=...
#spring.cloud.config.server.git.timeout=10
#spring.cloud.config.server.git.clone-on-start=true

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

Config server not able to find the remote application file

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

Resources