Automate deployment using Git, GitHub and Azure

In this tutorial, I am going to show the simple GUI based steps that how we can deploy our code to Microsoft Azure, but we can deploy using git, azure-cli.

Prerequisites:

  1. Microsoft Azure subscription here
  2. Git, you can download from here and complete installation
  3. GitHub account, create here
  4. Sample project, download from here or simply follow the steps

Let’s create simple ASP.NET Core project

Step # 1:

Make a new folder

Step # 2:

Navigate to the newly created folder.

 

Step # 3:

Set up and restore new ASP.NET Core MVC project.

Step # 4:

Run the project on your local machine to check it is working or not

Step # 1 – 4 Summary:

Step # 5:

Now, we have working sample project, and it’s time to push our code to GitHub account

Create new repository with any name you like, and description is optional then hit create button



Step# 6:

Initialize git repository from the current one to add a .git folder and makes it possible to start your revision history.

Step # 7:

The add all the existing files and folder to the index

Step # 8:

Record the state as your first commit in the history to the master branch of your project

Step # 9:

Now create a new remote called origin and then locate URL

Step # 10:

Push the local commit to the remote master branch



Now refresh your repository in browser to see the code

Step # 11:

Now it’s time to play with Azure

Follow the steps to create new Web app instance

  1. login to you Azure portal account
  2. At top left click + (New)
  3. Click the Web + Mobile
  4. Choose first option (Web app)
  5. Provide the App name (can be different from GitHub repository name)
  6. Create logical resource group
  7. Choose the location
  8. Press the create button

After successful creation and deployment, notification will appear shown in blow image

Step # 12:

  1. Click on newly created web app, go to the APP DEPLOYMENT section and select Deployment options
  2. Choose source > Choose GitHub

Step # 13:

  1. Provide GitHub Authorization
  2. Select the project from the list
  3. Select the master branch. Note: make sure that you are deploying the master branch.
  4. Click Ok

Wait a moment so that Azure can make a connection with our GitHub repository. After that Azure will start the process of build and deployment. You can see the progress by going deployment options.

After successful deployment, you can see the green active icon

Now browse the URL, Overview > URL

Your website is live on the internet.

But wait, the important point is to make sure that our deployment is automatic, for this we will make some changes in our project then commit and push these changes to our GitHub repository if the changes occurred in the live website then have achieved our goal otherwise, there is some problem.

So, open the project in Visual Studio Code

Step # 14:

Open the Views > Home > index.cshtml file

 

change some code and add these changes to the git index

Commit and push to the remote master branch

 

Open Azure portal

Go to APP DEPLOYMENT > Deployment options wait for the green active icon.



Now refresh your live website and see the change



Congratulation, That’s it.