Introduction
Azure App Service supports deploying our GitHub source into the Azure Cloud. This article helps you to learn about how to add your existing project into your GitHub repository and deploy it in Azure, using Azure App Services.
Prerequisites
- Visual Studio 2013+
- GitHub account
- Basic knowledge of GitHub
- Azure subscription and basic knowledge of Azure app Service
This article falls into the steps given below.
- Create a repository in GitHub.
- Create a basic ASP.NET Core Application, using Visual Studio.
- Add the project to your GitHub repository.
- Create a WebApp and deploy with GitHub source in an Azure.
Step 1
Create a Repository in GitHub
Login to
GitHub. Just click New respository in home page, as shown below.
Your new repository page will open, give a repository name and description. You can set whether this repository should be public or private, once the required settings are done, click Create repository. In my case, I named a repository as CoreAppKendoDemo.
Next step is that you will get https URL, which is used to push your local existing code to GitHub repository, as shown below.
Step 2
Create a basic ASP.NET Core application
Open Visual Studio file->Project-> From the installed template, choose .NET Core -> ASP.NET Core Web Application. I named the project as MyCoreAPI, as shown below.
Next step is to choose WEB API template and click OK.
The new ASP.NET Core project will be opened. Let’s create one new API.
If you are new to ASP.NET Core, please click
here to learn more about it.
Right click on Project and create one model folder.
Right click on the newly created model folder, followed by adding Class and name it as TechnoloyList.cs
TechnologyList.cs
- public class TechnologyList
- {
- public TechnologyList(int Value, string Text)
- {
-
- this.Value = Value;
- this.Text = Text;
- }
- public int Value { get; set; }
- public string Text { get; set; }
- }
Right click on controller folder, Add->Controller, select the minimal dependency and an empty API template, name it as TechnologiesController.cs, as shown below.
TechnologiesController.cs
- [Produces("application/json")]
- [Route("api/Technologies")]
- public class TechnologiesController Controller
- {
- [HttpGet]
- [AllowAnonymous]
- [Route("TechnologiesList")]
- public List<TechnologyList> GetTechnology()
- {
- try
- {
- List<TechnologyList> _TechList = new List<TechnologyList>();
- _TechList.Add(new TechnologyList(1, "ASP.NET"));
- _TechList.Add(new TechnologyList(2, "ADO.NET"));
- _TechList.Add(new TechnologyList(3, "SilverLight"));
- _TechList.Add(new TechnologyList(4, "C#"));
- _TechList.Add(new TechnologyList(5, "SQL Server"));
-
-
- return _TechList;
-
- }
- catch (Exception ex)
- {
- List < TechnologyList > _Tech= null;
- return _Tech;
- }
- }
- }
From the above Controller, it is obvious that we will get a list of technologies from the GetTechnology() action.
Let's test our API, using POSTMAN Tool.
Yes, our API is working fine, which is giving a proper response with the list of technologies from the request.
Step 3
Add the project to your GitHub repo
Go to File->Add to Source control or in right bottom, you can Add to Source control in Visual Studio, as shown below. Click it and it will open a Team Explore.
In Team Explorer, you can find a section for Push to Remote repository, just copy and paste GitHub URL, which you got it from creating a new repository in the section. Click Publish and this will publish your code to GitHub, as shown below.
Pulished code in GitHub code section is shown below.
Step 4
Create a Web app in an Azure with GitHub source and deploy
Login to your Azure portal (https//portal.azure.com). If you are new to Azure Web app Service, click here to learn more.
Create a new Web app, as shown below.
Click Web App and Create.
Name the Web app. In my case, I named it as kendoControlDemo. Choose your subscription, resource group and plan. Once all the settings are done, click Create.
The Web app deployment process starts.
Once the deployment completes, just click App Service from the menu, which will list out the number of app Services; which you created. Click the recently created kendoControlDemo app, as shown below.
You will get a basic information regarding the Web app from the overview. You will notice a separate URL is created for your Web app.
In the setting, you can find deployment option. Click it and it will open a set up deployment source page. Now, choose source and select GitHub, as shown below.
Now, the authorize process will start, give your GitHub credential to integrate the Web app with your GitHub resource. No worries, your password details will be safe and it won’t be saved in an Azure. It’s completely a token based authentication process.
Once your authorization process completes, you are able to choose your project and the branch.
Finally, click Ok for the deployment.
Once the deployment is sucessful, let's test our API, using POSTMAN tool, as shown below.
Yes, our GitHub source has been successfully deployed in Azure, using the Web app Service.
I hope, you have enjoyed this article. Your valuable feedback, questions or comments about this article are always welcome.