Azure App Services
In this guide, we describe how to deploy a Jmix application to Azure App Services cloud.
Before starting the guide, create a Microsoft Azure account and Azure DevOps account, and ensure that you have access to Azure portal.
We will use PostgreSQL as a database for this guide. |
Creating The Azure Environment
Launch the Azure Cloud Shell from the Azure portal and begin with creating a resource group:
az group create --name MyJmixGroup1 --location eastus
After that, create a PostgreSQL server. Here sku
stands for Stock Keeping Unit, so --sku-name GP_Gen5_2
maps to General Purpose pricing tier, Generation 5, and 2 virtual cores. Pass your own database credentials in the command:
az postgres server create --resource-group MyJmixGroup1 --name myjmixpostgres1 --admin-user jmixadmin --admin-password ChangeMe@42 --sku-name GP_Gen5_2
Remember the password, as you will not be able to see it anywhere in the Azure interface.
Navigate to myjmixpostgres1 in portal, open Connection security, set Allow access to Azure services to Yes and click Save.
Jmix Project Setup
If you want to use a local PostgreSQL database for development, your Data Store settings and application.properties
should contain connection parameters for the local database, for example:
main.datasource.url = jdbc:postgresql://localhost/demo
main.datasource.username = root
main.datasource.password = root
The Azure PostgreSQL connection parameters should be specified in the Gradle task configuration as described below.
Open build.gradle
and add the Azure WebApp Plugin for Gradle to the plugins
section:
plugins {
// ...
id "com.microsoft.azure.azurewebapp" version "1.2.0"
}
Then add the azurewebapp
task configuration with your Azure parameters and credentials:
azurewebapp {
subscription = '<your-subscription-id>'
resourceGroup = 'MyJmixGroup1' (1)
appServicePlanName = 'MyJmixPlan1' (2)
appName = 'MyJmixApp1' (3)
pricingTier = 'P1v2'
region = 'eastus'
runtime {
os = 'Linux'
webContainer = 'Java SE' (4)
javaVersion = 'Java 11' (5)
}
appSettings { (6)
put('main.datasource.url', 'jdbc:postgresql://myjmixpostgres1.postgres.database.azure.com:5432/postgres')
put('main.datasource.username', 'jmixadmin@myjmixpostgres1')
put('main.datasource.password', 'ChangeMe@42')
}
}
1 | The resource group which you created in Azure portal. |
2 | The app service plan will be created automatically on first deployment. |
3 | The app name which will be used also in your application URL. |
4 | A container for Spring Boot executable JAR. |
5 | Java version must correspond to the version used to compile the application. |
6 | The appSettings section allows you to set environment variables for connecting to the Azure PostgreSQL when the application is deployed to the cloud. Here myjmixpostgres1 is the name of PostgreSQL server created above. |
Now you can deploy the application to Azure cloud with the following command:
./gradlew azureWebAppDeploy
If the deployment was successful, the running application is available at https://myjmixapp1.azurewebsites.net
.
If you got an error from Gradle, try to execute the command again with the --stacktrace
option to see the cause:
./gradlew azureWebAppDeploy --stacktrace
To enable application logging, open the app in the portal and select App Service logs. In the Application logging field, select File System and click Save. After that, redeploy the application from the command line or restart it at the app overview page in the portal.
To view or download the logs, go to the app page in the portal, Diagnose and solve problems → Availability and Performance → Application Logs.