Deploy GitHub Source To Azure Using Azure App Services

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.

  1. Create a repository in GitHub.
  2. Create a basic ASP.NET Core Application, using Visual Studio.
  3. Add the project to your GitHub repository.
  4. 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 
  1. public class TechnologyList  
  2.     {  
  3.         public TechnologyList(int Value, string Text)  
  4.         {  
  5.   
  6.             this.Value = Value;  
  7.             this.Text = Text;  
  8.         }  
  9.         public int Value { getset; }  
  10.         public string Text { getset; }  
  11.     }  

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 
  1. [Produces("application/json")]  
  2.    [Route("api/Technologies")]  
  3.    public class TechnologiesController  Controller  
  4.    {  
  5.        [HttpGet]  
  6.        [AllowAnonymous]  
  7.        [Route("TechnologiesList")]  
  8.        public List<TechnologyList> GetTechnology()  
  9.        {  
  10.            try  
  11.            {  
  12.                 List<TechnologyList> _TechList = new List<TechnologyList>();  
  13.                _TechList.Add(new TechnologyList(1, "ASP.NET"));  
  14.                _TechList.Add(new TechnologyList(2, "ADO.NET"));  
  15.                _TechList.Add(new TechnologyList(3, "SilverLight"));  
  16.                _TechList.Add(new TechnologyList(4, "C#"));  
  17.                _TechList.Add(new TechnologyList(5, "SQL Server"));  
  18.   
  19.                //return Request.CreateResponse(HttpStatusCode.OK, _TechList, Configuration.Formatters.JsonFormatter);  
  20.                return _TechList;  
  21.   
  22.            }  
  23.            catch (Exception ex)  
  24.            {  
  25.                List < TechnologyList > _Tech= null;  
  26.                return _Tech;  
  27.            }  
  28.        }  
  29.    }  

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.

Up Next
    Ebook Download
    View all
    Learn
    View all