Deploy the Spring Petclinic app components to the Spring Apps service Enterprise
You now have the compute and data services available for deployment of the components of your applications, including spring-petclinic-admin-server
, spring-petclinic-customers-service
, spring-petclinic-vets-service
, spring-petclinic-visits-service
and spring-petclinic-api-gateway
. In this task, you will deploy these components as microservices to the Azure Spring Apps service. You will not be deploying the spring-petclinic-config-server
and spring-petclinic-discovery-server
to Azure Spring Apps, since these will be provided to you by the platform. To perform the deployment, you can use the following guidance:
-
Quickstart: Build and deploy apps to Azure Spring Apps using the Enterprise plan.
The
spring-petclinic-api-gateway
andspring-petclinic-admin-server
will have a public endpoint assigned to them.
Step by step guidance
-
In the src directory parent pom.xml file double check the version number on line 9.
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>3.0.2</version> </parent>
-
From the Git Bash window, set a
VERSION
environment variable to this version number3.0.2
.VERSION=3.0.2
-
You will start by building all the microservice of the spring petclinic application. To accomplish this, run
mvn clean package
in the root directory of the application.cd ~/workspaces/java-microservices-asa-e-lab/src mvn clean package -DskipTests
-
Verify that the build succeeds by reviewing the output of the
mvn clean package -DskipTests
command, which should have the following format:[INFO] ------------------------------------------------------------------------ [INFO] Reactor Summary for spring-petclinic-microservices 3.0.2: [INFO] [INFO] spring-petclinic-microservices ..................... SUCCESS [ 0.249 s] [INFO] spring-petclinic-admin-server ...................... SUCCESS [ 16.123 s] [INFO] spring-petclinic-customers-service ................. SUCCESS [ 6.749 s] [INFO] spring-petclinic-vets-service ...................... SUCCESS [ 4.845 s] [INFO] spring-petclinic-visits-service .................... SUCCESS [ 5.063 s] [INFO] spring-petclinic-config-server ..................... SUCCESS [ 1.777 s] [INFO] spring-petclinic-discovery-server .................. SUCCESS [ 2.563 s] [INFO] spring-petclinic-api-gateway ....................... SUCCESS [ 15.582 s] [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 55.901 s [INFO] Finished at: 2023-06-02T14:07:49Z [INFO] ------------------------------------------------------------------------
-
You will set a couple of environment variables for the name of each app.
API_GATEWAY=api-gateway ADMIN_SERVER=admin-server CUSTOMERS_SERVICE=customers-service VETS_SERVICE=vets-service VISITS_SERVICE=visits-service
-
For each application you will now create an app on Azure Spring Apps service. You will start with the
api-gateway
. To deploy it, from the Git Bash prompt, run the following command:az spring app create \ --name $API_GATEWAY \ --assign-endpoint true
Wait for the provisioning to complete. This might take about 5 minutes.
-
Next, bind the application to the Application Configuration Service.
az spring application-configuration-service bind --app ${API_GATEWAY}
-
And also bind the app to the service registry.
az spring service-registry bind --app ${API_GATEWAY}
-
Next deploy the jar file to this newly created app by running the following command from the Git Bash prompt:
API_GATEWAY_JAR=spring-petclinic-api-gateway/target/spring-petclinic-api-gateway-$VERSION.jar az spring app deploy --name ${API_GATEWAY} \ --config-file-patterns ${API_GATEWAY} \ --artifact-path ${API_GATEWAY_JAR}
-
In the same way create an app for the
admin-server
microservice, bind it and deploy it:az spring app create \ --name $ADMIN_SERVER \ --assign-endpoint true az spring application-configuration-service bind --app ${ADMIN_SERVER} az spring service-registry bind --app ${ADMIN_SERVER} ADMIN_SERVER_JAR=spring-petclinic-admin-server/target/spring-petclinic-admin-server-$VERSION.jar az spring app deploy --name ${ADMIN_SERVER} \ --config-file-patterns ${ADMIN_SERVER} \ --artifact-path ${ADMIN_SERVER_JAR}
Wait for each operation to complete. This might take about 5 minutes.
-
Next, you will create, bind and deploy an app for the
customers-service
microservice, without assigning an endpoint:az spring app create \ --name $CUSTOMERS_SERVICE az spring application-configuration-service bind --app ${CUSTOMERS_SERVICE} az spring service-registry bind --app ${CUSTOMERS_SERVICE} CUSTOMERS_SERVICE_JAR=spring-petclinic-customers-service/target/spring-petclinic-customers-service-$VERSION.jar az spring app deploy --name ${CUSTOMERS_SERVICE} \ --config-file-patterns ${CUSTOMERS_SERVICE} \ --artifact-path ${CUSTOMERS_SERVICE_JAR}
Wait for each operation to complete. This might take about 5 minutes.
-
Once deployed, take a look at the
customers-service
logs to make sure the configuration gets picked up correctly and there are no errors on startup.az spring app logs --name ${CUSTOMERS_SERVICE} --follow
In case you see no errors, you can escape out of the log statement with
Ctrl+C
and you can proceed with the next steps. In case you see errors, review the steps you executed and retry. The LabTips file also contains steps on how to recover from errors. -
Next, you will create, bind and deploy an app for the
visits-service
microservice, also without an endpoint assigned:az spring app create \ --name $VISITS_SERVICE az spring application-configuration-service bind --app ${VISITS_SERVICE} az spring service-registry bind --app ${VISITS_SERVICE} VISITS_SERVICE_JAR=spring-petclinic-visits-service/target/spring-petclinic-visits-service-$VERSION.jar az spring app deploy --name ${VISITS_SERVICE} \ --config-file-patterns ${VISITS_SERVICE} \ --artifact-path ${VISITS_SERVICE_JAR}
Wait for each operation to complete. This might take about 5 minutes.
-
To conclude, you will create, bind and deploy an app for the
vets-service
microservice, again without an endpoint assigned:az spring app create \ --name $VETS_SERVICE az spring application-configuration-service bind --app ${VETS_SERVICE} az spring service-registry bind --app ${VETS_SERVICE} VETS_SERVICE_JAR=spring-petclinic-vets-service/target/spring-petclinic-vets-service-$VERSION.jar az spring app deploy --name ${VETS_SERVICE} \ --config-file-patterns ${VETS_SERVICE} \ --artifact-path ${VETS_SERVICE_JAR}
Wait for each operation to complete. This might take about 5 minutes.