-
Notifications
You must be signed in to change notification settings - Fork 720
Add YARP container support #8856
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
16e8774
Simple YARP container integration
benjaminpetit 20421f3
Use WithContainerFiles instead
benjaminpetit f4dad75
Revert not needed change
benjaminpetit 928f461
Add README content
benjaminpetit e776f80
Merge remote-tracking branch 'origin/main' into yarp-container
benjaminpetit 81c8853
Move some stuff
benjaminpetit a524d72
Add some explanations
benjaminpetit c23cba8
More small modifications
benjaminpetit 1e303f3
Fix bad merge
benjaminpetit 289499f
Update Aspire.Hosting.Yarp.csproj
mitchdenny 01b7e54
Merge branch 'main' of https://github.com/dotnet/aspire into yarp-con…
benjaminpetit ad87b8d
Make YarpResource.ConfigFilePath internal
benjaminpetit 685fda5
Use builder.ExecutionContext.IsRunMode instead
benjaminpetit cec8dbb
Remove unnecessary using directive
benjaminpetit 632c960
Add basic functional test
benjaminpetit 7a11cf2
Merge branch 'main' of https://github.com/dotnet/aspire into yarp-con…
benjaminpetit db654f7
Add WithHttpHealthCheck in test
benjaminpetit a23dc9b
Merge branch 'main' of https://github.com/dotnet/aspire into yarp-con…
benjaminpetit 23f5c65
Add more tests
benjaminpetit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
playground/TestShop/TestShop.AppHost/appsettings.Development.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| "Logging": { | ||
| "LogLevel": { | ||
| "Default": "Information", | ||
| "Microsoft.AspNetCore": "Warning" | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -65,3 +65,4 @@ urls | |
| kubernetes | ||
| Pgweb | ||
| elasticsearch | ||
| Yarp | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| <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> | ||
| <SuppressFinalPackageVersion>true</SuppressFinalPackageVersion> | ||
| </PropertyGroup> | ||
|
|
||
| <PropertyGroup> | ||
| <MinCodeCoverage>0</MinCodeCoverage> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\Aspire.Hosting\Aspire.Hosting.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| # Aspire.Hosting.Yarp library | ||
|
|
||
| Provides extension methods and resource definitions for a .NET Aspire AppHost to configure a YARP instance. | ||
|
|
||
| ## Getting started | ||
|
|
||
| ### Install the package | ||
|
|
||
| In your AppHost project, install the .NET Aspire YARP Hosting library with [NuGet](https://www.nuget.org): | ||
|
|
||
| ```dotnetcli | ||
| dotnet add package Aspire.Hosting.Yarp | ||
| ``` | ||
|
|
||
| ## Usage example | ||
|
|
||
| Then, in the _Program.cs_ file of `AppHost`, add a YARP resource and provide the configuration file using the following methods: | ||
|
|
||
| ```csharp | ||
| var catalogService = builder.AddProject<Projects.CatalogService>("catalogservice") | ||
| [...]; | ||
| var basketService = builder.AddProject<Projects.BasketService>("basketservice") | ||
| [...]; | ||
|
|
||
| builder.AddYarp("apigateway") | ||
| .WithConfigFile("yarp.json") | ||
| .WithReference(basketService) | ||
| .WithReference(catalogService); | ||
| ``` | ||
|
|
||
| The `yarp.json` configuration file can use the referenced service like this: | ||
|
|
||
| ```json | ||
| { | ||
| "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", | ||
| } | ||
| } | ||
| }, | ||
| "basket": { | ||
| "Destinations": { | ||
| "basket": { | ||
| "Address": "http://basketservice", | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
benjaminpetit marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ``` | ||
|
|
||
| ## Additional documentation | ||
|
|
||
| * https://learn.microsoft.com/dotnet/aspire/caching/stackexchange-redis-component | ||
| * https://learn.microsoft.com/dotnet/aspire/caching/stackexchange-redis-output-caching-component | ||
| * https://learn.microsoft.com/dotnet/aspire/caching/stackexchange-redis-distributed-caching-component | ||
|
|
||
| ## Feedback & contributing | ||
|
|
||
| https://github.com/dotnet/aspire | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| // 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 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems like the other ones all have tags for each of these. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> | ||
| internal string? ConfigFilePath { get; set; } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.