Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 15 additions & 16 deletions Aspire.sln
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
Expand All @@ -21,8 +20,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CatalogService", "playgroun
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BasketService", "playground\TestShop\BasketService\BasketService.csproj", "{3FC74EA6-D554-4A87-AED5-A08FE407BBF4}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ApiGateway", "playground\TestShop\ApiGateway\ApiGateway.csproj", "{934625C7-243F-4659-9421-515301CF0263}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Aspire.StackExchange.Redis", "src\Components\Aspire.StackExchange.Redis\Aspire.StackExchange.Redis.csproj", "{7D4A7A84-B297-4777-9E2A-D8B1C427CAC7}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Components", "Components", "{27381127-6C45-4B4C-8F18-41FF48DFE4B2}"
Expand Down Expand Up @@ -675,6 +672,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aspire.Azure.Npgsql.EntityF
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aspire.Components.Common.Tests", "tests\Aspire.Components.Common.Tests\Aspire.Components.Common.Tests.csproj", "{30950CEB-2232-F9FC-04FF-ADDCB8AC30A7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aspire.Hosting.Yarp", "src\Aspire.Hosting.Yarp\Aspire.Hosting.Yarp.csproj", "{A3399DE9-AAB0-43EA-B99B-6A62ABBDD7BF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -745,18 +744,6 @@ Global
{3FC74EA6-D554-4A87-AED5-A08FE407BBF4}.Release|x64.Build.0 = Release|Any CPU
{3FC74EA6-D554-4A87-AED5-A08FE407BBF4}.Release|x86.ActiveCfg = Release|Any CPU
{3FC74EA6-D554-4A87-AED5-A08FE407BBF4}.Release|x86.Build.0 = Release|Any CPU
{934625C7-243F-4659-9421-515301CF0263}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{934625C7-243F-4659-9421-515301CF0263}.Debug|Any CPU.Build.0 = Debug|Any CPU
{934625C7-243F-4659-9421-515301CF0263}.Debug|x64.ActiveCfg = Debug|Any CPU
{934625C7-243F-4659-9421-515301CF0263}.Debug|x64.Build.0 = Debug|Any CPU
{934625C7-243F-4659-9421-515301CF0263}.Debug|x86.ActiveCfg = Debug|Any CPU
{934625C7-243F-4659-9421-515301CF0263}.Debug|x86.Build.0 = Debug|Any CPU
{934625C7-243F-4659-9421-515301CF0263}.Release|Any CPU.ActiveCfg = Release|Any CPU
{934625C7-243F-4659-9421-515301CF0263}.Release|Any CPU.Build.0 = Release|Any CPU
{934625C7-243F-4659-9421-515301CF0263}.Release|x64.ActiveCfg = Release|Any CPU
{934625C7-243F-4659-9421-515301CF0263}.Release|x64.Build.0 = Release|Any CPU
{934625C7-243F-4659-9421-515301CF0263}.Release|x86.ActiveCfg = Release|Any CPU
{934625C7-243F-4659-9421-515301CF0263}.Release|x86.Build.0 = Release|Any CPU
{7D4A7A84-B297-4777-9E2A-D8B1C427CAC7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7D4A7A84-B297-4777-9E2A-D8B1C427CAC7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7D4A7A84-B297-4777-9E2A-D8B1C427CAC7}.Debug|x64.ActiveCfg = Debug|Any CPU
Expand Down Expand Up @@ -3961,6 +3948,18 @@ Global
{30950CEB-2232-F9FC-04FF-ADDCB8AC30A7}.Release|x64.Build.0 = Release|Any CPU
{30950CEB-2232-F9FC-04FF-ADDCB8AC30A7}.Release|x86.ActiveCfg = Release|Any CPU
{30950CEB-2232-F9FC-04FF-ADDCB8AC30A7}.Release|x86.Build.0 = Release|Any CPU
{A3399DE9-AAB0-43EA-B99B-6A62ABBDD7BF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A3399DE9-AAB0-43EA-B99B-6A62ABBDD7BF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A3399DE9-AAB0-43EA-B99B-6A62ABBDD7BF}.Debug|x64.ActiveCfg = Debug|Any CPU
{A3399DE9-AAB0-43EA-B99B-6A62ABBDD7BF}.Debug|x64.Build.0 = Debug|Any CPU
{A3399DE9-AAB0-43EA-B99B-6A62ABBDD7BF}.Debug|x86.ActiveCfg = Debug|Any CPU
{A3399DE9-AAB0-43EA-B99B-6A62ABBDD7BF}.Debug|x86.Build.0 = Debug|Any CPU
{A3399DE9-AAB0-43EA-B99B-6A62ABBDD7BF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A3399DE9-AAB0-43EA-B99B-6A62ABBDD7BF}.Release|Any CPU.Build.0 = Release|Any CPU
{A3399DE9-AAB0-43EA-B99B-6A62ABBDD7BF}.Release|x64.ActiveCfg = Release|Any CPU
{A3399DE9-AAB0-43EA-B99B-6A62ABBDD7BF}.Release|x64.Build.0 = Release|Any CPU
{A3399DE9-AAB0-43EA-B99B-6A62ABBDD7BF}.Release|x86.ActiveCfg = Release|Any CPU
{A3399DE9-AAB0-43EA-B99B-6A62ABBDD7BF}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -3971,7 +3970,6 @@ Global
{C7B2309C-073A-4552-A508-A69768B64C6F} = {A68BA1A5-1604-433D-9778-DC0199831C2A}
{6D04BB34-1CC6-4FF3-A02A-1FFAC2A7A4F3} = {A68BA1A5-1604-433D-9778-DC0199831C2A}
{3FC74EA6-D554-4A87-AED5-A08FE407BBF4} = {A68BA1A5-1604-433D-9778-DC0199831C2A}
{934625C7-243F-4659-9421-515301CF0263} = {A68BA1A5-1604-433D-9778-DC0199831C2A}
{7D4A7A84-B297-4777-9E2A-D8B1C427CAC7} = {27381127-6C45-4B4C-8F18-41FF48DFE4B2}
{145E569B-633F-4FF0-B273-CB1D3B49B9F2} = {63BB22D3-0FAC-4E87-BF9D-9FA2441684C9}
{7570F683-EB48-467F-B1B1-70FF0153F52B} = {63BB22D3-0FAC-4E87-BF9D-9FA2441684C9}
Expand Down Expand Up @@ -4285,6 +4283,7 @@ Global
{192747A2-9338-DECF-5C8C-28EB8E13829B} = {27381127-6C45-4B4C-8F18-41FF48DFE4B2}
{8FCA0CFA-7823-6A2F-342A-107A994915B0} = {C424395C-1235-41A4-BF55-07880A04368C}
{30950CEB-2232-F9FC-04FF-ADDCB8AC30A7} = {C424395C-1235-41A4-BF55-07880A04368C}
{A3399DE9-AAB0-43EA-B99B-6A62ABBDD7BF} = {B80354C7-BE58-43F6-8928-9F3A74AB7F47}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {47DCFECF-5631-4BDE-A1EC-BE41E90F60C4}
Expand Down
5 changes: 3 additions & 2 deletions playground/TestShop/TestShop.AppHost/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@
builder.AddProject<Projects.OrderProcessor>("orderprocessor", launchProfileName: "OrderProcessor")
.WithReference(messaging).WaitFor(messaging);

builder.AddProject<Projects.ApiGateway>("apigateway")
builder.AddYarp("apigateway")
.WithConfigFile("yarp.json")
.WithReference(basketService)
.WithReference(catalogService);

Expand All @@ -89,7 +90,7 @@
// dashboard launch experience, Refer to Directory.Build.props for the path to
// the dashboard binary (defaults to the Aspire.Dashboard bin output in the
// artifacts dir).
builder.AddProject<Projects.Aspire_Dashboard>(KnownResourceNames.AspireDashboard);
//builder.AddProject<Projects.Aspire_Dashboard>(KnownResourceNames.AspireDashboard);
#endif

builder.Build().Run();
3 changes: 1 addition & 2 deletions playground/TestShop/TestShop.AppHost/TestShop.AppHost.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
<AspireProjectOrPackageReference Include="Aspire.Hosting.RabbitMQ" />
<AspireProjectOrPackageReference Include="Aspire.Hosting.Redis" />
<AspireProjectOrPackageReference Include="Aspire.Hosting.PostgreSQL" />

<ProjectReference Include="..\ApiGateway\ApiGateway.csproj" />
<AspireProjectOrPackageReference Include="Aspire.Hosting.Yarp" />
<ProjectReference Include="..\BasketService\BasketService.csproj" />
<ProjectReference Include="..\CatalogDb\CatalogDb.csproj" />
<ProjectReference Include="..\CatalogService\CatalogService.csproj" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
49 changes: 49 additions & 0 deletions playground/TestShop/TestShop.AppHost/yarp.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Information"
}
},
"AllowedHosts": "*",
"ReverseProxy": {
"Routes": {
"catalog": {
"ClusterId": "catalog",
"Match": {
"Path": "/catalog/{**catch-all}"
},
"Transforms": [
{ "PathRemovePrefix": "/catalog" }
]
},
"basket": {
"ClusterId": "basket",
"Match": {
"Path": "/basket/{**catch-all}"
},
"Transforms": [
{ "PathRemovePrefix": "/basket" }
]
}
},
"Clusters": {
"catalog": {
"Destinations": {
"catalog": {
"Address": "http://catalogservice",
"Health": "http://catalogservice/readiness"
}
}
},
"basket": {
"Destinations": {
"basket": {
"Address": "http://basketservice",
"Health": "http://basketservice/readiness"
}
}
}
}
}
}
1 change: 1 addition & 0 deletions spelling.dic
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,4 @@ urls
kubernetes
Pgweb
elasticsearch
Yarp
File renamed without changes.
19 changes: 19 additions & 0 deletions src/Aspire.Hosting.Yarp/Aspire.Hosting.Yarp.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>$(DefaultTargetFramework)</TargetFramework>
<IsPackable>true</IsPackable>
<PackageTags>aspire integration hosting yarp reverse-proxy</PackageTags>
<Description>YARP support for .NET Aspire.</Description>
<EnablePackageValidation>false</EnablePackageValidation>
</PropertyGroup>

