© The Author(s), under exclusive license to APress Media, LLC, part of Springer Nature 2023
A. Satapathi, A. MishraDeveloping Cloud-Native Solutions with Microsoft Azure and .NET https://doi.org/10.1007/978-1-4842-9004-0_11

11. Deploy an ASP.NET Web Application to an Azure Web App Using GitHub Actions

Ashirwad Satapathi1   and Abhishek Mishra2
(1)
Gajapati, Odisha, India
(2)
Navi MUmbai, India
 

DevOps is an important aspect for any application development process. The developers can develop the code and check it in to the source control repository. As soon as the code check processing is complete, the DevOps continuous integration pipeline builds the code and keeps the application’s deployable package in a centralized location. Then the DevOps continuous deployment pipeline picks up the package and deploys it to the target environment. This entire process repeats every time the developer makes changes to the code base and checks in the code. There are lot of DevOps tool offerings in the industry. A few of the popular ones are Jenkins, Azure DevOps, and GitHub Actions, to name a few.

In this chapter we will explore GitHub Actions and how to deploy a .NET application to an Azure web app using GitHub Actions.

Structure

In this chapter, we will explore the following topics related to Azure Cognitive Service:
  • Introduction to GitHub Actions

  • Build a .NET application and push it to GitHub

  • Provision an Azure web app

  • Deploy an application to Azure the web app using GitHub Actions

Objectives

After studying this chapter, you should be able to
  • Understand the fundamentals of GitHub Actions

  • Deploy code to an Azure web app using GitHub Actions

Introduction to GitHub Actions

GitHub Actions helps you to build continuous integration (CI) and continuous deployment (CD) workflows in GitHub that can build the application code checked in to GitHub and deploy it on target environments with ease. You can write YAML-based workflows that have multiple steps to perform different DevOps activities. These workflows get triggered whenever an event occurs in GitHub. For example, whenever the developer checks in the code to GitHub, an event occurs and this triggers the GitHub Actions workflow that will build and deploy the checked in code. The workflows run on servers called runners. Figure 11-1 depicts the architecture of GitHub Actions.
Figure 11-1

GitHub Actions architecture

GitHub actions are much more than DevOps tools. You can use GitHub actions to perform automations in the GitHub environment, like adding a label automatically whenever code is checked in to GitHub.

The workflows comprise a set of actions. Each of the actions performs an activity; for example, containerize the application, build the application, or push the container image to a container registry. GitHub provides a wide range of GitHub actions in the GitHub Marketplace. You can use GitHub actions to develop DevOps pipelines meeting your application and business needs.

Build a .NET Application and Push It to GitHub

Let’s build a .NET web application and commit it to a GitHub repository. We will then configure a GitHub action to deploy the code to an Azure web app. Open Visual Studio and click Create a new project as shown in Figure 11-2.
Figure 11-2

Click Create a new project

Select ASP.NET Core Web App as shown in Figure 11-3 and then click Next.
Figure 11-3

Select ASP.NET Core Web App

Provide the details for the project as in Figure 11-4 and click Next.
Figure 11-4

Provide project details

Select the framework for .NET that you will use to build the application, as shown in Figure 11-5, and then click Create. The default web application code will get generated. We can push this project to the GitHub repository without making any changes.
Figure 11-5

Select .NET version

Now let’s push the code to the GitHub repository. Click the Git menu and then click Create Git Repository as shown in Figure 11-6.
Figure 11-6

Chose Create Git Repository from the Git menu

Click the Account drop-down arrow and select GitHub account as shown in Figure 11-7. You need to sign it and authorize Visual Studio to push the code to the GitHub repository.
Figure 11-7

Select GitHub account

Provide your GitHub credentials when prompted and sign in to GitHub as shown in Figure 11-8.
Figure 11-8

Sign in to GitHub

Click Authorize github as shown in Figure 11-9 to authorize Visual Studio to push code to the GitHub repository.
Figure 11-9

Authorize GitHub

Select your repository and click Create and Push as shown in Figure 11-10.
Figure 11-10

Push code to GitHub

You can log in to your GitHub account and verify the checked in code, shown in Figure 11-11.
Figure 11-11

Checked in code in the GitHub repository

Provision Azure Web App

Now let’s provision an Azure web pp. We will deploy the web application checked in to GitHub to this web app using a GitHub action. Go to the Azure portal and click Create a resource as shown in Figure 11-12.
Figure 11-12

Click Create a resource

You will be navigated to the Azure Marketplace. Click Web and then click Web App as shown in Figure 11-13.
Figure 11-13

Click Web App

Provide the basic details for the web app as shown in Figure 11-14.
Figure 11-14

Provide basic details

Create an App Service plan as shown in Figure 11-15 and then click Review + create.
Figure 11-15

Click Review + create

Click Create as shown in Figure 11-16 to provision the web app.
Figure 11-16

Click Create

Deploy Application to Azure Web App Using GitHub Actions

Not let’s configure GitHub actions for the Azure web app and deploy to the web app the application code checked in to the GitHub repository. Go to the Azure web app you created and click Deployment Center. Select GitHub as the source as shown in Figure 11-17.
Figure 11-17

Select GitHub

Click Authorize as shown in Figure 11-18 to facilitate deployment of the application from GitHub to the web app.
Figure 11-18

Click Authorize

Provide your credentials and sign in to GitHub as shown in Figure 11-19.
Figure 11-19

Sign in to GitHub

Click Authorize AzureAppService as shown in Figure 11-20.
Figure 11-20

Authorize Azure App Service

Select the repository and branch details for the GitHub repository as shown in Figure 11-21 and then click Save.
Figure 11-21

Click Save

Generic GitHub actions pipeline for building and pushing .NET Core application will automatically get generated. Deployment will get initiated as shown in Figure 11-22. You can click the Logs tab to check the build and deployment logs.
Figure 11-22

Click the Logs tab to see logs

You can click one of the stages, either build or deploy, as shown in Figure 11-23 to view the detailed logs for each of the stages.
Figure 11-23

See logs for each stage

You can see the logs for the build and deploy stages as shown in Figure 11-24.
Figure 11-24

Detailed build and deploy logs

Once the deployment is complete, you can browse using the URL for the web app, which you can get from the Overview tab of the web app. You will see the deployed application rendered on the browser as shown in Figure 11-25.
Figure 11-25

Deployed application on web app

Summary

In this chapter, we explored the basic concepts of GitHub Actions. Then we created a .NET web application and checked in the code to the GitHub repository. We then created an Azure web app and deployed the application to the web app using GitHub actions.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset