The Payara Platform is perfect for deploying Jakarta EE and MicroProfile applications on Microsoft Azure. One rapid option for deploying on Azure is to use Azure Application Services, especially Web App for Containers. The WebApp for Containers service allows you to rapidly deploy production Payara Micro applications onto Azure in seconds, allowing both rapid horizontal and vertical scaling on demand.
In this blog post we will walk you through creating a Docker image of your application based on Payara Micro and deploying this to Microsoft Azure. Throughout the blog post we will be using the Azure CLI for Linux.
If you follow the instructions you will need to replace the names we use in this blog with names specific to your organisation.
First, we will create a new Resource Group called payara-app-rg in Azure to contain any resource we create for this blog post.
Next, we will create a container registry within the same resource group. A container registry is needed to store our Docker images. Alternatively you can publish your image to docker hub or any other registry.
To use the registry from Docker we will need to login to the registry. To do so we need to know the credentials which can be found by running:
This will show the username and pasword required for login via docker. Note the URL for your container registry which will be shown when creating your registry.
docker login https://payaraappregistry.azurecr.io
Creating the Base Docker Image
For creating our application docker image, rather than using the published Payara Micro docker file, we shall create our own. To do this I will assume you have a web application you wish to deploy and that you have downloaded Payara Micro from the Payara website.
To make things simpler for future applications first we will create a base image for Payara Micro on Azure and then layer our application on top of the base image. This can then be reused for other applications and microservices and will reduce the image sizes we push applications. We will create the base image from the Azul Zulu Open JDK image, as Payara support customers also get support for Azul Zulu Open JDK builds.
Our Dockerfile looks like:
And can be built using:
Creating the Application Image
Now all we need to do is layer the war file we wish to deploy onto this image.
I’ve created a simple war file demonstrating a simple MicroProfile JAX-RS web service in this repo, once you’ve cloned the repository build the application using Maven and then build a local docker image using the command:
You can test this image using the command:
Once running you can test the REST service using the URL: http://127.0.0.1:8080/AzureWebAppsExample/webresources/example
Pushing the Docker Image to Azure Container Registry
Before we can use the created docker image with Azure App Services we need to upload the container to your Azure container registry. We can do this simple with docker by tagging the local image as a remote image and then using docker push:
You can test your image has been uploaded successfully by using the azure CLI
Creating the Azure Application
Now we have a Docker image of our application on Azure Container Registry we can create an Azure Application and run it directly on Microsoft Azure. First step is to create an app service plan. The service plan determines the resources your application can use and the features available. To see more detail about what each plan level contains, see the documentation. For our application we will use the standard service plan which gives us access to autoscaling.
Now we have created the service plan we can create and deploy our application.
We also have to configure the application to use the Azure container registry to find the application image.
Once we have configured the container we can start the application.
Once the application has started you should be able to browse to the service on the URL.
Pass Configuration to Your Application
If you hit the REST endpoint now you will see that the environment variable injected via the config api is not configured. To set the environment variable you can use the Azure CLI.
Once this has been set you will need to restart the web application. App Service settings are passed to the docker container as environment variables and can be retrieved via the Microprofile config api or can be used to configure datasource connect strings, usernames and passwords.
Payara Micro Makes it Easy to Deploy MicroProfile and Java EE Apps on Azure
You can see that it is very easy to deploy MicroProfile and Java EE applications on Microsoft Azure using Azure App Services. All you need to do is create a Docker image with Payara Micro and you can be up and running rapidly with load balancing and auto scale out and auto scale up.