Movie Database App using Java on Azure

The purpose of this sample application is to illustrate a modern Java app in the cloud; the result of this project will be to create a movie database similar to IMDB.


In order to create and deploy this sample application, you need to have the following:

An Azure subscription; if you don't already have an Azure subscription, you can activate your MSDN subscriber benefits or sign up for a free Azure account.

In addition, you will need all of the following components before you go through the steps in this README:

| Azure CLI | Java 8 | Maven 3 | Git | Docker |

NOTE: There are additional requirements in the ~/deployment/ file which are required in order to setup your development environment; other required components will be installed automatically by the provisioning scripts.


In the following sections, you will create a development sandbox environment on Azure which uses the following components:

The following diagram illustrates the full topology for this sample application enviroment:

In this basic layout, the following design decisions have been implemented:

Note: For now, Node.js is being used instead of Java in this sample application for the Azure functions; this will be updated in the near future.

Create and Deploy the Sample Application

Download and customize the sample for your development environment

  1. Follow the steps in the ~/deployment/ file of the sample project to clone the project repo and set up your development environment.

  2. Navigate to the configuration directory for your Maven installation; for example: /usr/local/maven/3.5.0/libexec/conf/ or %ProgramFiles%\apache-maven\3.5.0\conf:

    a. Open the settings.xml file with a text editor.

    b. Add parameterized settings for ACR access settings to the <servers> collection in the the settings.xml file, this will enable Maven to use a private registry; for example:

               <email>[email protected]</email>

    c. Save and close your settings.xml file.

Create the initial build

  1. Open a command prompt and navigate to the ~/deployment/ folder of your local repo.

  2. Login to your Azure account and specify which subscription to use:

    az login
    az account set --subscription "<your-azure-subscription>"

    NOTE: You can use either a subscription name or id when specifying which subscription to use; to obtain a list of your subscriptions, type az account list.

  3. For Microsoft developers, we have network security group rules applied to the resources in the development subscriptions which restrict the network access from the internal CORP network. This blocks the SSH communications between the VM's provisioned in this project.

    To workaround this, set the environment variable MS_CORP before you start the provision process:

    export MS_CORP=1
  4. Build an initial layout on Azure using an ARM template from using one of the following methods:


    NOTE: On Windows, run all shell scripts in Git Bash.

    The provisioning script will create the following resources in Azure, which may take a long time to complete:

    • A MySQL instance
    • A Redis Cache instance
    • A Function app for resizing images
    • Two traffic managers for load balancing
    • An Azure Container Registry for hosting a private Docker image
    • Two Linux-based web apps for front-end websites
    • Two Azure Container Services (Kubernetes Clusters) for REST API services
    • An Azure Container Service (Kubernetes Cluster) for a Jenkins server

Deploy Java function to Azure Functions using Maven plugin

  1. Open a command prompt and navigate to the folder which contains the function app, which is located in the "~/function-app/" folder of your repo; this is a Java function app which:

    • Re-sizes images uploaded to Azure Storage

    • Trigger by an Azure Blob upload action.

  2. Build the data app:

    mvn clean package
  3. Deploy the function app to Azure Functions using Maven plugin:

    mvn azure-functions:deploy

Deploy the internal-facing data app into a Kubernetes cluster in ACS

  1. Open a command prompt and navigate to the folder which contains the data app, which is located in the "~/data-app/" folder of your repo; this is a Spring Boot app which:

    • Stores and reads data from Azure Database for MySQL using Spring JDBC

    • Stores images into and reads images from Azure Storage.

  2. Build and dockerize the data app, and push the container into ACR:

    mvn package docker:build -DpushImage
  3. Deploy the data app to a Kubernetes cluster in ACS using Maven:

    mvn clean fabric8:resource fabric8:apply
  4. Run below command to watch the creation process of your service object in Kubernetes. Wait until column EXTERNAL-IP has a valid IP address, which means your data app is accessible from internet now.

    kubectl get svc --namespace=${TARGET_ENV} --watch
  5. Navigate to the ~/deployment/ folder of your local repo and run the following script, which will configure various variables for your local enviroment:

    cd ../deployment

    NOTE: Microsoft is currently developing a Maven plugin to deploy to a Kubernetes cluster in Azure Container Service, so in the future you will be able to use mvn deploy.

Test your data app deployment

Run the following command to test whether your data app was successfully deployed:

   curl http://${DATA_API_URL}/api/v1

Deploy the Internet-facing web app into Linux containers in AAS

  1. Open the Internet-facing web app, which is located in the "~/web-app/" folder of your repo.

    • This is also a Spring Boot app which talks to the data app that we just deployed.

    • The web app can also use Azure Redis Cache using Spring Data Redis.

  2. Build and dockerize the web app, and push the container into ACR:

    mvn package docker:build -DpushImage
  3. Use Maven plugin for Azure Web Apps to deploy the web app to a Linux container in Azure App Service:

    mvn azure-webapp:deploy -Dwebapp.resourceGroup=${EAST_US_GROUP} -Dwebapp.appName=${EAST_US_WEBAPP_NAME}

    Learn more details about how to use Maven Plugin for Azure Web Apps with Azure Container Registry from this step-by-step tutorial at Microsoft Docs Site.

