Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Web API Development with ASP.NET Core 8

You're reading from  Web API Development with ASP.NET Core 8

Product type Book
Published in Apr 2024
Publisher Packt
ISBN-13 9781804610954
Pages 804 pages
Edition 1st Edition
Languages
Author (1):
Xiaodi Yan Xiaodi Yan
Profile icon Xiaodi Yan

Table of Contents (20) Chapters

Preface 1. Chapter 1: Fundamentals of Web APIs 2. Chapter 2: Getting Started with ASP.NET Core Web APIs 3. Chapter 3: ASP.NET Core Fundamentals (Part 1) 4. Chapter 4: ASP.NET Core Fundamentals (Part 2) 5. Chapter 5: Data Access in ASP.NET Core (Part 1: Entity Framework Core Fundamentals) 6. Chapter 6: Data Access in ASP.NET Core (Part 2 – Entity Relationships) 7. Chapter 7: Data Access in ASP.NET Core (Part 3: Tips) 8. Chapter 8: Security and Identity in ASP.NET Core 9. Chapter 9: Testing in ASP.NET Core (Part 1 – Unit Testing) 10. Chapter 10: Testing in ASP.NET Core (Part 2 – Integration Testing) 11. Chapter 11: Getting Started with gRPC 12. Chapter 12: Getting Started with GraphQL 13. Chapter 13: Getting Started with SignalR 14. Chapter 14: CI/CD for ASP.NET Core Using Azure Pipelines and GitHub Actions 15. Chapter 15: ASP.NET Core Web API Common Practices 16. Chapter 16: Error Handling, Monitoring, and Observability 17. Chapter 17: Cloud-Native Patterns 18. Index 19. Other Books You May Enjoy

CI/CD for ASP.NET Core Using Azure Pipelines and GitHub Actions

In the previous chapters, we have explored the fundamentals of building, testing, and running ASP.NET Core applications. We have also discussed how to access data from a database using Entity Framework Core (EF Core) and secure our applications using ASP.NET Core Identity. Additionally, we have discussed how to test our applications using unit tests and integration tests, as well as how to use RESTful APIs, gRPC, and GraphQL. Furthermore, we have learned how to use the dotnet run command to run our applications locally. Now, it is time to take the next step in our ASP.NET Core journey and learn how to deploy our applications to the cloud.

In this chapter, we will explore the concept of continuous integration and continuous delivery/deployment (CI/CD). This chapter will focus on two popular CI/CD tools and platforms: Azure Pipelines and GitHub Actions.

We will discuss the following topics in this chapter:

    ...

Technical requirements

Introduction to CI/CD

Developers work on code every day – they may create new features, fix bugs, or refactor existing code. In a team environment, multiple developers may be working on the same code base. A developer may create a new feature, while another developer may be fixing a bug. The code base is constantly changing, and it is important to ensure that the code changes made by different developers do not conflict with each other and do not break any existing functionalities. To avoid such issues, developers should integrate their code changes frequently.

Additionally, when the application is ready to be deployed, it is important to consider the different environments it may be deployed to, such as development, staging, or production. Different environments may have different configurations, and the deployment process may be different for each environment. To ensure that the application is deployed correctly and consistently, it is ideal to automate the deployment process...

Containerizing ASP.NET Core applications using Docker

Many years ago, when we deployed applications to the production environment, we needed to ensure that the target environment had the correct version of the .NET Framework installed. Developers were struggling with the it works on my machine problem, as development environments may have had different configurations than the production environment, including software versions, operating systems, and hardware. This often led to deployment failures due to configuration issues.

The introduction of .NET Core, a cross-platform and open-source framework, has enabled us to deploy our applications on any platform, including Windows, Linux, and macOS. However, for successful deployment, we still need to ensure that the target environment has the correct runtime installed. This is where containerization comes in.

What is containerization?

Containers are lightweight, isolated, and portable environments that contain all the necessary...

CI/CD using Azure DevOps and Azure Pipelines

Azure DevOps is a cloud-based service that provides a set of tools for managing the software development process. It includes the following services:

  • Azure Boards: A service for managing work items, such as user stories, tasks, and bugs.
  • Azure Repos: A service for hosting code repositories. It supports Git and Team Foundation Version Control (TFVC). The repositories can be public or private.
  • Azure Pipelines: A service for building, testing, and deploying applications with any language, platform, and cloud.
  • Azure Test Plans: A service for manual and exploratory testing tools.
  • Azure Artifacts: A service for creating, hosting, and sharing packages, such as Maven, npm, NuGet, and Python packages.

Azure DevOps is free for open-source projects and small teams. We will not cover all the features of Azure DevOps in this book. Let us focus on Azure Pipelines. In this section, we will discuss how to use Azure Pipelines...

GitHub Actions

In the previous section, we explored Azure Pipelines. Next, let us explore GitHub Actions. GitHub Actions is a CI/CD tool provided by GitHub. It is quite similar to Azure Pipelines. In this section, we will use GitHub Actions to build and test the application and push the Docker image to ACR.

Preparing the project

To demonstrate how to use GitHub Actions, we will use the same source code as we used in the previous section. You can download the source code from the GitHub repository here: https://github.com/PacktPublishing/Web-API-Development-with-ASP.NET-Core-8/tree/main/samples/chapter14/MyBasicWebApiDemo. Create a new GitHub repository and push the source code to the repository. The directory structure of the source code is as follows:

MyGitHubActionsDemo    ├── src
    │   └──MyBasicWebApiDemo
    ├── tests
 ...

Summary

In this chapter, we explored the fundamentals of CI/CD. We discussed how to use Docker to containerize ASP.NET web API applications, including how to create a Dockerfile, build a Docker image, and run a Docker container locally. We then looked at Azure DevOps Pipelines, a powerful CI/CD platform from Microsoft, and how to create CI/CD pipelines in YAML files. We covered configuring triggers, using built-in tasks, and using variables. We created three pipelines for builds, Docker image builds, and releases. We also briefly discussed GitHub Actions, another popular CI/CD tool, and created a GitHub Actions workflow to build and test the application, then build the Docker image and push it to ACR. After reading this chapter, you should have a basic understanding of CI/CD and be able to use CI/CD pipelines to automate the build, test, and deployment process.

In the next chapter, we will examine some common practices for building ASP.NET web APIs, including caching, HttpClient...

lock icon The rest of the chapter is locked
You have been reading a chapter from
Web API Development with ASP.NET Core 8
Published in: Apr 2024 Publisher: Packt ISBN-13: 9781804610954
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}