Deploy the Remote Monitoring solution accelerator locally - Visual Studio Code

This article shows you how to deploy the Remote Monitoring solution accelerator to your local machine for testing and development. You learn how to run the microservices in Visual Studio Code. A local microservices deployment uses the following cloud services: IoT Hub, Cosmos DB, Azure Streaming Analytics, and Azure Time Series Insights.

Prerequisites

To deploy the Azure services used by the Remote Monitoring solution accelerator, you need an active Azure subscription.

If you don’t have an account, you can create a free trial account in just a couple of minutes. For details, see Azure Free Trial.

Machine setup

To complete the local deployment, you need the following tools installed on your local development machine:

Note

Visual Studio Code is available for Windows, Mac and Ubuntu.

Download the source code

The Remote Monitoring source code repositories include the source code and the Docker configuration files you need to run the microservices Docker images.

To clone and create a local version of the repository, use your command-line environment to navigate to a suitable folder on your local machine. Then run one of the following sets of commands to clone either the .NET repository:

To download the latest version of the .NET microservice implementations, run:

git clone --recurse-submodules https://github.com/Azure/azure-iot-pcs-remote-monitoring-dotnet.git

# To retrieve the latest submodules, run the following command:

cd azure-iot-pcs-remote-monitoring-dotnet
git submodule foreach git pull origin master

Note

These commands download the source code for all the microservices in addition to the scripts you use to run the microservices locally. Although you don't need the source code to run the microservices in Docker, the source code is useful if you later plan to modify the solution accelerator and test your changes locally.

Deploy the Azure services

Although this article shows you how to run the microservices locally, they depend on Azure services running in the cloud. Use the following script to deploy the Azure services. The following script examples assume you're using the .NET repository on a Windows machine. If you're working in another environment, adjust the paths, file extensions, and path separators appropriately.

Create new Azure resources

If you've not yet created the required Azure resources, follow these steps:

  1. In your command-line environment, navigate to the \services\scripts\local\launch folder in your cloned copy of the repository.

  2. Run the following commands to install the pcs CLI tool and sign in to your Azure account:

    npm install -g iot-solutions
    pcs login
    
  3. Run the start.cmd script. The script prompts you for the following information:

    • A solution name.

    • The Azure subscription to use.

    • The location of the Azure datacenter to use.

      The script creates resource group in Azure with your solution name. This resource group contains the Azure resources the solution accelerator uses. You can delete this resource group once you no longer need the corresponding resources.

      The script also adds a set of environment variables with a prefix PCS to your local machine. These environment variables provide the details for Remote Monitoring to be able to read from an Azure Key Vault resource. This Key Vault resource is where Remote Monitoring will read its configuration values from.

      Tip

      When the script completes, it also saves the environment variables to a file called <your home folder>\.pcs\<solution name>.env. You can use them for future solution accelerator deployments. Note that any environment variables set on your local machine override values in the services\scripts\local\.env file when you run docker-compose.

  4. Exit from your command-line environment.

Use existing Azure resources

If you've already created the required Azure resources, create the corresponding environment variables on your local machine. Set the environment variables for the following:

  • PCS_KEYVAULT_NAME - Name of the Azure Key Vault resource
  • PCS_AAD_APPID - The AAD application ID
  • PCS_AAD_APPSECRET - The AAD application secret

Configuration values will be read from this Azure Key Vault resource. These environment variables may be saved in the <your home folder>\.pcs\<solution name>.env file from the deployment. Note that environment variables set on your local machine override values in the services\scripts\local\.env file when you run docker-compose.

Some of the configuration needed by the microservice is stored in an instance of Key Vault that was created on initial deployment. The corresponding variables in keyvault should be modified as needed.

Run the microservices

In this section, you run the Remote Monitoring microservices. You run the web UI natively, the Device Simulation service in Docker, and the microservices in Visual Studio Code.

Build the code

Navigate to azure-iot-pcs-remote-monitoring-dotnet\services in the command prompt and run the following commands to build the code.

dotnet restore
dotnet build -c Release

Deploy all other microservices on local machine

The following steps show you how to run the Remote Monitoring microservices in Visual Studio Code:

  1. Launch Visual Studio Code.
  2. In VS Code, open the azure-iot-pcs-remote-monitoring-dotnet folder.
  3. Create a new folder called .vscode in the azure-iot-pcs-remote-monitoring-dotnet folder.
  4. Copy the files launch.json and tasks.json from services\scripts\local\launch\idesettings\vscode to the .vscode folder you just created.
  5. Open the Debug panel in VS Code and run the Run All microservices configuration. This configuration runs the device simulation microservice in Docker and runs the other microservices in the debugger.

The output from running Run All microsoervices in the Debug Console looks like the following:

Deploy-Local-Microservices

Run the web UI

In this step, you start the web UI. Navigate to azure-iot-pcs-remote-monitoring-dotnet\webui folder in your local copy and run the following commands:

npm install
npm start

When the start is complete, your browser displays the page http://localhost:3000/dashboard. The errors on this page are expected. To view the application without errors, complete the following step.

Configure and run NGINX

Set up a reverse proxy server to link the web application and microservices running on your local machine:

  • Copy the nginx.conf file from the webui\scripts\localhost folder to the nginx\conf install directory.
  • Run nginx.

For more information about running nginx, see nginx for Windows.

Connect to the dashboard

To access the Remote Monitoring solution dashboard, navigate to http://localhost:9000 in your browser.

Clean up

To avoid unnecessary charges, when you've finished your testing remove the cloud services from your Azure subscription. To remove the services, navigate to the Azure portal and delete the resource group that the start.cmd script created.

You can also delete the local copy of the Remote Monitoring repository created when you cloned the source code from GitHub.

Next steps

Now that you've deployed the Remote Monitoring solution, the next step is to explore the capabilities of the solution dashboard.