THE CONCEPT:
High Overview
Github Link for Project:
Azure App Service
- We have to create three Azure App services for three different Environments Dev, QA, and Production.
Create Azure App Service first where we will be going to deploy our dotnet Project.
For Configurations refer to the below Screenshots.
Now, the Resource has been created.
In the end, we will have three app services for three different environments dev, QA, and Production.
Azure Project & Repo
2. After Creating the Azure App services. Go to the devops.azure.com Where we have to create the Organization first. After Creating the Organization, we are going to create the project as you can see below.
The project must be Private.
The Project has been created.
3. Now as per the flow of the Azure Pipeline, We are getting the source code from Azure Repo itself.
Now, Go to the Repos and follow the below steps:
- Copy the repository link.
- Generate the credentials for the repository to push the changes on the repository.
- Clone the repository on your terminal.
4. Here, We have cloned the repository on our terminal and added our project to the cloned repository, and pushed it to the repository.
I have used a demo project, you can also use it.
5. Here, We have uploaded the Code successfully.
Azure Build
6. Now, We will have to build our DotNet Project.
- Click on “Pipelines”
- Choose “Azure Repos Git”
- Select the Repository which pushed to the Azure Repos recently.
7. The buildspec file is the most important file to build any project where we write the process that how the project will be built and where to push the artifact as well.
You can refer to my buildspec file. Also, Azure has a good
feature to create the buildspec file without making any major
complications as compared to AWS CodeBuild.
8. Now, run the build and watch the live logs where you will see the process of build and, in the end, the artifact must be created and stored in the given directory.
The build has been successful and you can validate the artifact by clicking on “artifact”.
Azure Release
9. Now, We are going to deploy our code to the Azure App Service which is easy as compared to Azure VM.
- Click on “Create release pipeline”.
- Select a template as given below.
- To get the artifact, click on “Add an artifact” and select the “Source Alias” and click on add.
- Now, you have to choose the app type and you can choose anything from Windows or Linux.
- Add the app service which you have created.
10. Before going to the next step we will get one error while doing the deployment where we have to raise the request to run the Azure Pipeline. So If we get an error like this “No hosted parallelism has been purchased or granted” in the release logs. So. follow the below link and solve the issue.
How to resolve “No hosted parallelism has been purchased or granted”
11. To start the deployment, Click on “create a release”.
12. If you want to automate the deployment of a specific environment then, click on your stage name if the border turns blue then, it will automate else you can choose the Stage name from the drop-down menu and click on create to start the deployment.
13. As we can see below, the deployment for the dev environment has succeeded.
14. But to check whether the deployment of the dev environment has succeeded or not use the “default domain” link on your browser.
The deployment has succeeded for the Dev environment.
15. Now, We have to deploy our code in a QA environment where all things will remain the same as in the dev environment. And get the Azure App Service for QA environment “default domain” link and check the deployment.
The deployment has succeeded for the QA environment.
If the deployment is for dev and QA environments then, the downtime will not be a problem but in the Production environment, there should be no downtime.
So to get rid of this downtime, we will use the Deployment slot feature which is available in the Azure app service which will help to minimize the probability of downtime.
To get a better understanding of the Deployment Slot feature:
Azure Functions deployment slots allow your function app to run different instances called “slots”*. Slots are different environments exposed via a publicly available endpoint. One app instance is always mapped to the production slot, and you can swap instances assigned to a slot on demand.*
16. Go to the Azure App Service for Production environment -> Deployment slots, and add the slot.
Here, I’ve created a new slot named staging.
So, when the deployment of Production with the new version of the code is in progress then the application will not have downtime because the staging slot will be handling the previous version of the code.
17. Now, We will create the deployment for the Production environment.
Choose the App service for the Production environment.
In a Production environment, We don’t want to do Continuous deployment without Human Intervention. So before starting the Code deployment for a Production environment, the authorized user would have to approve the request for the Deployment.
Add “**Agentless Job” by clicking on three dots in the line of “Production Deployment Process”
Now, We have to create two jobs, first will be normal where we will deploy our code on the Production slot in the Production environment.
Don’t forget to check the “Deploy to Slot or App Service Environment” and add the first slot which created automatically.
Now, We need to add the Swap slot by selecting the template name “Azure App Service manage”*.*
Add the slot we created in the Production App Service named Staging slot.
The Final Pipeline will look like this for three different Environments.
Let’s run the entire pipeline for all environments.
As you can see the pipeline has succeeded.
Now, check the final output of all the different environments.
Development Environment
QA Environment
Production Environment
Stackademic
Thank you for reading until the end. Before you go:
- Please consider clapping and following the writer! 👏
- Follow us on Twitter(X), LinkedIn, and YouTube.
- Visit Stackademic.com to find out more about how we are democratizing free programming education around the world.