How we implemented DevOps: infrastructure-as-a-code using Microsoft Azure and Azure Resource Manager
- Transfer
- Tutorial
Hello! The next issue of the article “How We Deployed DevOps” by the Vorlon.JS team. Vorlon.JS is a node.js-based tool that allows web developers a convenient way to remotely test, control and debug a web application, especially on mobile and embedded systems. In its blog on MSDN, the team described the phased implementation of DevOps practices in organizing work on Vorlon.JS and the selection of tools for solving daily tasks. Vorlon.JS is an open source project .Microsoft offers a large number of tools that can be used to implement DevOps practices, and we talk about some of them in this series.
Cycle content:
- Project Planning and Management with Visual Studio Team Services
- Continuous integration with GitHub and Visual Studio Team Services build system
- ASA framework with Microsoft Azure and Azure Resource Manager
- Release Management in Visual Studio Team Services
- Testing in a production environment with Microsoft Azure App Service and Web Apps
What is Infrastructure-as-a-Code?
Infrastructure-as-a-code is an opportunity to improve the methods for creating and managing application deployment environments at all stages of its life cycle, from development to production. It allows you to describe (declare) the final desired state of the environment.
Suppose you are deploying an application that must run on a web farm of 4 servers.
The application stores and retrieves data from an Azure SQL database and optimizes load times using the Redis Cache service. The “Infrastructure-as-a-code” approach allows you to write a script that creates an entire environment in an idempotent way (that is, with an identical result, even when executed repeatedly).
Another important feature: describing the infrastructure with a script, you can control its versions. Thus, the source code repository allows us to improve the way the developers interact with the operating team, which means it becomes their common tool. By managing versions of infrastructure scripts in the source code repository, you can restore an arbitrary version of the application and its environment at any time, for example, to fix the error.
Infrastructure-as-a-code and Microsoft Azure
Using the infrastructure as code approach in Microsoft Azure is easy: use the Azure Resource Manager and deployment templates.
What is Azure Resource Manager and resource groups?
Azure Resource Manager (ARM), as the name suggests, is a management service for all resources created in Azure. In the first version of Microsoft Azure, ARM was absent, and when creating services for the application, developers faced a problem: all services were created as single elements, without any cross-references or dependencies. Managing a multi-resource application was not easy.
ARM works with resource providers. Each resource provider (for example, Microsoft.Compute, Microsoft.Storage, Microsoft.Network and others) is used to create a basic resource, and ARM manages all providers.
Not all, but many services have been ported to ARM. Some of them are duplicated. For example, the Azure portal allows you to create virtual machines using a classic provider or use a new one that works with ARM. To create a new infrastructure, it is recommended to use ARM providers, if available.
When using ARM, all created resources will be placed in the resource group. This entity is intended for grouping resources in Microsoft Azure. Resource groups offer many new convenient features, such as using tags or getting billing data for the entire application, rather than for individual services.
When deploying a new resource using ARM, you must first create a resource group to which the new resource will be assigned, or use the existing one. Of course, resources from one resource group can be deployed in different data centers.
Another advantage of ARM compared to older providers: you can describe a group of resources using JSO files and ARM will deploy resources not sequentially, but in parallel, that is, much faster.
The Deployment folder of the Vorlon.JS project contains a number of scripts that are used to deploy the infrastructure of development, testing, and production environments. In fact, we used the same script (azuredeploy.json) for development and testing environments with different parameter files, which allowed us to configure each resource for each environment: For the production environment, different deployment templates are used, since we use the Azure functionality in it Web Apss (deployment slots) that are not needed in two other environments. In addition, the Deployment folder contains several PowerShell scripts that are used in the release management process. We will talk about this in a future post. For more information on Azure Resource Manager and resource groups, see the documentation for
link .
Get started with Azure Resource Manager and resource groups
Perhaps Vorlon.JS project ARM templates are not the easiest to read material, but I want you to know that working with ARM is very simple.
Firstly, there are many templates in this GitHub repository that let you get started quickly. You can read them, change them or even try to deploy them - for this, click the Deploy to Azure button in the readme section of the desired template. You will be taken to the Azure portal, where you only need to enter the parameters and click OK to start the deployment. Visual Studio and the latest version of the Microsoft Azure SDK / Tools contain a user interface for working with Azure Resource Manager templates. First create an Azure Resource Group project in Visual Studio:
The wizard prompts help you create a resource group. For example, you can create a resource group consisting of a web application and an Azure SQL database: Visual Studio will create the following solution: The Scripts folder contains a PowerShell script that can be used to deploy a resource group to Azure. The Templates folder contains two JSON files: an Azure Resource Manager template with a description of the infrastructure and a parameter file with the parameters necessary for the script. You can create multiple copies of the second file for different environments. The Tools folder contains the executable file AzCopy.exe. This is an Azure version of the copy robot that allows you to upload content (such as an application package or database backup) to Azure during deployment.
When you open the ARM template, the JSON Outline window will appear on the side: The window is used to navigate the template: select a resource from the list and its presentation will be highlighted in the JSON file. In addition, in this window you can add resources to the template. Right-click on the resource node and select Add New Resource: The wizard opens again, and you can add any of the many resources to your template: As you can see, if the created resource depends on other resources, the system will offer to create them too. The prepared template can be deployed to Microsoft Azure. Right-click on the template and select New Deployment: Enter your credentials in Azure and the name of the resource group and select the subscription within which the group will be created.
There is another way - to open and run the PowerShell script from the Scripts folder: In Vorlon.JS we set the templates that will be used to automatically prepare the release of the application using Visual Stusio Team Services. These templates can be viewed directly on GitHub: https://github.com/MicrosoftDX/Vorlonjs/tree/dev/DeploymentTools Storing the infrastructure as a code template with the application source code is a good practice: you can manage versions of the application at the same time as its infrastructure . Imagine, for example, that a user reports an error in the old version. If you have not only the source code, but also the infrastructure templates, then you can extract the error version, restore the environment in a few minutes, and start debugging.
Now you are familiar with the basics of using the Infrastructure-as-Code approach in Microsoft Azure.
In the next article in this series, you'll learn how we use the Azure Resource Manager and Release Management templates in Visual Studio Team Services to automatically prepare environments and deploy an application right after the build is successfully completed.
Stay in touch!
About Authors
Julien Corioland is a technology evangelist at Microsoft, France. The main area of work is the Microsoft Azure application platform. He helps developers create cloud applications, and is also part of the Vorlon.JS tool development group, in which he helps implement DevOps practices.
We are pleased to announce that the developers of the Vorlon.JS project - Julien Corioland and Ettiene Margraff will be speakers at the DevCon 2016 conference, where they will exclusively talk about their experience in implementing live practices and provide an opportunity to build these processes on their own. hands.
If you have questions about this series of publications or about the DevOps methodology, you can contact the author directly via Twitter:twitter.com/jcorioland
useful links
- Visual Studio 2015, Visual Studio Team Services, Visual Studio Code: Free Developer Offerings
- Additional and free tools and services in Visual Studio Dev Essentials
- Laboratory work on the development, testing and lifecycle management of software for Visual Studio 2015