Code Monkey home page Code Monkey logo

nodejs-aks-cosmosdb-po-api's Introduction

Build and deploy a Nodejs Microservice using Azure DevOps Projects

This project describes the steps for building and deploying a containerized Node.js microservice using Azure DevOps Projects. The microservice exposes a simple REST API for manipulating (CRUD) Purchase Orders and the purchase order documents (JSON messages) are persisted in a Azure CosmosDB No-SQL database.

With Azure DevOps Projects, there are two options for building and deploying a containerized application

  1. Azure App Service on Linux. Refer to Section [A] in order to build and deploy this application to Web App for Containers on Azure App Service.
  2. Azure Kubernetes Service. Refer to Section [B] in order to build and deploy this application to AKS.

Both options use DevOps CI/CD workflows in Azure DevOps to build and deploy the containerized application. The CI/CD workflows are automatically created by Azure DevOps Project. We will examine both of these options for deploying our containerized application on Azure.

PREREQUISITES

  1. This application uses an Azure CosmosDB instance to persist the purchase orders. Using the Azure Portal, create a new instance of Azure CosmosDB. Click on the 'Keys' blade and take a note (save) of the values for URI and PRIMARY KEY properties. See screenshot below.

    alt tag

  2. Fork this GitHub repository to your GitHub account. After logging in to your GitHub account via a browser, click on Fork in the upper right hand corner to get a copy of this project added to your GitHub account.

  3. In the file config.js, specify the correct values for config.host and config.authkey properties. Substitute the value of URI in config.host and PRIMARY KEY in config.authkey. Commit your changes to your forked GitHub repository.

A] Deploy to Azure App Service on Linux

  1. Login to your account on Azure Portal, click on All services and search for DevOps Projects service. Add this service to your navigational pane by clicking on the star beside the service. Next, click on DevOps Projects to open the blade and click on Add to start the DevOps Project wizard. See screenshot below.

    alt tag

    In the next page, select Build your own code as shown in the screenshot below. Then click Next.

    alt tag

    On the Code Repository page, select GitHub and this repository which you forked earlier. You may be prompted to login to your GitHub account with your credentials. See screenshot below. Click Next.

    alt tag

    On the next page, click on YES for Is app Dockerized as shown below. Click on Next.

    alt tag

    On the Application/Framework page, select Web App for Containers as shown below.

    alt tag

    Leave the value of Dockerfile path as is and specify node app.js as the value for Startup Command. Then click OK and Next.

    alt tag

    On the Service page, create a new or use an existing Azure DevOps organization. Then give the DevOps project a meaningful name. Also, select an Azure Subscription, give a name for the Web app and specify the Location where the Azure resources will be deployed. See screenshot below. Make a note of the Web app name.

    alt tag

    Click on Done. The DevOps Project wizard shall execute the following steps

    • Provision build (Continuous Integration) and release (Continuous Deployment) pipelines for the application in Azure DevOps and run the pipelines. The release pipeline will build an application container image and push the image to a new Azure Container Registry instance.
    • Provision and deploy the containerized application to a Web App for Containers Service on Linux. The Web App Service will be provisioned in a App Service Plan ([Web app name]-hostingPlan). Review the App Service and App Service Plan details in the Azure Portal.
  2. Examine the deployed build and release (CI/CD) pipelines in your Azure DevOps account. Review Web App Service (Web app name) resources in Azure using the portal (or CLI). Also, verify that the application container image got built and pushed to a new Azure Container Registry (ACR) instance ([Web app name]xxxx).

  3. The microservice application can now be accessed via a browser at https://[Web app name].azurewebsites.net.

  4. Use the test scripts in the test-scripts folder of this project to fetch, add, update & delete purchase orders. Update the REST API URLs in the scripts to point to your App Service end-point. The test scripts invoke the REST API's exposed by this Nodejs application. Invoke the test-scripts/insert-orders.sh script from a terminal window (or a browser based REST Client such as Postman or ARC) to create purchase orders in the backend Azure CosmosDB document repository. Verify the purchase order documents got created/updated/deleted in the Azure CosmosDB database via the Azure portal.

  5. After you are done testing the application, you can delete the App Service via the Azure portal. This will delete the App Service and the App Service Plan in Azure. You will need to manually delete the Azure Container Registry (ACR) and DevOps Project instances in Azure. Deleting the Azure DevOps Project will also delete corresponding resources (CI and CD pipelines, work items etc) in Azure DevOps.

