-
Notifications
You must be signed in to change notification settings - Fork 863
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Skeleton app for containerization (#2710)
* Skeleton app for containerization * Add AddServiceDiscovery * Fixes
- Loading branch information
1 parent
f9f2236
commit 093ed77
Showing
9 changed files
with
181 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,43 @@ | ||
<Project> | ||
<Import Sdk="Microsoft.NET.Sdk" Project="Sdk.props" /> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net9.0</TargetFramework> | ||
<IsPackable>true</IsPackable> | ||
<SuppressDependenciesWhenPacking>true</SuppressDependenciesWhenPacking> | ||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> | ||
<IncludeBuildOutput>false</IncludeBuildOutput> | ||
<PackageOutputPath Condition=" '$(PackageOutputPath)' == '' ">$(ArtifactsShippingPackagesDir)</PackageOutputPath> | ||
<YarpAppArtifactsOutputDir>$([MSBuild]::NormalizeDirectory('$(ArtifactsDir)', 'YarpAppArtifacts', '$(Configuration)'))</YarpAppArtifactsOutputDir> | ||
|
||
</PropertyGroup> | ||
|
||
<PropertyGroup> | ||
<PackageId>Yarp.Application.$(YarpAppRuntime)</PackageId> | ||
<Description>Reverse proxy</Description> | ||
</PropertyGroup> | ||
|
||
<Import Sdk="Microsoft.NET.Sdk" Project="Sdk.targets" /> | ||
|
||
<Target Name="Build" /> | ||
|
||
<Target Name="BeforeBuild" BeforeTargets="Build"> | ||
<MSBuild Projects="../../src/Application/Yarp.Application.csproj" Targets="publish" Properties="Configuration=$(Configuration);Platform=$(Platform);TargetFramework=$(TargetFramework);RuntimeIdentifier=$(YarpAppRuntime)" /> | ||
|
||
<!-- After publishing the project, we ensure that the published assets get packed in the nuspec. --> | ||
<ItemGroup> | ||
<_PublishItems Include="$(ArtifactsBinDir)/Yarp.Application/$(Configuration)/$(TargetFramework)/$(YarpAppRuntime)/publish/**/*" /> | ||
<None Include="@(_PublishItems)" Pack="true" PackagePath="tools/" /> | ||
</ItemGroup> | ||
|
||
<MakeDir Directories="$(YarpAppArtifactsOutputDir)/$(YarpAppRuntime)" /> | ||
<ZipDirectory | ||
SourceDirectory="$(ArtifactsBinDir)/Yarp.Application/$(Configuration)/$(TargetFramework)/$(YarpAppRuntime)/publish" | ||
DestinationFile="$(YarpAppArtifactsOutputDir)/$(YarpAppRuntime)/reverse-proxy-$(YarpAppRuntime).zip" | ||
Overwrite="true" /> | ||
|
||
<!-- Throw an error if _PublishItems is empty. --> | ||
<Error Condition="'@(_PublishItems)' == ''" Text="No files were found to pack. Ensure that the project being packed has a publish target defined." /> | ||
</Target> | ||
|
||
</Project> |
This file contains 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,10 @@ | ||
<Project> | ||
|
||
<PropertyGroup> | ||
<YarpAppRuntime>linux-arm64</YarpAppRuntime> | ||
<YarpAppPlatformType>Unix</YarpAppPlatformType> | ||
</PropertyGroup> | ||
|
||
<Import Project="Common.projitems" /> | ||
|
||
</Project> |
This file contains 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,10 @@ | ||
<Project> | ||
|
||
<PropertyGroup> | ||
<YarpAppRuntime>linux-x64</YarpAppRuntime> | ||
<YarpAppPlatformType>Unix</YarpAppPlatformType> | ||
</PropertyGroup> | ||
|
||
<Import Project="Common.projitems" /> | ||
|
||
</Project> |
This file contains 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 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,36 @@ | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
|
||
// Load configuration | ||
if (args.Length != 1) | ||
{ | ||
Console.Error.WriteLine("Usage: yarp.exe <config_file>"); | ||
return 1; | ||
} | ||
var configFile = args[0]; | ||
var fileInfo = new FileInfo(configFile); | ||
if (!fileInfo.Exists) | ||
{ | ||
Console.Error.WriteLine($"Could not find '{configFile}'."); | ||
return 2; | ||
} | ||
|
||
var builder = WebApplication.CreateBuilder(); | ||
builder.Configuration.AddJsonFile(fileInfo.FullName, optional: false, reloadOnChange: true); | ||
|
||
// Configure YARP | ||
builder.Services.AddServiceDiscovery(); | ||
builder.Services.AddReverseProxy() | ||
.LoadFromConfig(builder.Configuration.GetSection("ReverseProxy")) | ||
.AddServiceDiscoveryDestinationResolver(); | ||
|
||
Console.WriteLine(builder.Configuration.GetSection("ReverseProxy").Value); | ||
|
||
var app = builder.Build(); | ||
app.MapReverseProxy(); | ||
|
||
await app.RunAsync(); | ||
|
||
return 0; |
This file contains 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,21 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<RuntimeIdentifiers>win-x64;win-arm64;linux-x64;linux-arm64;</RuntimeIdentifiers> | ||
<TargetFrameworks>net8.0;net9.0</TargetFrameworks> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<AssemblyName>yarp</AssemblyName> | ||
</PropertyGroup> | ||
|
||
<!-- Used by publishing infrastructure to get the version to use for blob publishing --> | ||
<Target Name="ReturnPackageVersion" Returns="$(PackageVersion)" /> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Yarp.ReverseProxy" Version="$(YarpNugetVersion)" /> | ||
<PackageReference Include="Microsoft.Extensions.ServiceDiscovery" Version="$(MicrosoftExtensionsServiceDiscovery)" /> | ||
<PackageReference Include="Microsoft.Extensions.ServiceDiscovery.Yarp" Version="$(MicrosoftExtensionsServiceDiscoveryYarp)" /> | ||
</ItemGroup> | ||
|
||
</Project> |