Skip to content

Commit 4bd19c5

Browse files
committed
feat: add .NET example
1 parent d79bc14 commit 4bd19c5

File tree

8 files changed

+112
-0
lines changed

8 files changed

+112
-0
lines changed

deploy-apps.sh

+5
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ echo "Building the Rust demo"
2727
make -C rust build
2828
kubectl apply -f ./rust/deployment.yaml
2929

30+
echo "Building the .NET demo"
31+
32+
make -C dotnet build
33+
kubectl apply -f ./dotnet/deployment.yaml
34+
3035
echo "Building the Python demo"
3136

3237
make -C python build

dotnet/.gitignore

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Created by https://www.toptal.com/developers/gitignore/api/dotnetcore
2+
# Edit at https://www.toptal.com/developers/gitignore?templates=dotnetcore
3+
4+
### DotnetCore ###
5+
# .NET Core build folders
6+
bin/
7+
obj/
8+
9+
# Common node modules locations
10+
/node_modules
11+
/wwwroot/node_modules
12+
13+
# End of https://www.toptal.com/developers/gitignore/api/dotnetcore
14+

dotnet/Dockerfile

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
FROM mcr.microsoft.com/dotnet/runtime:7.0 AS base
2+
WORKDIR /app
3+
4+
# Creates a non-root user with an explicit UID and adds permission to access the /app folder
5+
# For more info, please refer to https://aka.ms/vscode-docker-dotnet-configure-containers
6+
RUN adduser -u 5678 --disabled-password --gecos "" appuser && chown -R appuser /app
7+
USER appuser
8+
9+
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
10+
WORKDIR /src
11+
COPY ["demo.csproj", "./"]
12+
RUN dotnet restore "demo.csproj"
13+
COPY . .
14+
WORKDIR "/src/."
15+
RUN dotnet build "demo.csproj" -c Release -o /app/build
16+
17+
FROM build AS publish
18+
RUN dotnet publish "demo.csproj" -c Release -o /app/publish
19+
20+
FROM base AS final
21+
ENV DOTNET_PerfMapEnabled=1
22+
WORKDIR /app
23+
COPY --from=publish /app/publish .
24+
ENTRYPOINT ["dotnet", "demo.dll"]

dotnet/Makefile

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.PHONY: build
2+
build:
3+
docker build -t parca-demo:dotnet .

dotnet/Program.cs

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System;
2+
3+
namespace Demo
4+
{
5+
class Program
6+
{
7+
static int Fibonacci(int n)
8+
{
9+
int a = 0, b = 1, tmp;
10+
11+
for (int i = 0; i < n; i++)
12+
{
13+
tmp = a;
14+
a = b;
15+
b += tmp;
16+
}
17+
18+
return a;
19+
}
20+
21+
static void Main(string[] args)
22+
{
23+
while (true)
24+
{
25+
Console.WriteLine(Fibonacci(42));
26+
}
27+
}
28+
}
29+
}

dotnet/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# .NET
2+
3+
See https://learn.microsoft.com/en-us/dotnet/core/runtime-config/debugging-profiling#export-perf-maps

dotnet/demo.csproj

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net7.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
</Project>

dotnet/deployment.yaml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
labels:
5+
app.kubernetes.io/name: demo-dotnet
6+
name: dotnet
7+
namespace: parca
8+
spec:
9+
replicas: 3
10+
selector:
11+
matchLabels:
12+
app.kubernetes.io/name: demo-dotnet
13+
template:
14+
metadata:
15+
labels:
16+
app.kubernetes.io/name: demo-dotnet
17+
spec:
18+
containers:
19+
- image: parca-demo:dotnet
20+
name: dotnet
21+
resources:
22+
limits:
23+
cpu: '100m'
24+
memory: '256Mi'

0 commit comments

Comments
 (0)