Introduction to DevOps and Azure DevOps
DevOps is a set of practices that combines software development (Dev) and IT operations (Ops) to shorten the systems development life cycle and provide continuous delivery with high software quality. Azure DevOps is Microsoft's cloud-based DevOps service, offering a suite of tools to plan, build, test, and deploy applications. This module will guide you through leveraging Azure DevOps to implement these critical practices.
Key Concepts
- Continuous Integration (CI)
- Continuous Delivery/Deployment (CD)
- Infrastructure as Code (IaC)
- Monitoring and Feedback
- Collaboration and Communication
Continuous Integration and Continuous Delivery (CI/CD) with Azure Pipelines
Azure Pipelines is a cloud service that you can use to automatically build, test, and deploy your code to any cloud or on-premises. It supports any language, platform, and cloud. We’ll explore how to set up a CI/CD pipeline for an Azure application.
Setting up a CI Pipeline
A CI pipeline typically involves the following steps:
- Code Commit: Developer commits code to a repository (e.g., Azure Repos, GitHub).
- Build: A CI server (Azure Pipelines) automatically triggers a build. This includes compiling code, running unit tests, and creating build artifacts.
- Artifacts: The build artifacts are published to a package management system (e.g., Azure Artifacts).
- Notification: Teams are notified of build status.
Setting up a CD Pipeline
A CD pipeline extends CI by automating the release of your application:
- Deployment: Upon successful CI, the CD pipeline automatically deploys the artifacts to a staging environment.
- Automated Tests: Further tests (e.g., integration tests, UI tests) are run in the staging environment.
- Approval Gates: Manual approvals can be configured before deployment to production.
- Production Deployment: Once approved, the application is deployed to production.
Example: YAML Pipeline Configuration
Here's a simplified example of a azure-pipelines.yml file for a .NET application:
trigger:
- main
pool:
vmImage: 'ubuntu-latest'
steps:
- task: UseDotNet@2
inputs:
version: '6.x'
packageType: 'sdk'
- task: DotNetCoreCLI@2
displayName: 'Restore dependencies'
inputs:
command: 'restore'
projects: '**/*.csproj'
- task: DotNetCoreCLI@2
displayName: 'Build project'
inputs:
command: 'build'
projects: '**/*.csproj'
arguments: '--configuration Release'
- task: DotNetCoreCLI@2
displayName: 'Run unit tests'
inputs:
command: 'test'
projects: '**/*[Tt]ests/*.csproj'
arguments: '--configuration Release'
- task: DotNetCoreCLI@2
displayName: 'Publish project'
inputs:
command: 'publish'
publishWebProjects: true
arguments: '--configuration Release --output $(Build.ArtifactStagingDirectory)'
zipAfterPublish: true
- task: PublishBuildArtifacts@1
displayName: 'Publish Artifact'
inputs:
pathToPublish: '$(Build.ArtifactStagingDirectory)'
artifactName: 'drop'
Infrastructure as Code (IaC) with Azure Resource Manager (ARM) and Terraform
IaC allows you to manage and provision your infrastructure through machine-readable definition files, rather than physical hardware configuration or interactive configuration tools. Azure DevOps integrates seamlessly with IaC tools like ARM templates and Terraform.
Using ARM Templates
ARM templates are JSON files that declare the infrastructure you want to deploy for your Azure solution. You can deploy these templates using Azure Pipelines.
Using Terraform
Terraform is an open-source IaC tool that enables you to safely and efficiently build, change, and version your cloud infrastructure. Azure DevOps provides tasks to run Terraform commands.
Try It: Deploying a Web App
Let's simulate deploying a simple Azure Web App using a pre-configured pipeline. Click the button below to initiate a dummy deployment process.
Monitoring and Feedback
Effective DevOps relies on robust monitoring and feedback loops. Azure Monitor and Application Insights provide comprehensive tools to collect, analyze, and act on telemetry from your cloud and on-premises environments.
Azure Monitor
Collects and analyzes telemetry data. It helps you understand how your applications and infrastructure are performing and proactively identifies issues.
Application Insights
An extensible Application Performance Management (APM) service for developers and DevOps professionals. Use it to monitor your live application. It automatically detects performance anomalies and includes powerful analytics tools to help you diagnose issues and understand what users of your app are doing.
Module Summary and Next Steps
In this module, you've learned the foundational principles of DevOps and how to implement them using Azure DevOps services like Azure Pipelines, Azure Repos, and Azure Artifacts. You've also touched upon Infrastructure as Code and the importance of monitoring. The next steps in your journey as an Azure Developer should focus on practical application of these concepts in your projects.