Skip to content

Commit

Permalink
Add AoT example
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel15 committed Nov 19, 2023
1 parent 24775b1 commit 316558c
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 3 deletions.
12 changes: 9 additions & 3 deletions prometheus-net.SystemMetrics.sln
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29503.13
# Visual Studio Version 17
VisualStudioVersion = 17.8.34309.116
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Prometheus.SystemMetrics", "src\Prometheus.SystemMetrics\Prometheus.SystemMetrics.csproj", "{C65859B3-4125-4594-A6BF-8917C1549E16}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Prometheus.SystemMetrics.Example", "src\Prometheus.SystemMetrics.Example\Prometheus.SystemMetrics.Example.csproj", "{C965DA91-6C2A-4D62-B32C-DA42CA5A6146}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Prometheus.SystemMetrics.Tests", "src\Prometheus.SystemMetrics.Tests\Prometheus.SystemMetrics.Tests.csproj", "{D76966FB-8E1F-40F7-B47B-D2AC03927906}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Prometheus.SystemMetrics.Tests", "src\Prometheus.SystemMetrics.Tests\Prometheus.SystemMetrics.Tests.csproj", "{D76966FB-8E1F-40F7-B47B-D2AC03927906}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Prometheus.SystemMetrics.Example.AOT", "src\Prometheus.SystemMetrics.Example.AOT\Prometheus.SystemMetrics.Example.AOT.csproj", "{FF2F4C3A-A4CF-4ACB-8828-60967517E163}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -27,6 +29,10 @@ Global
{D76966FB-8E1F-40F7-B47B-D2AC03927906}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D76966FB-8E1F-40F7-B47B-D2AC03927906}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D76966FB-8E1F-40F7-B47B-D2AC03927906}.Release|Any CPU.Build.0 = Release|Any CPU
{FF2F4C3A-A4CF-4ACB-8828-60967517E163}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FF2F4C3A-A4CF-4ACB-8828-60967517E163}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FF2F4C3A-A4CF-4ACB-8828-60967517E163}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FF2F4C3A-A4CF-4ACB-8828-60967517E163}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
29 changes: 29 additions & 0 deletions src/Prometheus.SystemMetrics.Example.AOT/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
USER app
WORKDIR /app
EXPOSE 8080

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
# Install clang/zlib1g-dev dependencies for publishing to native
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
clang zlib1g-dev
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["src/Prometheus.SystemMetrics.Example.AOT/Prometheus.SystemMetrics.Example.AOT.csproj", "src/Prometheus.SystemMetrics.Example.AOT/"]
RUN dotnet restore "./src/Prometheus.SystemMetrics.Example.AOT/./Prometheus.SystemMetrics.Example.AOT.csproj"
COPY . .
WORKDIR "/src/src/Prometheus.SystemMetrics.Example.AOT"
RUN dotnet build "./Prometheus.SystemMetrics.Example.AOT.csproj" -c $BUILD_CONFIGURATION -o /app/build

FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./Prometheus.SystemMetrics.Example.AOT.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=true

FROM mcr.microsoft.com/dotnet/runtime-deps:8.0 AS final
WORKDIR /app
EXPOSE 8080
COPY --from=publish /app/publish .
ENTRYPOINT ["./Prometheus.SystemMetrics.Example.AOT"]
23 changes: 23 additions & 0 deletions src/Prometheus.SystemMetrics.Example.AOT/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Prometheus;
using Prometheus.SystemMetrics;

var builder = WebApplication.CreateSlimBuilder(args);

var services = builder.Services;
services.AddSystemMetrics();

var app = builder.Build();

if (app.Environment.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}

app.UseRouting();
app.MapMetrics();
app.MapGet("/", async context =>
{
context.Response.Redirect("/metrics");
});

app.Run();
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<InvariantGlobalization>true</InvariantGlobalization>
<PublishAot>true</PublishAot>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<DockerfileContext>..\..</DockerfileContext>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.5" />
<PackageReference Include="prometheus-net.AspNetCore" Version="8.1.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Prometheus.SystemMetrics\Prometheus.SystemMetrics.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"profiles": {
"http": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "todos",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"dotnetRunMessages": true,
"applicationUrl": "http://localhost:5017"
},
"Docker": {
"commandName": "Docker",
"launchBrowser": true,
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/todos",
"environmentVariables": {
"ASPNETCORE_HTTP_PORTS": "8080"
},
"publishAllPorts": true
}
},
"$schema": "http://json.schemastore.org/launchsettings.json"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
9 changes: 9 additions & 0 deletions src/Prometheus.SystemMetrics.Example.AOT/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}

0 comments on commit 316558c

Please sign in to comment.