<PropertyGroup>
<MinCodeCoverage>0</MinCodeCoverage>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Aspire.Hosting\Aspire.Hosting.csproj" />
</ItemGroup>

</Project>
2 changes: 2 additions & 0 deletions src/Aspire.Hosting.Yarp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Aspire.Hosting.Yarp library

17 changes: 17 additions & 0 deletions src/Aspire.Hosting.Yarp/YarpContainerImageTags.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace Aspire.Hosting.Yarp;

internal static class YarpContainerImageTags
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the other ones all have tags for each of these.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure to understand?

{
public const string Registry = "mcr.microsoft.com";

public const string Image = "dotnet/nightly/yarp";

public const string Tag = "2-preview";

public const int Port = 5000;

public const string ConfigFilePath = "/etc/yarp.config";
}
18 changes: 18 additions & 0 deletions src/Aspire.Hosting.Yarp/YarpResource.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Aspire.Hosting.ApplicationModel;

namespace Aspire.Hosting.Yarp;

/// <summary>
/// A resource that represents a YARP resource independent of the hosting model.
/// </summary>
/// <param name="name">The name of the resource.</param>
public class YarpResource(string name) : ContainerResource(name)
{
/// <summary>
/// File path of the config file for this YARP resource.
/// </summary>
public string? ConfigFilePath { get; set; }
}
69 changes: 69 additions & 0 deletions src/Aspire.Hosting.Yarp/YarpServiceExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Aspire.Hosting.ApplicationModel;
using Aspire.Hosting.Yarp;
using Microsoft.Extensions.Hosting;