B] Deploy to Azure Kubernetes Service

  1. Login to your account on Azure Portal, click on All services and search for DevOps Projects service. Add this service to your navigational pane by clicking on the star beside the service. Next, click on DevOps Projects to open the blade and click on Add to start the DevOps Project wizard. See screenshot below.

    alt tag

    In the next page, select Build your own code as shown in the screenshot below. Then click Next.

    alt tag

    On the Code Repository page, select GitHub and this repository which you forked earlier. You may be prompted to login to your GitHub account with your credentials. See screenshot below. Click Next.

    alt tag

    On the next page, click on YES for Is app Dockerized as shown below. Click on Next.

    alt tag

    On the Application/Framework page, select Kubernetes Service as shown below.

    alt tag

    Leave the value of Dockerfile path as is and specify value nodejs-cosmosdb-po-service for Path to Chart folder. Then click Ok and Next.

    alt tag

    On the Service page, create a new or use an existing Azure DevOps organization. (You should already have a Azure DevOps Account!). Give the DevOps project a meaningful name and select an Azure Subscription. Leave the Cluster Name field as is, it should default to the value of the project name. Specify the Location where the Azure resources will be deployed. Make a note of the Project name. Then click on Additional Settings as shown in the screen shot below.

    alt tag

    Change the Node count to 1 and Kubernetes Version to 1.11.8. You can either leave the other field values as is or change the default values if needed. Then click OK. See screenshot below.

    alt tag

    Click on Done. The DevOps Projects wizard shall execute the following steps

    • Provision an Azure Container Registry (ACR) instance (nodejscosmosdbxxxx).
    • Provision an Azure Kubernetes Service (AKS) instance on Azure (nodejscosmosdb).
    • Provision build (Continuous Integration) and release (Continuous Deployment) pipelines for the application in Azure DevOps Services and run the pipelines. The build pipeline will build an application container image and push the image to a new Azure Container Registry (ACR) instance. Upon successful execution of the build pipeline, the release pipeline will be triggered. The release pipeline will use Helm Package Manager to deploy the application to AKS. Helm charts provided in this repository will be used to deploy the containerized application to AKS.

    It will take approximately 15-20 minutes (maybe more) to provision all the resources in Azure DevOps and AKS. So be patient and take a coffee break, perhaps treat yourself to a pastry!

  2. Wait for the Notification panel in Azure portal to confirm that the deployment of all resources succeeded. At this point, you want to take some time to examine all the resources which were provisioned in

    • Azure : DevOps Project, AKS, ACR and Load Balancer
    • Azure DevOps : Build and Release pipelines
  3. Open the Load Balancer blade in Azure Portal to find the Public IP address of the application service endpoint. See Screenshot below.

    alt tag

    In the overview pane, click on 2 public IP addresses.

    alt tag

    In the Frontend IP configuration pane, you should see two IP addresses. Use either one of the IP addresses to access the purchase order service REST endpoint eg., http://[IP address]/orders

  4. Use the test scripts in the test-scripts folder of this project to fetch, add, update & delete purchase orders. Update the REST API URLs in the scripts to point to your App Service end-point. The test scripts invoke the REST API's exposed by this Nodejs application. Invoke the test-scripts/insert-orders.sh script from a terminal window (or a browser based REST Client such as Postman or ARC) to create purchase orders in the backend Azure CosmosDB document repository. Verify the purchase order documents got created/updated/deleted in the Azure CosmosDB database via the Azure portal.

  5. After you are done testing the application, you can use the Azure portal to delete the Resource Group in which all the resources were deployed. This will delete all resources provisioned in Azure and Azure DevOps Services (Project).

    alt tag

Congrats!! You have successfully explored two options provided by Azure DevOps Project PaaS service for automating the build and deployment of a containerized Nodejs application on Azure.

To sum it up, Azure DevOps Projects allows application development teams to easily and quickly adopt DevOps (CI and CD) and deploy containerized applications written in a variety of programming languages on Azure.

nodejs-aks-cosmosdb-po-api's People

Contributors

ganrad avatar vamsi338 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.