Enhancing Code Quality with Modern Cloud-Native Tools

Luca Milan
3 min readJul 25, 2024

--

Constructing a smooth pipeline for code deployment to production is challenging but ultimately rewarding

In the ever-evolving landscape of cloud-native development, ensuring code quality is paramount. Today, I’m excited to share our cutting-edge approach to End-to-End (E2E) testing, leveraging .NET Aspire, Azure Developer CLI (AZD), and Azure Container Apps.

Our Modern Tech Stack

  • Application Framework: .NET Aspire
  • E2E Testing: Cypress
  • Hosting: Azure Container Apps
  • Infrastructure as Code: Bicep
  • Orchestration: Azure Developer CLI (AZD)
  • CI/CD: GitHub Actions

The Concept

For each Pull Request (PR), we dynamically create an isolated, ephemeral Azure Container App environment. This environment, built with Bicep templates generated by .NET Aspire resource manifests, serves as the stage for our Cypress E2E tests.

How We Implement It

  1. PR Triggered: A new PR kicks off our GitHub Actions workflow.
  2. Environment Provisioning: AZD commands orchestrate the creation of our Azure resources, using Bicep templates for infrastructure-as-code.
  3. Application Deployment: Our .NET Aspire application is containerized by dotnet, pushed to Azure Container Registry and deployed to the newly created Azure Container App environment by AZD commands.
  4. E2E Testing: Cypress tests run against this isolated environment, providing comprehensive coverage of our application’s functionality.
  5. Results & Cleanup: Test results are reported back to the PR, and the environment is torn down post-testing.

Why It’s Game-Changing

  • True Isolation: Each PR gets its own Azure Container App environment, eliminating cross-PR interference.
  • Cloud-Native Testing: Our E2E tests run in an environment that mirrors production, thanks to .NET Aspire and Azure Container Apps.
  • Rapid Feedback: AZD’s streamlined commands ensure quick setup and teardown, speeding up our PR process.
  • Infrastructure as Code: Bicep templates make our test environments consistent and version-controlled.
  • Comprehensive Automation: From PR creation to test result reporting, everything is automated via GitHub Actions.

Key Benefits

  • Ensures only fully tested code, validated in a production-like environment, reaches our main branch.
  • Dramatically reduces integration issues and conflicts.
  • Improves overall application quality and stability.
  • Accelerates our development cycle without compromising on thoroughness.

Implementation Tips

  • Leverage .NET Aspire’s built-in observability features to gain insights during E2E tests.
  • Use AZD’s environment management capabilities to streamline your workflow.
  • Optimize your Bicep templates for quick provisioning of Azure Container App environments.
  • Configure GitHub Actions to efficiently manage the lifecycle of your test environments.

How it works

When you open a PR to merge your work, the flow starts with the checks shown in the image below and ends by running all e2e tests in the newly spawned environment ([name-of-env]-[PR-number]):

ON:PR open event

After the checks pass and you close the PR, the flow continues by destroying the [name-of-env]-[PR-number] environment.

ON:PR “closed” event

Finally the checks:

Considerations

By adopting this approach with .NET Aspire, AZD, and Azure Container Apps, we’ve not only enhanced our code quality but also significantly streamlined our development process.

The combination of these modern tools has allowed us to achieve a level of automation and efficiency that was previously out of reach.

--

--

Luca Milan
Luca Milan

Written by Luca Milan

Passionate Developer | ~25 years of experience | I write on DevOps, CI/CD, Platforms, Programming, and, sometimes, Web