namespace Aspire.Hosting;

/// <summary>
/// Provides extension methods for adding YARP resources to the application model.
/// </summary>
public static class YarpServiceExtensions
{
/// <summary>
/// Adds a YARP container to the application model.
/// </summary>
/// <param name="builder">The <see cref="IDistributedApplicationBuilder"/>.</param>
/// <param name="name">The name of the resource. This name will be used as the connection string name when referenced in a dependency.</param>
/// <returns>A reference to the <see cref="IResourceBuilder{T}"/>.</returns>
public static IResourceBuilder<YarpResource> AddYarp(
this IDistributedApplicationBuilder builder,
[ResourceName] string name)
{
var resource = new YarpResource(name);

var yarpBuilder = builder.AddResource(resource)
.WithHttpEndpoint(targetPort: YarpContainerImageTags.Port)
.WithImage(YarpContainerImageTags.Image)
.WithImageRegistry(YarpContainerImageTags.Registry)
.WithEnvironment("ASPNETCORE_ENVIRONMENT", builder.Environment.EnvironmentName)
.WithOtlpExporter();

if (builder.Environment.IsDevelopment())
{
// YARP will not trust the cert used by aspire otlp endpoint when running locally
yarpBuilder.WithEnvironment("YARP_UNSAFE_OLTP_CERT_ACCEPT_ANY_SERVER_CERTIFICATE", "true");
}

// Map the configuration file
yarpBuilder.ApplicationBuilder.Eventing.Subscribe<AfterEndpointsAllocatedEvent>((e, ct) =>
{
if (yarpBuilder.Resource.ConfigFilePath != null)
{
yarpBuilder.WithBindMount(yarpBuilder.Resource.ConfigFilePath, YarpContainerImageTags.ConfigFilePath, isReadOnly: true);
}
else
{
// TODO: build dynamically the config file if none provided.
throw new DistributedApplicationException($"No configuration provided for YARP instance \"{yarpBuilder.Resource.Name}\"");
}
return Task.CompletedTask;
});

return yarpBuilder;
}

/// <summary>
/// Set explicitly the config file to use for YARP.
/// </summary>
/// <param name="builder">The YARP resource to configure.</param>
/// <param name="configFilePath">The path to the YARP config file.</param>
/// <returns>A reference to the <see cref="IResourceBuilder{T}"/>.</returns>
public static IResourceBuilder<YarpResource> WithConfigFile(this IResourceBuilder<YarpResource> builder, string configFilePath)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this was suggested elsewhere, but would it make sense to be able to define the config in C#? That way someone doesn't have to jump out to a JSON file. But instead something like:

builder.AddYarp("apigateway")
       .WithReference(basketService)
       .WithReference(catalogService)
       .WithConfig(context =>
       {
           context.AddRoute(basketService, "{**catch-all}");
       });

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea but not as a gate for this initial PR

{
builder.Resource.ConfigFilePath = configFilePath;
return builder;
}
}
1 change: 1 addition & 0 deletions tests/Shared/RepoTesting/Directory.Packages.Helix.props
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
<PackageVersion Include="Aspire.Hosting.SqlServer" Version="$(PackageVersion)" />
<PackageVersion Include="Aspire.Hosting.Testing" Version="$(PackageVersion)" />
<PackageVersion Include="Aspire.Hosting.Valkey" Version="$(PackageVersion)" />
<PackageVersion Include="Aspire.Hosting.Yarp" Version="$(PackageVersion)" />

<PackageVersion Include="Aspire.Keycloak.Authentication" Version="$(PackageVersion)" />
<PackageVersion Include="Aspire.Microsoft.Azure.Cosmos" Version="$(PackageVersion)" />
Expand Down
Loading