Skip to content

Commit 093ed77

Browse files
Skeleton app for containerization (dotnet#2710)
* Skeleton app for containerization * Add AddServiceDiscovery * Fixes
1 parent f9f2236 commit 093ed77

File tree

9 files changed

+181
-0
lines changed

9 files changed

+181
-0
lines changed

eng/Build.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<ProjectToBuild Include="$(RepoRoot)test\**\*.csproj" />
66
<ProjectToBuild Include="$(RepoRoot)samples\**\*.csproj" />
77
<ProjectToBuild Include="$(RepoRoot)testassets\**\*.csproj" />
8+
<ProjectToBuild Include="$(RepoRoot)eng\yarpapppack\**\*.csproj" />
89
<ProjectToBuild Include="$(RepoRoot)docs\docfx\docfx.csproj" Condition="'$(OS)' == 'Windows_NT'" />
910
</ItemGroup>
1011
</Project>

eng/Publishing.props

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,48 @@
33
<PropertyGroup>
44
<PublishingVersion>3</PublishingVersion>
55
</PropertyGroup>
6+
7+
<PropertyGroup>
8+
<_UploadPathRoot>reverse-proxy</_UploadPathRoot>
9+
</PropertyGroup>
10+
11+
<PropertyGroup>
12+
<PublishDependsOnTargets>$(PublishDependsOnTargets);_PublishBlobItems</PublishDependsOnTargets>
13+
14+
<!-- NOTE: This property is also defined on the root-level Directory.Build.props, but that file is not imported by the Publishing project.
15+
Pulling it in here will cause different issues as that file will conflict with Arcade's publishing logic, so as a workaround we define it here.
16+
If you are editing this property, make sure to also edit the one in Directory.Build.props. -->
17+
<YarpAppArtifactsOutputDir>$([MSBuild]::NormalizeDirectory('$(ArtifactsDir)',
18+
'YarpAppArtifacts', '$(Configuration)'))</YarpAppArtifactsOutputDir>
19+
</PropertyGroup>
20+
21+
<ItemGroup>
22+
<_YarpAppFilesToPublish Include="$(YarpAppArtifactsOutputDir)\**\*.zip" />
23+
</ItemGroup>
24+
25+
<Target Name="_PublishBlobItems">
26+
<!--
27+
For blob items, we want to make sure that the version we get back is not stable, even when the repo
28+
is producing stable versions.
29+
This is because we want to be able to re-spin the build if necessary without hitting issues of blob
30+
items clashing with each other. For this reason,
31+
We will pass SuppressFinalPackageVersion as true when fetching the package version so that we get
32+
back a version with a prerelease suffix.
33+
-->
34+
<MSBuild Projects="$(RepoRoot)src\Application\Yarp.Application.csproj"
35+
Targets="ReturnPackageVersion"
36+
SkipNonexistentProjects="false"
37+
Properties="SuppressFinalPackageVersion=true">
38+
<Output TaskParameter="TargetOutputs" PropertyName="_PackageVersion" />
39+
</MSBuild>
40+
41+
<ItemGroup>
42+
<ItemsToPushToBlobFeed Include="@(_YarpAppFilesToPublish)">
43+
<IsShipping>true</IsShipping>
44+
<PublishFlatContainer>true</PublishFlatContainer>
45+
<RelativeBlobPath>$(_UploadPathRoot)/$(_PackageVersion)/%(Filename)%(Extension)</RelativeBlobPath>
46+
</ItemsToPushToBlobFeed>
47+
</ItemGroup>
48+
</Target>
49+
650
</Project>

eng/Versions.props

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<SystemCollectionsImmutableVersion>8.0.0</SystemCollectionsImmutableVersion>
1616
<SystemIOHashingVersion>8.0.0</SystemIOHashingVersion>
1717
<MicrosoftBclTimeProviderVersion>8.0.0</MicrosoftBclTimeProviderVersion>
18+
<MicrosoftDotNetXUnitExtensionsPackageVersion>10.0.0-beta.24613.2</MicrosoftDotNetXUnitExtensionsPackageVersion>
1819
<MicrosoftAspNetCoreTestHostVersion>6.0.36</MicrosoftAspNetCoreTestHostVersion>
1920
<MicrosoftCrankEventSourcesVersion>0.2.0-alpha.24576.2</MicrosoftCrankEventSourcesVersion>
2021
<MicrosoftDotNetXUnitExtensionsPackageVersion>10.0.0-beta.25056.1</MicrosoftDotNetXUnitExtensionsPackageVersion>
@@ -33,5 +34,9 @@
3334
<DocfxConsoleVersion>2.59.4</DocfxConsoleVersion>
3435
<YamlDotNetVersion>16.2.1</YamlDotNetVersion>
3536
<KubernetesClientVersion>15.0.1</KubernetesClientVersion>
37+
<!-- Container app dependencies -->
38+
<YarpNugetVersion>2.2.0</YarpNugetVersion>
39+
<MicrosoftExtensionsServiceDiscovery>8.2.2</MicrosoftExtensionsServiceDiscovery>
40+
<MicrosoftExtensionsServiceDiscoveryYarp>8.2.2</MicrosoftExtensionsServiceDiscoveryYarp>
3641
</PropertyGroup>
3742
</Project>

eng/yarpapppack/Common.projitems

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<Project>
2+
<Import Sdk="Microsoft.NET.Sdk" Project="Sdk.props" />
3+
4+
<PropertyGroup>
5+
<TargetFramework>net9.0</TargetFramework>
6+
<IsPackable>true</IsPackable>
7+
<SuppressDependenciesWhenPacking>true</SuppressDependenciesWhenPacking>
8+
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
9+
<IncludeBuildOutput>false</IncludeBuildOutput>
10+
<PackageOutputPath Condition=" '$(PackageOutputPath)' == '' ">$(ArtifactsShippingPackagesDir)</PackageOutputPath>
11+
<YarpAppArtifactsOutputDir>$([MSBuild]::NormalizeDirectory('$(ArtifactsDir)', 'YarpAppArtifacts', '$(Configuration)'))</YarpAppArtifactsOutputDir>
12+
13+
</PropertyGroup>
14+
15+
<PropertyGroup>
16+
<PackageId>Yarp.Application.$(YarpAppRuntime)</PackageId>
17+
<Description>Reverse proxy</Description>
18+
</PropertyGroup>
19+
20+
<Import Sdk="Microsoft.NET.Sdk" Project="Sdk.targets" />
21+
22+
<Target Name="Build" />
23+
24+
<Target Name="BeforeBuild" BeforeTargets="Build">
25+
<MSBuild Projects="../../src/Application/Yarp.Application.csproj" Targets="publish" Properties="Configuration=$(Configuration);Platform=$(Platform);TargetFramework=$(TargetFramework);RuntimeIdentifier=$(YarpAppRuntime)" />
26+
27+
<!-- After publishing the project, we ensure that the published assets get packed in the nuspec. -->
28+
<ItemGroup>
29+
<_PublishItems Include="$(ArtifactsBinDir)/Yarp.Application/$(Configuration)/$(TargetFramework)/$(YarpAppRuntime)/publish/**/*" />
30+
<None Include="@(_PublishItems)" Pack="true" PackagePath="tools/" />
31+
</ItemGroup>
32+
33+
<MakeDir Directories="$(YarpAppArtifactsOutputDir)/$(YarpAppRuntime)" />
34+
<ZipDirectory
35+
SourceDirectory="$(ArtifactsBinDir)/Yarp.Application/$(Configuration)/$(TargetFramework)/$(YarpAppRuntime)/publish"
36+
DestinationFile="$(YarpAppArtifactsOutputDir)/$(YarpAppRuntime)/reverse-proxy-$(YarpAppRuntime).zip"
37+
Overwrite="true" />
38+
39+
<!-- Throw an error if _PublishItems is empty. -->
40+
<Error Condition="'@(_PublishItems)' == ''" Text="No files were found to pack. Ensure that the project being packed has a publish target defined." />
41+
</Target>
42+
43+
</Project>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Project>
2+
3+
<PropertyGroup>
4+
<YarpAppRuntime>linux-arm64</YarpAppRuntime>
5+
<YarpAppPlatformType>Unix</YarpAppPlatformType>
6+
</PropertyGroup>
7+
8+
<Import Project="Common.projitems" />
9+
10+
</Project>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Project>
2+
3+
<PropertyGroup>
4+
<YarpAppRuntime>linux-x64</YarpAppRuntime>
5+
<YarpAppPlatformType>Unix</YarpAppPlatformType>
6+
</PropertyGroup>
7+
8+
<Import Project="Common.projitems" />
9+
10+
</Project>

reverse-proxy.sln

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Prometheus", "Prometheus",
100100
EndProject
101101
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HttpLoadApp", "samples\Prometheus\HttpLoadApp\HttpLoadApp.csproj", "{BD73A038-8F3D-4BB2-A5C4-C8D077969DED}"
102102
EndProject
103+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yarp.Application", "src\Application\Yarp.Application.csproj", "{B63DDC4F-DA04-4B03-BF82-302FB3A954D7}"
104+
EndProject
103105
Global
104106
GlobalSection(SolutionConfigurationPlatforms) = preSolution
105107
Debug|Any CPU = Debug|Any CPU
@@ -364,6 +366,14 @@ Global
364366
{BD73A038-8F3D-4BB2-A5C4-C8D077969DED}.Release|Any CPU.Build.0 = Release|Any CPU
365367
{BD73A038-8F3D-4BB2-A5C4-C8D077969DED}.Release|x64.ActiveCfg = Release|Any CPU
366368
{BD73A038-8F3D-4BB2-A5C4-C8D077969DED}.Release|x64.Build.0 = Release|Any CPU
369+
{B63DDC4F-DA04-4B03-BF82-302FB3A954D7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
370+
{B63DDC4F-DA04-4B03-BF82-302FB3A954D7}.Debug|Any CPU.Build.0 = Debug|Any CPU
371+
{B63DDC4F-DA04-4B03-BF82-302FB3A954D7}.Debug|x64.ActiveCfg = Debug|Any CPU
372+
{B63DDC4F-DA04-4B03-BF82-302FB3A954D7}.Debug|x64.Build.0 = Debug|Any CPU
373+
{B63DDC4F-DA04-4B03-BF82-302FB3A954D7}.Release|Any CPU.ActiveCfg = Release|Any CPU
374+
{B63DDC4F-DA04-4B03-BF82-302FB3A954D7}.Release|Any CPU.Build.0 = Release|Any CPU
375+
{B63DDC4F-DA04-4B03-BF82-302FB3A954D7}.Release|x64.ActiveCfg = Release|Any CPU
376+
{B63DDC4F-DA04-4B03-BF82-302FB3A954D7}.Release|x64.Build.0 = Release|Any CPU
367377
EndGlobalSection
368378
GlobalSection(SolutionProperties) = preSolution
369379
HideSolutionNode = FALSE
@@ -407,6 +417,7 @@ Global
407417
{AC0EF892-7D32-4EAF-BE99-3696181E889F} = {149C61A2-D9F8-49B9-9F9B-3C953FEF53AA}
408418
{78A83196-53F3-444B-84BF-F0FDC2CD0466} = {149C61A2-D9F8-49B9-9F9B-3C953FEF53AA}
409419
{BD73A038-8F3D-4BB2-A5C4-C8D077969DED} = {78A83196-53F3-444B-84BF-F0FDC2CD0466}
420+
{B63DDC4F-DA04-4B03-BF82-302FB3A954D7} = {6CBE18D4-64E9-492B-BB02-58CD57126C10}
410421
EndGlobalSection
411422
GlobalSection(ExtensibilityGlobals) = postSolution
412423
SolutionGuid = {31F6924A-E427-4830-96E9-B47CEB7BFE78}

src/Application/Program.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using Microsoft.AspNetCore.Builder;
2+
using Microsoft.Extensions.Configuration;
3+
using Microsoft.Extensions.DependencyInjection;
4+
using Microsoft.Extensions.Hosting;
5+
6+
// Load configuration
7+
if (args.Length != 1)
8+
{
9+
Console.Error.WriteLine("Usage: yarp.exe <config_file>");
10+
return 1;
11+
}
12+
var configFile = args[0];
13+
var fileInfo = new FileInfo(configFile);
14+
if (!fileInfo.Exists)
15+
{
16+
Console.Error.WriteLine($"Could not find '{configFile}'.");
17+
return 2;
18+
}
19+
20+
var builder = WebApplication.CreateBuilder();
21+
builder.Configuration.AddJsonFile(fileInfo.FullName, optional: false, reloadOnChange: true);
22+
23+
// Configure YARP
24+
builder.Services.AddServiceDiscovery();
25+
builder.Services.AddReverseProxy()
26+
.LoadFromConfig(builder.Configuration.GetSection("ReverseProxy"))
27+
.AddServiceDiscoveryDestinationResolver();
28+
29+
Console.WriteLine(builder.Configuration.GetSection("ReverseProxy").Value);
30+
31+
var app = builder.Build();
32+
app.MapReverseProxy();
33+
34+
await app.RunAsync();
35+
36+
return 0;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<RuntimeIdentifiers>win-x64;win-arm64;linux-x64;linux-arm64;</RuntimeIdentifiers>
6+
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<Nullable>enable</Nullable>
9+
<AssemblyName>yarp</AssemblyName>
10+
</PropertyGroup>
11+
12+
<!-- Used by publishing infrastructure to get the version to use for blob publishing -->
13+
<Target Name="ReturnPackageVersion" Returns="$(PackageVersion)" />
14+
15+
<ItemGroup>
16+
<PackageReference Include="Yarp.ReverseProxy" Version="$(YarpNugetVersion)" />
17+
<PackageReference Include="Microsoft.Extensions.ServiceDiscovery" Version="$(MicrosoftExtensionsServiceDiscovery)" />
18+
<PackageReference Include="Microsoft.Extensions.ServiceDiscovery.Yarp" Version="$(MicrosoftExtensionsServiceDiscoveryYarp)" />
19+
</ItemGroup>
20+
21+
</Project>

0 commit comments

Comments
 (0)