| title | Deploying a MySQL database backed Java app to Tomcat on Azure with Azure DevOps |
|---|---|
| layout | page |
| sidebar | vsts2 |
| permalink | /labs/vstsextend/tomcat/ |
| folder | /labs/vstsextend/tomcat/ |
Last updated : {{ "now" | date: "%b %d,%Y" }}
In this lab, you will learn how you can use Azure Pipelines in Azure DevOps to deploy a Java web application to Apache Tomcat{:target="_blank"} with a MySQL database on Azure. Apache Tomcat is an open-source Java Servlet Container developed by the Apache Software Foundation (ASF). MySQL is a very popular open-source relational database management system.
For this lab, you will use Azure App Service and Azure Database for MySQL, a relational database service based on the open source MySQL Server engine. It is a fully managed database as a service, capable of handing mission-critical workload with predictable performance and dynamic scalability.
This lab will show how you will
- Create a new Azure App Service and configure it to use Apache Tomcat
- Create a new MySQL database
- Use Azure App Service Task to deploy a WAR file
-
Refer the Getting Started page before you follow the lab exercises.
-
Use MyShuttle as a template to provision the new Azure DevOps project using the Azure DevOps Demo Generator{:target="_blank"}.
-
Use the Web App + MySQL Azure template from the Azure Marketplace to create a Website and MySQL Database together to start developing even faster.
-
This template provides two MySQL options :
- Azure Database for MySQL provides a managed database service for app development. You will choose this option.
- MySQL In app is an App Service feature where MySQL database is created for your web app. In this scenario, MySQL server is running on the same instance side by side with your web server hosting the site. This is recommended for development purposes and has no additional cost.
-
Wait for the web app and the database to be provisioned. It roughly takes 3-5 minutes.
-
Navigate to the resource group that you have created. You should see an Azure Database for MySQL server provisioned. Select the database server.
-
Select Properties. Save the SERVER NAME and SERVER ADMIN LOGIN NAME to a notepad.
In this example, the server name is myshuttle-1-mysqldbserver.mysql.database.azure.com and the admin user name is mysqldbuser@myshuttle-1-mysqldbserver.
Next, navigate to the web app that you have created. As you are deploying a Java application, you need to change the web app's web container to Apache Tomcat.
-
Click Application Settings. To change it to Tomcat, you will first need to install Java. Select a Java Version to install and then change Web container to use Apache Tomcat. For this lab, you will choose Java 8 and Apache Tomcat 9.0 though the version number would not matter much for the simple app that we are deploying.
-
Click on Save and wait for the update to be applied. Then navigate to the web app URL again and now you should see a different page.
Next, you need to update the connection strings for the web app to connect to the database correctly. There are multiple ways you can do this - but for the purpose of this lab, you will take a simple approach by updating it directly on the Azure portal.
-
From the Azure portal, select the Web app you provisioned. Select Application Settings and scroll down to the Connection Strings section.
-
Click + Add new connection string, change the type to MySQL, name as MyShuttleDb and paste the following string for the value and replace MySQL Server Name, your user name and your password with the appropriate values -
jdbc:mysql://{MySQL Server Name}:3306/alm?useSSL=true&requireSSL=false&autoReconnect=true&user={your user name}&password={your password}- MySQL Server Name : Value that you copied previously from the MySQL server Properties.
- your user name : Value that you copied previously from the MySQL server Properties.
- your password : Value that you provided during the creation of MYSQL database server in the Deploy to Azure phase.
-
Click on Save to save the connection string.
You have now setup and configured all the resources that is needed to deploy and run the MyShuttle application.
-
Select Pipelines and then Releases.
-
Select MyShuttle Release and click Edit Pipeline to open the release definition.
-
If you are following this lab from Jenkins hands-on-lab, make sure the artifact is pointing to Jenkins. Otherwise, it should be pointing to the Build artifact as shown below:
If you havent followed the Jenkins hands-on-lab, then notice that a CI build under Builds section has completed and its artifacts are linked here.
-
Click Tasks, select Azure-Dev and choose the Azure subscription details from the drop down. Click Authorize and login to your Azure subscription in the pop-up window. Provide or choose the created App Service Name with the web app that you created previously.
-
Click Tasks and select Execute Azure MySQL : SqlTaskFile task and provide the following details.
- Azure Subscription Details : Select the appropriate subscription.
- Host Name : Select the MySQL Database server host name that was created.
- Server Admin Login : Provide the SERVER ADMIN LOGIN NAME that you noted down previously.
- Password : Provide the password that you created during the creation of Azure Web App + MYSQL database server in the Azure portal.
-
Select the Deploy Azure App Service task, select the Azure subscription from the drop down and ensure that the created app service name is reflected correctly.
{% include note.html content= "We are using the Deploy Azure App Service task. This task is used to update Azure App Service to deploy Web Apps and WebJobs to Azure. The task works on cross platform agents running Windows, Linux or Mac and uses the underlying deployment technologies of Web Deploy and Kudu. The task works for ASP.NET, ASP.NET Core 1 and Node.js based web applications. Note that this task works with Azure Resource Manager APIs only." %}
-
Click on Save and then +Release | Create Release to start a new release
-
Wait for the release to complete. Then navigate to the Web App and select the URL from the overview blade. Add /myshuttledev context to the URL. For instance - http://myshuttle1.azurewebsites.net/myshuttledev{:target="_blank"}
-
Select Login and try logging in to the site with any one of the following credentials.
Username Password barney barneypassword fred fredpassword -
If your database was setup correctly and the connection parameters are valid, you should be able to login to the portal.
{% include warning.html content="If you encounter an error with The specified CGI application encountered an error and the server terminated the process message, check whether you have entered the app settings variables and values (for the database connection) correctly" %}
In this lab, you have learnt how to deploy a Tomcat based Java application with MySQL database on Azure through Azure Pipelines.