Test and diagnose your sample deployment

Test and diagnose using one of the following two methods:

OPTIONAL: Enable monitoring and diagnostics using third party services

You can optionally enable New Relic and OverOps monitoring and diagnostics in both the web app and data app by using the steps in the following sections.

Enable New Relic

To enable monitoring using New Relic, use the following steps.

Enable OverOps

To enable diagnostics using OverOps, use the following steps.

Enable Azure Application Insights

To enable monitoring using Azure Application Insights, use the following steps.

Automate continuous integration and continuous deployment (CI/CD) using Jenkins

  1. Use an existing Jenkins instance, setup continuous delivery - build and configure pipeline using:

    a. A pipeline config file from the cloned repo

    b. The forked repo

    As part of the initial build, a Jenkins cluster with pipelines is setup in a Kubernetes cluster in Azure Container Service. You can see that at:


    1. Download the Jenkins CLI JAR from your Jenkins server; for example:

      curl -O http://${JENKINS_URL}/jnlpJars/jenkins-cli.jar
    2. Log into your Jenkins Dashboard, then build and deploy the development, test and production releases for these environments:

      java -jar jenkins-cli.jar -s \
        http://${JENKINS_URL}/ login
      java -jar jenkins-cli.jar -s \
        http://${JENKINS_URL}/ \
        build 'movie-db-pipeline-for-dev' -f -v

      NOTE: Job movie-db-pipeline-for-dev is for dev environment you created in previous section.

      If you want to have test and prod environments, you will first need create them using below commands.

      cd ./deployment
      source --env test
      source --env prod

      Then you can build the test and prod environments using similar steps; e.g. build 'movie-db-pipeline-for-test' -f -v.

    Continue to develop apps and rapidly deploy them

    The steps in this section will walk you through the steps to make a simple change to your web app and see those changes reflected on the hom page when you browse to your web app.

    1. Using IntelliJ change the name of the web app in the ~/web-app/src/main/resources/templates/index.html page; for example:

      Welcome to My Cool Movie DB on Azure!!!

    2. Using IntelliJ and Maven, build, deploy and test the web app:

      mvn spring-boot:run
      curl http://localhost:8080/
    3. Using IntelliJ and Git, push changes to the forked repo when you are satisfied with the changes:

      git push origin master
    4. Watch Jenkins building and deploying dev and test releases on the Jenkins Dashboard (triggered by GitHub)

      Go to http://${JENKINS_URL}

    5. Trigger a new build of job movie-db-pipeline-for-dev to deploy your latest changes to dev environment.

    6. Once these steps have been completed, you should see your updated title on the home page of your web app.

    Scale apps

    1. Scale out Internet facing web apps

      az appservice plan update --number-of-workers 6 \
        --name ${EAST_US_WEBAPP_PLAN} \
        --resource-group ${EAST_US_GROUP}
      az appservice plan update --number-of-workers 6 \
        --name ${WEST_EUROPE_WEBAPP_PLAN} \
        --resource-group ${WEST_EUROPE_GROUP}

    Sample Application Summary

    In review, this sample application utilized all of the following design concepts and technologies.

    Web App Design

    • It is a Spring Boot app with an embedded Tomcat server
    • It can run in Linux Containers in Azure App Service
    • App uses Azure Redis Cache and accesses it using Spring Data Redis
    • NOTE: In the future the app secrets will be stored in an Azure Key Vault.

      Data App Design

      • It is a Spring Boot app with an embedded Tomcat server
      • It can run in Kubernetes clusters in Azure Container Service
      • App uses Azure Redis Cache and accesses it using Spring Data Redis
      • App stores and fetches images into and from Azure Storage
      • App stores and reads app data into and from SQL MySQL-as-a-service using Spring JDBC

      NOTE: In the future the app secrets will be stored in an Azure Key Vault.

      Functions Design

      • They are used for independent micro computations
      • They are used for linking two disconnected units in a workflow - re-sizes images uploaded to Azure Storage. They are triggered by an Azure Blob upload action.


      This section will document some of the issues which have been identified when trying to build and deploy this sample application; more will be added as different issues are discovered.

      'Permission Denied' error when creating the data app

      When you are attempting to build the data app, you might encounter the following error:

      [ERROR] Failed to execute goal com.spotify:docker-maven-plugin:0.4.11:build (default-cli) on project data-app: Exception caught: java.util.concurrent.ExecutionException: Permission denied

      This error is caused when your user account does not have permissions to create the necessary socket for Docker; more details are available in Solving Docker permission denied while trying to connect to the Docker daemon socket.

      'Password Complexity' errors when provisioning the sample application

      Some of the Azure services have various password complexity requirements; as a result, you may encounter various errors related to password complexity when you are running the provision scripts. In order to avoid or resolve these issues, you should ensure that the passwords which you choose adhere to standards; for example, at the very least you should choose passwords which have a mixture of uppercase letters, lowercase letters, numbers, and punctuation.


      This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.


      Note: The sample code, scripts, and documentation in this sample application are not supported under any Microsoft standard support program or service. This sample application is provided AS IS without warranty of any kind. Microsoft disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of this sample application remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use this sample application, even if Microsoft has been advised of the possibility of such damages.