Skip to main content Link Menu Expand (external link) Document Search Copy Copied

Deploy the microservices of the Spring Petclinic app to Azure Container Apps

You now have an ACA environment deployed in your resource group and it has been enabled with some of the internal components. You are now ready to deploy your actual microservices to your ACA environment. For this first deployment you will use deploy from jar, which is a quick and easy way to deploy Java apps without the need to containerize. You can follow the below guidance to do so.

Deploy all the microservices to Azure Container Apps.

Make sure the api-gateway and admin-server microservices have public IP addresses available to them.

Step by step guidance

  1. From the Git Bash window, set a VERSION environment variable to the version number that you also find in the pom.xml file.

    VERSION=$(mvn -q -Dexec.executable=echo -Dexec.args='${project.version}' --non-recursive exec:exec)
    echo $VERSION
    
  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-aca-lab/src
    mvn clean package -DskipTests
    
  3. Once your build has finished, you can create each of the microservices. You’ll start with the api-gateway. Since this is the entrypoint to your other microservices, you will create it with an external ingress. Also, you will bind this app to the configserver and eureka components you created earlier.

    APP_NAME=api-gateway
    
    az containerapp create \
       --name $APP_NAME \
       --resource-group $RESOURCE_GROUP \
       --ingress external \
       --target-port 8080 \
       --environment $ACA_ENVIRONMENT \
       --min-replicas 1 \
       --artifact ./spring-petclinic-api-gateway/target/spring-petclinic-api-gateway-$VERSION.jar \
       --bind $JAVA_CONFIG_COMP_NAME $JAVA_EUREKA_COMP_NAME \
       --runtime java
    
  4. Wait for the provisioning of this first service to finish, and then create the next microservice. This will be the admin-server, which is similar in settings to the api-gateway.

    APP_NAME=admin-server
    az containerapp create \
       --name $APP_NAME \
       --resource-group $RESOURCE_GROUP \
       --ingress external \
       --target-port 8080 \
       --environment $ACA_ENVIRONMENT \
       --min-replicas 1 \
       --artifact ./spring-petclinic-admin-server/target/spring-petclinic-admin-server-$VERSION.jar \
       --bind $JAVA_CONFIG_COMP_NAME $JAVA_EUREKA_COMP_NAME \
       --runtime java
    
  5. Wait for the provisioning to finish, now you can create the other microservices, customers, vets and visits. These will be internal microservices, exposed by the api-gateway. Since these microservices connect to the MySQL database, you will also assign them the user assigned managed identity.

    APP_NAME=customers-service
    az containerapp create \
       --name $APP_NAME \
       --resource-group $RESOURCE_GROUP \
       --ingress internal \
       --target-port 8080 \
       --environment $ACA_ENVIRONMENT \
       --min-replicas 1 \
       --artifact ./spring-petclinic-customers-service/target/spring-petclinic-customers-service-$VERSION.jar \
       --bind $JAVA_CONFIG_COMP_NAME $JAVA_EUREKA_COMP_NAME \
       --runtime java
    
    APP_NAME=vets-service
    az containerapp create \
       --name $APP_NAME \
       --resource-group $RESOURCE_GROUP \
       --ingress internal \
       --target-port 8080 \
       --environment $ACA_ENVIRONMENT \
       --min-replicas 1 \
       --artifact ./spring-petclinic-vets-service/target/spring-petclinic-vets-service-$VERSION.jar \
       --bind $JAVA_CONFIG_COMP_NAME $JAVA_EUREKA_COMP_NAME \
       --runtime java
    
    APP_NAME=visits-service
    az containerapp create \
       --name $APP_NAME \
       --resource-group $RESOURCE_GROUP \
       --ingress internal \
       --target-port 8080 \
       --environment $ACA_ENVIRONMENT \
       --min-replicas 1 \
       --artifact ./spring-petclinic-visits-service/target/spring-petclinic-visits-service-$VERSION.jar \
       --bind $JAVA_CONFIG_COMP_NAME $JAVA_EUREKA_COMP_NAME \
       --runtime java