Aspire is optimized for apps that are destined to run in containerized environments. Azure Container Apps is a fully managed environment that enables you to run microservices and containerized applications on a serverless platform. This article will walk you through creating a new Aspire solution and deploying it to Microsoft Azure Container Apps using Visual Studio and the Azure Developer CLI (azd).
In this example, we'll assume you're deploying the MyWeatherHub app from the previous sections. You can use the code you've built, or you can use the code in the complete directory. However, the general steps are the same for any Aspire app.
-
In the Solution Explorer, right-click on the AppHost project and select Publish to open the Publish dialog.
Publishing Aspire requires the current version of the
azdCLI. This should be installed with the Aspire workload, but if you get a notification that the CLI is not installed or up to date, you can follow the directions in the next part of this tutorial to install it. -
Select Azure Container Apps for Aspire as the publishing target.
-
On the AzDev Environment step, select your desired Subscription and Location values and then enter an Environment name such as aspire-weather. The environment name determines the naming of Azure Container Apps environment resources.
-
Select Finish to create the environment, then Close to exit the dialog workflow and view the deployment environment summary.
-
Select Publish to provision and deploy the resources on Azure.
This process may take several minutes to complete. Visual Studio provides status updates on the deployment progress in the output logs and you can learn a lot about how publishing works by watching these updates! You'll see that the process involves creating a resource group, an Azure Container Registry, a Log Analytics workspace, and an Azure Container Apps environment. The app is then deployed to the Azure Container Apps environment.
-
When the publish completes, Visual Studio displays the resource URLs at the bottom of the environment screen. Use these links to view the various deployed resources. Select the webfrontend URL to open a browser to the deployed app.
The process for installing azd varies based on your operating system, but it is widely available via winget, brew, apt, or directly via curl. To install azd, see Install Azure Developer CLI.
Aspire 13 introduces the aspire do command, which provides a powerful deployment pipeline system with discrete, parallelizable steps. This replaces and extends the earlier experimental aspire deploy command.
Available pipeline subcommands:
aspire do build # Build containers
aspire do push # Push containers to registry
aspire do deploy # Deploy to target environment
aspire do diagnostics # Visualize your pipelinePipeline steps can be customized and dependency-tracked in code. Aspire automatically parallelizes independent steps, speeding up deployments. To use the full pipeline:
aspire doThis runs all configured pipeline steps in dependency order. You can also customize your pipeline in the AppHost:
builder.Pipeline.AddStep("my-step", requiredBy: "deploy", async (context) =>
{
// Custom deployment logic
});Note
The aspire do pipeline system is evolving rapidly. Check the Aspire Blog for the latest updates on deployment features.
Prerequisites:
- Make sure you're signed in: run
azd loginand select the correct Azure subscription.- Run the following commands from the folder that contains your AppHost (for this repo, typically the
completefolder if you're deploying the finished sample).
-
Open a new terminal window and
cdinto the root of your Aspire project. -
Execute the
azd initcommand to initialize your project withazd, which will inspect the local directory structure and determine the type of app.azd initFor more information on the
azd initcommand, see azd init. -
If this is the first time you've initialized the app,
azdprompts you for the environment name:Initializing an app to run on Azure (azd init) ? Enter a new environment name: [? for help]
Enter the desired environment name to continue. For more information on managing environments with
azd, see azd env. -
Select Use code in the current directory when
azdprompts you with two app initialization options.? How do you want to initialize your app? [Use arrows to move, type to filter] > Use code in the current directory Select a template
-
After scanning the directory,
azdprompts you to confirm that it found the correct Aspire AppHost project. Select the Confirm and continue initializing my app option.Detected services: .NET (Aspire) Detected in: D:\source\repos\letslearn-dotnet-aspire\complete\AppHost\AppHost.csproj azd will generate the files necessary to host your app on Azure using Azure Container Apps. ? Select an option [Use arrows to move, type to filter] > Confirm and continue initializing my app Cancel and exit
-
azdpresents each of the projects in the Aspire solution and prompts you to identify which to deploy with HTTP ingress open publicly to all internet traffic. Select only themyweatherhub(using the ↓ and Space keys), since you want the API (api) to be private to the Azure Container Apps environment and not available publicly.? Select an option Confirm and continue initializing my app By default, a service can only be reached from inside the Azure Container Apps environment it is running in. Selecting a service here will also allow it to be reached from the Internet. ? Select which services to expose to the Internet [Use arrows to move, space to select, <right> to all, <left> to none, type to filter] [ ] api > [x] myweatherhub
-
Finally, specify the the environment name, which is used to name provisioned resources in Azure and managing different environments such as
devandprod.Generating files to run your app on Azure: (✓) Done: Generating ./azure.yaml (✓) Done: Generating ./next-steps.md SUCCESS: Your app is ready for the cloud! You can provision and deploy your app to Azure by running the azd up command in this directory. For more information on configuring your app, see ./next-steps.md
azd generates a number of files and places them into the working directory. These files are:
- azure.yaml: Describes the services of the app, such as Aspire AppHost project, and maps them to Azure resources.
- .azure/config.json: Configuration file that informs
azdwhat the current active environment is. - .azure/aspireazddev/.env: Contains environment specific overrides.
- .azure/aspireazddev/config.json: Configuration file that informs
azdwhich services should have a public endpoint in this environment.
Once azd is initialized, the provisioning and deployment process can be executed as a single command, azd up.
By default, a service can only be reached from inside the Azure Container Apps environment it is running in. Selecting a service here will also allow it to be reached from the Internet.
? Select which services to expose to the Internet webfrontend
? Select an Azure Subscription to use: 1. <YOUR SUBSCRIPTION>
? Select an Azure location to use: 1. <YOUR LOCATION>
Packaging services (azd package)
SUCCESS: Your application was packaged for Azure in less than a second.
Provisioning Azure resources (azd provision)
Provisioning Azure resources can take some time.
Subscription: <YOUR SUBSCRIPTION>
Location: <YOUR LOCATION>
You can view detailed progress in the Azure Portal:
<LINK TO DEPLOYMENT>
(✓) Done: Resource group: <YOUR RESOURCE GROUP>
(✓) Done: Container Registry: <ID>
(✓) Done: Log Analytics workspace: <ID>
(✓) Done: Container Apps Environment: <ID>
(✓) Done: Container App: <ID>
SUCCESS: Your application was provisioned in Azure in 1 minute 13 seconds.
You can view the resources created under the resource group <YOUR RESOURCE GROUP> in Azure Portal:
<LINK TO RESOURCE GROUP OVERVIEW>
Deploying services (azd deploy)
(✓) Done: Deploying service api
- Endpoint: <internal-only>
(✓) Done: Deploying service myweatherhub
- Endpoint: <YOUR UNIQUE myweatherhub APP>.azurecontainerapps.io/
SUCCESS: Your application was deployed to Azure in 1 minute 39 seconds.
You can view the resources created under the resource group <YOUR RESOURCE GROUP> in Azure Portal:
<LINK TO RESOURCE GROUP OVERVIEW>
SUCCESS: Your up workflow to provision and deploy to Azure completed in 3 minutes 50 seconds.First, the projects will be packaged into containers during the azd package phase, followed by the azd provision phase during which all of the Azure resources the app will need are provisioned.
Once provision is complete, azd deploy will take place. During this phase, the projects are pushed as containers into an Azure Container Registry instance, and then used to create new revisions of Azure Container Apps in which the code will be hosted.
At this point the app has been deployed and configured, and you can open the Azure portal and explore the resources.
Run the following Azure CLI command to delete the resource group when you no longer need the Azure resources you created. Deleting the resource group also deletes the resources contained inside of it.
az group delete --name <your-resource-group-name>
