Free DevOps end-to-end automation – part 3

Hello and welcome to Part 3 of our optimization. 
 
What we have built so far: 
 
 
 
In Part 1 https://dev.bg/digest/vsg-bulgaria-devops-automation-dc03/ : 
a. We created frontend and backend project 
b. We automated build processes and created artifacts for distribution 
c. We created a test project and automated the testing of any code change 
d. We automated publishing to project servers at release 
e. We automated scanning for vulnerabilities in projects 
 
In Part 2 https://dev.bg/digest/vsg-bulgaria-devops-automation-part-2-dc03/  
a. We added a version of our projects in the build processes 
b. We created docker images of our projects and published them in docker registers 
c. We automated release processes and generated a file with all changes from version to version 
 
In Part 3 
a. We will create a status project that monitors every second whether our applications are working by adding HealthChecks 
b. We will create docker-compose to distribute our entire infrastructure 
c. We will add Application Insights in Azure for full monitoring of our applications 
In this article, we'll look at how to implement full DevOps automation for .NET applications deployed in Azure. We will focus on four key steps that will increase the sustainability, monitoring and effectiveness of our applications. 
 
Step 1 – Create a Status Project with HealthChecks 
In this step on our path to free DevOps automation, we will focus on creating a status project that will allow us to monitor the performance of our applications in real time. Using .NET for programming, we will integrate HealthChecks, which will provide us with valuable information about the health of our systems. 
The objective of this status project is to provide continuous feedback on the status of all application components, thus guaranteeing a high level of reliability and accessibility. 
 
Integration of HealthChecks: 
Add HealthChecks to each project: 
• We use the AspNetCore.HealthChecks.UI.Client package for each individual project in our infrastructure. 
• This will allow us to monitor the main parameters of each application such as response time, resource status and other important metrics. 
To integrate Health Checks, we need to modify the Startup.cs file in our .NET project. 
 
 
With this, if we open our RIA project we will see: 
 
 
Create the main 'Status Project': 
• For the main status project, we integrate the AspNetCore.HealthChecks.UI package. 
• This project will aggregate and visualise the data from all HealthChecks performed in the different applications. 
• It will provide a centralised interface where we can see aggregated information on the status of our entire infrastructure. 
For the "Status Project" we open Visual Studio and create a new "ASP.NET Core Web App (Razor Pages)", then in the Startup.cs file we add: 
 
 
And then we use with: 
 
 
This code will create endpoint /health, which returns the health status of the application, and the UI at /hc-ui, where detailed information can be viewed. 
 
Configuration and setup: 
• We configure HealthChecks to send data to the status project. 
• We adjust the periodicity of inspections so that we receive information in real time. 
 
Testing and validation: 
• After completing the settings, we conduct tests to make sure that the status project correctly reflects the status of the applications. 
• We check that all components of the infrastructure are properly integrated and that the data is visualized correctly. 
Creating an effective status project with HealthChecks is a key step in achieving our DevOps automation goals. This step not only facilitates application monitoring and management but also improves our system's reliability and accessibility. 
The next steps will continue to expand our automation strategy to include more tools and practices for optimizing DevOps processes. 
 
 
Step 2: Create a Docker Compose to distribute the infrastructure 
The second step in the DevOps automation process involves using Docker Compose to distribute your infrastructure. Docker Compose makes it easy to define and launch multi-container Docker applications by allowing you to use a YAML file to configure services, networks, and volumes. 
 
Create a Dockerfile for each microservice: 
For each application in your infrastructure, create a Dockerfile that describes how to create a Docker image for the application. This includes copying the source code, installing the dependencies, and setting the runtime. 
 
For this purpose, Visual Studio has an integration that easily does all this for us: 
 
 
Configure Docker Compose file: 
Create a docker-compose.yml file at the root of the project. This file should define the services (each microservice or component), their configurations, dependencies, and how they interact with each other. 
 
Sample structure of docker-compose.yml: 
 
 
Then we press the right button of the "docker-compose" project, select "Set as startup" and launch our entire infrastructure of applications in docker: 
 
 
When you're done, you can migrate and distribute your infrastructure to Azure using Azure Container Instances or Azure Kubernetes Service to manage cloud containers. 
 
The creation of a Docker Compose file greatly facilitates the distribution and management of multiple containers, providing flexibility and efficiency in the development and distribution of complex applications. Combined with Azure, this provides a powerful platform for creating, distributing and managing your microservices and applications. 
 
Step 3: Add Application Insights to Azure for full application monitoring 
The third step in our DevOps automation strategy involves integrating Application Insights from Azure, which provides powerful tools for monitoring and analyzing your applications. Application Insights is an application performance management service that allows you to live monitor the functioning and usage of your application. 
 
Creating an Application Insights resource: 
First of all, you need to create an Application Insights resource in the Azure portal. This will provide you with a tooling key that you will use to configure your applications. 
 
Adding Application Insights to the .NET project: 
In your .NET project, add the NuGet package Microsoft.ApplicationInsights.AspNetCore. Then, integrate Application Insights into your application using the tooling key. 
 
Example of adding in Startup.cs: 
 
 
Once Application Insights is integrated and configured, you can use the Azure portal to analyze the collected data. This includes reviewing performance, troubleshooting, and analyzing traffic and user behavior. 
 
 
Application Insights integration provides deep insights for your applications and makes it easy to detect problems, optimize performance, and understand user behavior. This is a key component in the cloud-based DevOps automation strategy that provides important data to manage and improve your applications. 
 
Conclusion: Mastering DevOps automation with .NET and Azure 
In this article, we explored the key steps to implement full DevOps automation for .NET applications in Azure. From creating status projects with Health Checks, through building containerized infrastructures with Docker Compose, to integrating Application Insights for monitoring and analysis,. Each step contributes to the increased sustainability, efficiency and visibility of your applications. 
 
With a focus on .NET and Azure, we can see how Microsoft technologies provide a comprehensive and scalable platform for DevOps practices. The benefits of this integration are numerousfrom easy setup and management, to the possibility of rapid distribution and reliable monitoring. 
Besides the technical aspects, success in the DevOps culture also requires a shift in thinking and collaboration between developers, operational teams, and business stakeholders. Such a holistic approach to automation in DevOps not only improves technical efficiency, but also leads to faster delivery of value for customers and more sustainable business growth. 
 
We hope this article has provided you with valuable insights and guidance on your DevOps path with .NET and Azure. Ultimately, the most important thing is to continue experimenting, learning, and optimizing your processes to meet the ever-changing demands of modern software development!
Previous
Next