Skip to content

Commit daa177e

Browse files
ShilpiRachShilpiRCopilot
authored
Add README.md for the Aspire.Hosting.Azure.AppService package (#12528)
* Adding README.md for Aspire.Hosting.Azure.AppService * Replaced tabs with spaces * Apply suggestion from @Copilot Co-authored-by: Copilot <[email protected]> * Addressing PR comments --------- Co-authored-by: Shilpi Rachna <[email protected]> Co-authored-by: Copilot <[email protected]>
1 parent 64459de commit daa177e

File tree

1 file changed

+123
-0
lines changed

1 file changed

+123
-0
lines changed
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
# Aspire.Hosting.Azure.AppService library
2+
3+
Provides extension methods and resource definitions for an Aspire AppHost to configure Azure App Service for the compute resources (like project).
4+
5+
## Getting started
6+
7+
### Prerequisites
8+
9+
- Azure subscription (requires Owner access to the target subscription for role assignments)
10+
11+
### Install the package
12+
13+
In your AppHost project, install the Aspire Azure App Service Hosting library with [NuGet](https://www.nuget.org):
14+
15+
```dotnetcli
16+
dotnet add package Aspire.Hosting.Azure.AppService
17+
```
18+
19+
## Usage example
20+
21+
Then, in the _AppHost.cs_ file of `AppHost`, add an Azure App Service Environment and publish your project as an Azure App Service Web App:
22+
23+
```csharp
24+
var builder = DistributedApplication.CreateBuilder(args);
25+
26+
var appServiceEnvironment = builder.AddAzureAppServiceEnvironment("env");
27+
28+
builder.AddProject<Projects.MyWebApp>("webapp")
29+
.WithExternalHttpEndpoints()
30+
.PublishAsAzureAppServiceWebsite((infrastructure, website) =>
31+
{
32+
// Customize the App Service health check path and appsettings
33+
website.SiteConfig.HealthCheckPath = "/health";
34+
website.SiteConfig.AppSettings.Add(new AppServiceNameValuePair()
35+
{
36+
Name = "Environment",
37+
Value = "Production"
38+
});
39+
});
40+
```
41+
42+
## Azure App Service constraints
43+
44+
When deploying to Azure App Service, the following constraints apply:
45+
46+
- **External endpoints only**: App Service only supports external endpoints. All endpoints must be configured using `WithExternalHttpEndpoints()`.
47+
- **HTTP/HTTPS only**: Only HTTP and HTTPS endpoints are supported. Other protocols are not supported.
48+
- **Single endpoint**: App Service supports only a single target port. Resources with multiple external endpoints with different target ports are not supported. The default target port is 8000, which can be overridden using the `WithHttpEndpoint` extension method.
49+
50+
### Publishing compute resources to Azure App Service
51+
52+
The `PublishAsAzureAppServiceWebsite` extension method is used to configure a compute resource (such as a project) to be published as an Azure App Service Web App when deploying to Azure. This method allows you to customize the App Service Web App configuration using the Azure Provisioning SDK.
53+
54+
```csharp
55+
builder.AddProject<Projects.MyApi>("api")
56+
.WithHttpEndpoint(targetPort: 8080)
57+
.WithExternalHttpEndpoints()
58+
.WithHealthProbe(ProbeType.Liveness, "/health")
59+
.WithArgs("--environment", "Production")
60+
.PublishAsAzureAppServiceWebsite((infrastructure, website) =>
61+
{
62+
// Customize the App Service Web App appsettings
63+
website.SiteConfig.IsWebSocketsEnabled = true;
64+
website.SiteConfig.MinTlsVersion = SupportedTlsVersions.Tls1_2;
65+
});
66+
```
67+
68+
### Adding an Azure App Service Environment
69+
70+
The Azure App Service Environment resource creates the underlying infrastructure needed to host your applications, including:
71+
72+
- An Azure App Service Plan (default SKU: P0v3)
73+
- An Azure Container Registry for storing container images
74+
- A managed identity for accessing the container registry
75+
- Optionally, the Aspire Dashboard as an Azure App Service Web App
76+
- Optionally, Application Insights for monitoring and telemetry
77+
78+
```csharp
79+
var appServiceEnvironment = builder.AddAzureAppServiceEnvironment("env");
80+
```
81+
82+
By default, the Aspire Dashboard is included in the App Service Environment. To disable the dashboard, use the `WithDashboard` extension method:
83+
84+
```csharp
85+
var appServiceEnvironment = builder.AddAzureAppServiceEnvironment("env")
86+
.WithDashboard(enable: false);
87+
```
88+
89+
### Enabling Application Insights
90+
91+
Application Insights can be enabled for the App Service Environment using the `WithAzureApplicationInsights` extension method. A different location can be specified for Application Insights using the optional location parameter:
92+
93+
```csharp
94+
var appServiceEnvironment = builder.AddAzureAppServiceEnvironment("env")
95+
.WithAzureApplicationInsights();
96+
```
97+
98+
### Customizing the App Service Plan
99+
100+
The App Service Plan can be customized using the `ConfigureInfrastructure` extension method.
101+
102+
The default SKU for the App Service Plan is P0V3 and can be changed using this extension method:
103+
104+
```csharp
105+
var appServiceEnvironment = builder.AddAzureAppServiceEnvironment("env")
106+
.ConfigureInfrastructure((infra) =>
107+
{
108+
var plan = infra.GetProvisionableResources().OfType<AppServicePlan>().Single();
109+
plan.Sku = new AppServiceSkuDescription
110+
{
111+
Name = "P2V3",
112+
Tier = "Premium"
113+
};
114+
});
115+
```
116+
117+
## Additional documentation
118+
119+
* https://learn.microsoft.com/azure/app-service/
120+
121+
## Feedback & contributing
122+
123+
https://github.com/dotnet/aspire

0 commit comments

Comments
 (0)