ACA Container App Jobs break when launchSettings has kestrel settings
- Dominant language
- C#
- Stars
- 6.3k
- Forks
- 991
- Avg merge
- 2d 15h
- Merged PRs (30d)
- 196
Description
With an application like:
```C#
var builder = DistributedApplication.CreateBuilder(args);
builder.AddAzureContainerAppEnvironment("env");
builder.AddProject("processor")
.PublishAsAzureContainerAppJob("*/5 * * * *");
builder.Build().Run();
```
and where ProcessorJob has a launchSettings.json like:
```json
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": false,
"applicationUrl": "http://localhost:5557",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": false,
"applicationUrl": "https://localhost:7543;http://localhost:5557",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
```
Trying to deploy the app results in an error:
```
Failed to publish the distributed application.
System.Collections.Generic.KeyNotFoundException: The given key 'http' was not present in the dictionary.
at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
at Aspire.Hosting.Azure.BaseContainerAppContext.ProcessValue(Object value, SecretType secretType, Object parent) in /_/src/Aspire.Hosting.Azure.AppContainers/BaseContainerAppContext.cs:line 272
at Aspire.Hosting.Azure.BaseContainerAppContext.ProcessValue(Object value, SecretType secretType, Object parent) in /_/src/Aspire.Hosting.Azure.AppContainers/BaseContainerAppContext.cs:line 284
at Aspire.Hosting.Azure.BaseContainerAppContext.AddEnvironmentVariablesAndCommandLineArgs(ContainerAppContainer container, Func`1 getContainerAppConfigurationSecrets, BicepValue`1 containerAppIdentityId) in /_/src/Aspire.Hosting.Azure.AppContainers/BaseContainerAppContext.cs:line 363
at Aspire.Hosting.Azure.ContainerAppJobContext.BuildContainerApp(AzureResourceInfrastructure infra) in /_/src/Aspire.Hosting.Azure.AppContainers/ContainerAppJobContext.cs:line 70
at Aspire.Hosting.Azure.AzureProvisioningResource.GetBicepTemplateFile(String directory, Boolean deleteTemporaryFileOnDispose) in /_/src/Aspire.Hosting.Azure/AzureProvisioningResource.cs:line 79
at Aspire.Hosting.Azure.AzureBicepResource.WriteToManifest(ManifestPublishingContext context) in /_/src/Aspire.Hosting.Azure/AzureBicepResource.cs:line 160
at Aspire.Hosting.ApplicationModel.ManifestPublishingCallbackAnnotation.<>c__DisplayClass0_0.<.ctor>b__0(ManifestPublishingContext context) in /_/src/Aspire.Hosting/ApplicationModel/ManifestPublishingCallbackAnnotation.cs:line 23
at Aspire.Hosting.Publishing.ManifestPublishingContext.WriteDeploymentTarget(DeploymentTargetAnnotation deploymentTarget) in /_/src/Aspire.Hosting/Publishing/ManifestPublishingContext.cs:line 188
at Aspire.Hosting.Publishing.ManifestPublishingContext.WriteProjectAsync(ProjectResource project) in /_/src/Aspire.Hosting/Publishing/ManifestPublishingContext.cs:line 172
at Aspire.Hosting.Publishing.ManifestPublishingContext.<>c__DisplayClass20_0.<g__WriteResourceObjectAsync|1>d`1.MoveNext() in /_/src/Aspire.Hosting/Publishing/ManifestPublishingContext.cs:line 129
--- End of stack trace from previous location ---
at Aspire.Hosting.Publishing.ManifestPublishingContext.WriteResourceAsync(IResource resource) in /_/src/Aspire.Hosting/Publishing/ManifestPublishingContext.cs:line 107
at Aspire.Hosting.Publishing.ManifestPublishingContext.WriteModel(DistributedApplicationModel model, CancellationToken cancellationToken) in /_/src/Aspire.Hosting/Publishing/ManifestPublishingContext.cs:line 79
at Aspire.Hosting.Publishing.ManifestPublisher.WriteManifestAsync(DistributedApplicationModel model, Utf8JsonWriter jsonWriter, CancellationToken cancellationToken) in /_/src/Aspire.Hosting/Publishing/ManifestPublisher.cs:line 67
at Aspire.Hosting.Publishing.ManifestPublisher.PublishInternalAsync(DistributedApplicationModel model, CancellationToken cancellationToken) in /_/src/Aspire.Hosting/Publishing/ManifestPublisher.cs:line 55
at Aspire.Hosting.Publishing.ManifestPublisher.PublishAsync(DistributedApplicationModel model, CancellationToken cancellationToken) in /_/src/Aspire.Hosting/Publishing/ManifestPublisher.cs:line 23
at Aspire.Hosting.DistributedApplicationRunner.ExecuteAsync(CancellationToken stoppingToken) in /_/src/Aspire.Hosting/DistributedApplicationRunner.cs:line 41
```
The issue is that since the `launchSettings.json` file has kestrel settings, the `https` and `http` endoints are getting injected on the project. This causes problems down the line because we create endpoints, but since Container App Jobs don't support ingress, things get messed up.
We could fix this in `PublishAsAzureContainerAppJob` by filtering out the `http` and `https` endpoints using the `WithEndpointsInEnvironment` method to add a filter.
Another option to fix this would be in the ContainerAppJobContext code, basically skipping over endpoint reference. But this feels less correct, since it is really an error to make these endpoints in the first place.
Another thought is to add validation up front and fail if an ACA Container App Job has `http` or `https` endpoints. This would make the error condition better, but users would still be confused at why the endpoints are being created in the first place (a misconfigured launchSettings.json file).
Thoughts on how to proceed on this? @mitchdenny @davidfowl @DamianEdwards
Contributor guide
Assessment
This issue has not been assessed yet.