Azure DevOps

This story will show the simplicity of deploying an API into the cloud by using best practices like infrastructure as code using ARM (Azure Resource Manager), monitoring (using App Insights), etc. We are going thru the entire build and release lifecycle.

What is Azure DevOps Services?

Azure DevOps Services (formerly VSTS) is a suite of built-in services provided by Azure, these are:

Azure Pipelines : Deploy anything in any language in minutes.

: Deploy anything in any language in minutes. Azure Repos : Private repositories.

: Private repositories. Azure Artifacts : A repository in Azure to upload our artifacts.

: A repository in Azure to upload our artifacts. Azure Boards : It provides agile planning boards like Kanban/Scrum.

: It provides agile planning boards like Kanban/Scrum. Azure Test Plans: Manual & Exploratory tools for testing.

This tutorial will focus on automation so will deploy with Azure pipelines.

Do you have an API and you want to deploy it now in Azure quickly?

Absolutely, Azure Pipelines provide built-in feature which allow engineers to:

Take code from its repository

Provision the required infrastructure via ARM in a Resource group

Pre-built pipelines with Build/Release tasks ready to use

Add monitoring via App Insights

Are you an advanced user and you want to craft your pipeline?

Craft it on your own.

Azure Pipelines

Azure Pipelines from Github

Azure Pipelines allows to deploy anywhere, App Services, Kubernetes, Serverless Functions as well and any other cloud provider like GCP or AWS.

The lifecycle begins with the build phase. During the execution the code will typically go trough:

Build

Run tests

Upload the test results

Publish built artifacts

Once the build is complete we need something to deploy, a tool. Azure Pipelines offer the Release tool which be triggered when a new artifact is published. The release tool can be triggered even from Jenkins or any other tool by using hooks.

The release phase will typically go through:

Checkout the code

Deploy the Infrastructure via ARM

Download the artifacts

Deploy

Pre-requisites

An Azure pay-as-you go account enabled

A repository with the code expected to be deployed

Add unit tests to the code (optionally)

Add a custom Resource group project if you wish to provision additional infrastructure (optionally)

Pay-as-you go subscription

Hands On Lab

Lets create an Azure DevOps Project. Go to the site search and find DevOps Project item:

DevOps Project

Click on Create DevOps project > .NET

DevOps Project Step 1

Choose ASP.NET Core since the application I created is running ASP.NET Core:

DevOps Project step 2

Lets choose the deployment infrastructure. It can be:

Kubernetes for containerized applications

Service Fabric Cluster to deploy it as a Microsoft Container’s technology

Windows Web App (our scenario)

Linux Web App (this is new from 2018)

Web App for Containers (docker images, this is new from 2018)

Virtual Machines

DevOps project step 3

Lets create the project into an existing organization. If there is not Azure DevOps Organization created then go for it and create a new one.

DevOps project step 4

Lets click done to begin the provisioning process.

DevOps project in progress

After a couple of minutes we will find two different resource groups.

DevOps project output

Lets go into VstsRG-hmarcelodelnegro-d4ee where I can find my Project URL

DevOps project organization output

So lets open my DevOps project. We will find the CI/CD pipeline already running provisioning the needed infrastructure in Azure from your repository. On the top menu we can find:

Project homepage : Open VSTS project dashboard page.

: Open VSTS project dashboard page. Repositories : Git/TFVSTS repositories.

: Git/TFVSTS repositories. Build pipelines : Build tools from Azure Pipelines.

: Build tools from Azure Pipelines. Release pipelines : Release tools from Azure Pipelines.

: Release tools from Azure Pipelines. Agile backlogs: Azure Backlogs tool.

Azure pipelines before provisioning

Below we can see the Build/Release tools from Azure pipelines working:

First Build

First build execution

First build execution results

First Release

First release execution

After a few minutes we will find everything provisioned in our Azure Resource group:

Azure Pipelines after provisioning process

Resource group output infrastructure

Build/Release Tasks

So, how does Azure was able to provision and deploy my services and infrastructure? Azure DevOps will create a set of built-in smart steps.

Infrastructure as Code

Azure offers its own provisioning tool named ARM (Azure Resource Manager) which is a bunch of JSON files that Azure understands. By default Azure DevOps performs a basic provisioning but we can add our custom ARM templates in order to architect the desired infrastructure via code.

ARM Gallery: https://azure.microsoft.com/en-us/resources/templates/

If what is in the gallery does not fit our needs we can write this code on our own. I strongly suggest using Visual Studio to do that since it already provides intellisense for this.

Visual Studio ARM templates tools

Learning resources about ARM: I strongly recommend this intro course to ARM from Pluralsight from James Bannan https://www.pluralsight.com/courses/microsoft-azure-resource-manager-mastering

Build Tasks

Azure pipelines will create a build sequence with a common lifecycle. We can edit this as expected to be if needed. The steps we can find below are:

Restore: Restore dependency packages.

Restore dependency packages. Build: Build assemblies.

Build assemblies. Test: Run unit tests and upload results to VSTS.

Run unit tests and upload results to VSTS. Publish: If tests ran successfully it will publish the application output.

If tests ran successfully it will publish the application output. Publish Functional tests: Publish functional tests if they are present.

Publish functional tests if they are present. Copy ARM templates: Move our ARM JSON files to provision the infrastructure in Release phase.

Move our ARM JSON files to provision the infrastructure in Release phase. Publish artifacts: Publish artifacts needed for the Release phase.

Automatic build tasks

Release Tasks

As Azure pipelines made with Build, it will add a Release sequence of pre-defined tasks that can be customized as needed even add more environments and workflows to it.

Azure Deployment: Run ARM templates in order to provision the required infrastructure.

Run ARM templates in order to provision the required infrastructure. Deploy Azure App Service: Deploy the artifacts into the Web App.

Deploy the artifacts into the Web App. Visual Studio Test Platform Installer: Install the test runner for functional tests.

Install the test runner for functional tests. Test assemblies: Run tests.

Automatic release tasks

End results

After the above five minutes process we will have an entire devops lifecycle running in Azure. We can look at the image below and we will find a ton of work already made:

CI/CD pipeline: We can see a repository deployed from master branch, a succeed build and a release into dev environment succeed.

Azure resources: We will find the application URL and the provisioned infrastructure from Release-2.

Repository: The code repository deployed.

Application Insights: Monitoring tool for our deployed application.

Final results

Lets browse it:

Deployed application result

Obviously, this pipeline can be customized entirely to do different things, so we have infinite power there to do what we want.

End Results Video

It was easy, quick and headless. If you liked it, please clap my story.