I would like to talk about how to deploy ASP.NET Core CRUD API by using the Azure CI/CD pipeline. So First I plan to show, how to deploy ASP.NET Core Web API by using the Azure CI/CD pipeline.
Before all of this work, you should have installed Visual Studio 2022 Community with ASP.NET Core environment, install the Postman, create GitHub Account, Set up Git and Free Azure Account.
In this article, I will tell you,
- Create ASP.NET Core Web API
- What is CI/CD
- Deploy the API to AZURE
Create ASP.NET Core Web API
Open the visual studio and create a new project and select ASP.NET CORE Web Application, add the project name and then select “API” as the web application type, then create this application.
Now we created our ASP.NET Web API application and got the directory structure with these pre-created files for the Web API template. So you can see the directory structure below the picture and There is a pre-created controller called WeatherForeacastController and one model class called WeatherForecast.
Now we can check it by use postman in the localhost server because it has created pre-created files. So you will get your API result as below picture.
Before we deploy the API, we have to push these project files into GitHub. Because I use existing projects that trying to get it from GitHub to create the Azure CI/CD pipeline to deploy it.
Now we have to create a repository for this and push our commits to GitHub. Then we can use it for deploying the Web API to Azure.
Now we have to configure the Azure CI/CD pipeline to deploy the ASP.NET Core Web API project.
What is CI/CD?
Following definition from the InfoWorld.
Continuous integration (CI) and continuous delivery (CD) embody a culture, set of operating principles, and collection of practices that enable application development teams to deliver code changes more frequently and reliably. The implementation is also known as the CI/CD pipeline.
CI/CD is one of the best practices for DevOps teams to implement. It is also an agile methodology best practice, as it enables software development teams to focus on meeting business requirements, code quality, and security because deployment steps are automated.
CI/CD helps teams to be more productive when shipping software with quality built in.
Deploy ASP.NET Core Web API to Azure.
let’s start to deploy our created web API by using the Azure CI/CD Pipeline. To deploy our Web API application to Azure, first, we need an Azure account, if you don’t have an Azure account, you have to create a free Azure account first.
After creating your azure account, first, we have to go to the Azure portal.
Then you have select DevOps starter. We create CI/CD pipeline by using DevOps Starter in Azure DevOps.
You can see the “Add” button after you go to Azure DevOps Starter. You have to click it to start to create or add our existing project to Azure.
Then you can see it like this. If you are creating a new application, you can create it by selecting its environment. By the way, I use an existing project from GitHub. So I select the “Bring your own code” card.
Then you have to get an existing project from GitHub.for that, you have to connect with your GitHub account and then select your project with a necessary branch from GitHub.
Then if your app is dockerized, select it as yes and select a runtime environment for your app, and select the framework you used. My app is not dockerized and I use a .Net runtime environment and ASP.NET Core framework.
Then select Azure service to deploy the application. And I selected Windows Web App for my project.
Then configure the Azure DevOps and Azure Subscription. When you configure the Azure DevOps, you have to enter the project name and select your existing Azure DevOps organization or also you can create a new Azure DevOps organization.
After configuring the project on Azure DevOps, you can see the Deployment overview and then select Go to Resource to view the DevOps starter dashboard. Then you can see it like the below picture.
So this dashboard provides visibility of our project code and repository and also our CI/CD pipeline for the App in Azure and its status.
After succeeded, we can check our API by using Postman.
As we can see, now we are able to get the correct result from our Web API in Azure, and we deployed our .NET CORE Web API to Azure successfully!
Also, You can do small changes to your Web API project and then commit it to GitHub. Then you can see, that the changes you made are automatically built and deployed through a CI/CD pipeline.
I think you learned something new from my article.
Good Luck All!
No comments:
Post a Comment