A sample .NET Aspire application demonstrating cloud-native development with Azure deployment capabilities. This project showcases a multi-service application with a web frontend, API service, and Azure integrations including Cosmos DB and Blob Storage.
This solution contains the following projects:
apphost.cs- The Aspire AppHost that orchestrates the application and defines cloud resourcesDeployApp.Web- Blazor web frontend applicationDeployApp.ApiService- ASP.NET Core Web API that provides weather forecast dataDeployApp.ServiceDefaults- Shared service defaults and configurations
- Azure Container App Environment - Hosting environment for containerized services
- Azure Cosmos DB - NoSQL database with preview emulator support for local development
- Azure Blob Storage - Object storage for images and files
- Bicep Templates - Infrastructure as Code definitions located in individual folders
- .NET 9.0 SDK
- Docker Desktop (for local development)
- Azure CLI (for deployment)
- .NET Aspire CLI
-
Clone the repository:
git clone https://github.com/captainsafia/aspire-azure-deploy-standalone-test.git cd aspire-azure-deploy-standalone-test -
Install .NET Aspire CLI:
curl -sSL https://aspire.dev/install.sh | bash
Use the Aspire CLI to run the entire application stack locally with orchestration:
aspire runThis command will:
- Start the Aspire dashboard at
http://localhost:15000 - Launch all services with proper service discovery
- Initialize local emulators for Azure services (Cosmos DB, Storage)
- Provide real-time monitoring and logging capabilities
Deploy the application to Azure using the Aspire CLI:
aspire deployThis command will:
- Build and containerize your applications
- Deploy infrastructure using the generated Bicep templates
- Deploy application containers to Azure Container Apps
- Configure service connections and environment variables
Before deploying, ensure you have authenticated with Azure via the az CLI, the Azure extension in VS Code, or in Visual Studio.
After successful deployment, you'll receive:
- URLs for your deployed applications
- Resource group information
- Connection strings and endpoints
The repository includes a GitHub Actions workflow (.github/workflows/deploy.yml) that automatically deploys the application when changes are pushed to the main branch.
- Triggers: Pushes to
main, pull requests, and manual dispatch - Environment: Runs on Ubuntu latest
- Security: Uses OpenID Connect for secure Azure authentication
- Deployment: Automated Aspire CLI deployment to Azure
The pipeline uses federated credentials to authenticate with Azure in the pipeline.
- Create an Azure app registration using
az ad app create --display-name "GitHub-Actions-App". - Create a service principal using
az ad sp create --id <app-id-from-step-1>. - Configure the federated credentials:
az ad app federated-credential create \
--id <app-id> \
--parameters '{
"name": "GitHub-Actions",
"issuer": "https://token.actions.githubusercontent.com",
"subject": "repo:your-org/your-repo:ref:refs/heads/main",
"audiences": ["api://AzureADTokenExchange"]
}'
- Configure the service principal with permissions to configure role assignments on the target subscription.
az role assignment create \
--assignee <your-service-principal-id> \
--role "User Access Administrator" \
--scope "/subscriptions/<subscription-id>"
Configure the following secrets in your GitHub repository:
| Secret Name | Description | Example |
|---|---|---|
AZURE_TENANT_ID |
Azure Active Directory Tenant ID | xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx |
AZURE_CLIENT_ID |
Service Principal Client ID | xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx |
AZURE_SUBSCRIPTIONID |
Azure Subscription ID | xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx |
AZURE_LOCATION |
Azure region for deployment | eastus |
AZURE_RESOURCEGROUP |
Target resource group name | my-aspire-app-rg |
WEATHER_API_KEY |
API key for weather forecast service | test-api-key |
The deployment workflow performs the following steps:
- Code Checkout - Retrieves the latest code
- Environment Setup - Installs .NET SDK based on
global.json - Azure Authentication - Securely authenticates using OIDC
- Aspire CLI Installation - Downloads and installs the latest Aspire CLI
- Deployment - Executes
aspire deploywith environment variables