Set up a configuration repository
The Spring Petclinic microservices provides a config server that your apps can use. You do need to however provide a git repository for this config server and link this git repo to the server. The current configuration used by the Spring microservices resides in the config folder of the GitHub repo for this lab. You will need to create your own private git repo in this exercise, since, in one of its steps, you will be changing some of the configuration settings.
We simplified some of the original config of the spring-petclinic-microservices application to make some of the lab steps easier to execute.
As part of the setup process, you need to create a Personal Access Token (PAT) in your GitHub repo and make it available to the config server. It is important that you make note of the PAT after it has been created.
Once you have your own config repository to work with, you will have to update the spring-petclinic-config-server/src/main/resources/application.yml file of the spring-petclinic-config-server application to make use of this new repo.
Step by step guidance
-
On your lab computer, in your web browser, navigate to your GitHub account, navigate to the Repositories page and create a new private repository named spring-petclinic-microservices-config.
Make sure to configure the repository as private.
-
Once the repo gets created, copy the clone URL.
-
To create a PAT, in your browser, select the avatar icon in the upper right corner, and then select Settings.
-
At the bottom of the vertical navigation menu, select Developer settings, select Personal access tokens, and then select Generate new token.
-
On the New personal access token page, in the Note text box, enter a descriptive name, such as spring-petclinic-config-server-token.
There is a new Beta experience available on GitHub for more fine-grained access tokens. This experience will create a token with a more limited scope than full repository scope (which basically gives access to all your repositories). The lab will work as well with a more fine-grained token, in that case, in the Fine-grained tokens (Beta) token creation page, choose for Only select repositories and select your config repository. For the Repository permissions select for the Contents the Read-only access level. You can use this fine-grained token when you configure your config-server on Azure Spring Apps. We recommend you create a second token in case you also need a personal access token for interacting with the repositories from the Git Bash prompt.
-
In the Select scopes section, select repo and then select Generate token.
-
Record the generated token. You will need it in this and subsequent labs.
You can check the validity of your token with the following statement:
curl -XGET -H 'authorization: token <token_value>' 'https://api.github.com/repos/<user_name>/spring-petclinic-microservices-config'
. This statement should succeed. If it does not, redo the above steps for generating the PAT token.In case you are running this lab in a GitHub codespace, you can use the same Create a codespace option as you did for the lab project for making edits in the config repo. In the config repository, go to Code and next Codespaces. Next select Create a codespace. Your codespace of the config repository will now get created in your browser window. You can do this instead of the below clone steps. You will need to execute the below
curl
steps in your codespace. In case you don’t see the Create a codespace option in your repository, add a README.md file, refresh the page and retry. -
From the Git Bash prompt, change the current directory to the workspaces folder. Next, clone the newly created GitHub repository by typing
git clone
, pasting the clone URL you copied into Clipboard in the previous step, and entering the PAT string followed by the@
symbol in front ofgithub.com
.cd ~/workspaces # Clone config repo git clone https://<token>@github.com/<your-github-username>/spring-petclinic-microservices-config.git
Make sure to replace the
<token>
and<your-github-username>
placeholders in the URL listed above with the value of the GitHub PAT and your GitHub user name when running thegit clone
command. -
From the Git Bash prompt, change the current directory to the newly created spring-petclinic-microservices-config folder and run the following commands to copy all the config server configuration yaml files from the config folder of the GitHub repo for this lab to the local folder on your lab computer.
cd spring-petclinic-microservices-config curl -o api-gateway.yml https://raw.githubusercontent.com/Azure-Samples/java-microservices-aks-lab/main/config/api-gateway.yml curl -o application.yml https://raw.githubusercontent.com/Azure-Samples/java-microservices-aks-lab/main/config/application.yml curl -o customers-service.yml https://raw.githubusercontent.com/Azure-Samples/java-microservices-aks-lab/main/config/customers-service.yml curl -o discovery-server.yml https://raw.githubusercontent.com/Azure-Samples/java-microservices-aks-lab/main/config/discovery-server.yml curl -o tracing-server.yml https://raw.githubusercontent.com/Azure-Samples/java-microservices-aks-lab/main/config/tracing-server.yml curl -o vets-service.yml https://raw.githubusercontent.com/Azure-Samples/java-microservices-aks-lab/main/config/vets-service.yml curl -o visits-service.yml https://raw.githubusercontent.com/Azure-Samples/java-microservices-aks-lab/main/config/visits-service.yml
-
From the Git Bash prompt, run the following commands to commit and push your changes to your private GitHub repository.
git add . git commit -m 'added base config' git push
-
In your web browser, refresh the page of the newly created spring-petclinic-microservices-config repository and double check that all the configuration files are there.
-
To configure the spring-petclinic-config-server microservice so it points to your GitHub repository, in your java-microservices-aks-lab project navigate to the spring-petclinic-config-server/src/main/resources/application.yml file and update the uri of the git repo to use your own git repo uri. Also add 2 additional settings for your PAT username and password.
uri: https://github.com/your-org/your-config-repo-uri username: your-username password: your-PAT-password default-label: the-branch-name-in-case-you-will-not-be-using-the-main-branch
In case you are saving your config on another branch than the main branch of the repository, you can indicate the branch in the default-label setting. In case you are using the main branch, you can omit this setting.
The
uri
should not include the.git
extension.Notice that currently the PAT token giving access to your GitHub repositories is visible in plain text in the spring-petclinic-config-server microservice application.yml file. You should not commit this to your repository on GitHub, or your PAT would be exposed. Luckily GitHub security would immediately revoke the PAT in case you would accidentally commit and push it to your repo. In one of the next steps we will remediate this, so the PAT is no longer visible in the application.yml file. In case you do accidentally push your PAT to a remote GitHub repo, you can check out the LabTips to recover from this.