9f1df4b3e8
* update the github token generation * update links |
||
---|---|---|
.. | ||
media | ||
AzureReposForConfig.md | ||
README.md |
README.md
04 - Configure a Spring Cloud Config server
This guide is part of the Azure Spring Apps training
A key feature of cloud-native applications is externalized configuration - the ability to store, manage, and version configuration separately from the application code. In this section, we'll configure a Spring Cloud Config Server to enable this functionality. In the next section, you'll see how Spring Cloud Config can inject configuration from a Git repository into your application.
💡 If your organization uses Azure Repos as your source code repository, see Using Azure Repos for Azure Spring Apps configuration
⏱ If you want to skip the step of creating a private repository, you can use this public repository instead: https://github.com/Azure-Samples/spring-cloud-sample-public-config.git. Storing configuration in a public repository is not recommended in real-world deployments. We offer this public repository only as a shortcut for this workshop, for example if you don't have a GitHub account.
To use this shortcut:
- Go to the Azure portal.
- Go to the overview page of your Azure Spring Apps server and select "Config server" in the menu
- Set the repository URL:
https://github.com/Azure-Samples/spring-cloud-sample-public-config.git
- Click on "Validate" and wait for the operation to succeed
- Click on "Apply" and wait for the operation to succeed
We have enabled Azure Spring Apps to create a configuration server with the configuration files from this repository. You can now proceed to the next guide: ➡ 05 - Build a Spring Boot microservice using Spring Cloud features
Create a Git repository for storing the application configuration
On your GitHub account, create a new private repository where the Spring Boot configurations will be stored.
In the new private GitHub repository, add a new application.yml
file which will store configuration data for all our microservices.
Typically, each Spring Boot application includes such a file within the application's deployable artifact to contain application settings. A Spring Cloud Config Server allows such settings to be stored at a single location and served from a single source.
For the moment, our application.yml
will just store a message to check if the configuration is successful:
application:
message: Configured by Azure Spring Apps
Commit and push the new file.
Create a GitHub personal token
Azure Spring Apps can access Git repositories that are public, secured by SSH, or secured using HTTP basic authentication. We will use that last option, as it is easier to create and manage with GitHub.
Let's create a new token by going into the GitHub developer settings and selecting "Personal access tokens" and "Fine-grained tokens" in the menu. Give it a name such as spring apps training
.
We select the private config repository, we've just created.
And then we specify the Repository permissions.
Only the Contents
Read-only
permission is required.
After that is done, click on "Generate token" and copy the token value.
Once the token is generated, leave that tab open until the end of this section.
If you need more help here, please follow the GitHub guide to create a personal token documentation.
Configure Azure Spring Apps to access the Git repository
- Go to the Azure portal.
- Go to the overview page of your Azure Spring Apps server and select "Config server" in the menu
- Configure the repository we previously created:
-
Add the repository URL, for example
https://github.com/Azure-Samples/spring-cloud-sample-public-config.git
💡 Make sure you include the
.git
ending in the URL. -
For the label, select the branch name, for example the GitHub default
main
-
Click on
Authentication
and selectHTTP Basic
-
The username is your GitHub login name
-
The password is the personal token we created in the previous section
-
- Click on "Validate" and wait for the operation to succeed
- Click on "Apply" and wait for the operation to succeed
Review
We have now created a private configuration repository. We have enabled Azure Spring Apps to create a configuration server with the configuration files from this repository.
In the next section, we will create an application that consumes this configuration, specifically the custom message we defined in application.yml
.
⬅️ Previous guide: 03 - Configure application logs
➡️ Next guide: 05 - Build a Spring Boot microservice using Spring Cloud features