Skip to content

feat: add .NET example #18

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 1 commit into from
Nov 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions deploy-apps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ echo "Building the Rust demo"
make -C rust build
kubectl apply -f ./rust/deployment.yaml

echo "Building the .NET demo"

make -C dotnet build
kubectl apply -f ./dotnet/deployment.yaml

echo "Building the Python demo"

make -C python build
Expand Down
14 changes: 14 additions & 0 deletions dotnet/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Created by https://www.toptal.com/developers/gitignore/api/dotnetcore
# Edit at https://www.toptal.com/developers/gitignore?templates=dotnetcore

### DotnetCore ###
# .NET Core build folders
bin/
obj/

# Common node modules locations
/node_modules
/wwwroot/node_modules

# End of https://www.toptal.com/developers/gitignore/api/dotnetcore

24 changes: 24 additions & 0 deletions dotnet/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
FROM mcr.microsoft.com/dotnet/runtime:7.0 AS base
WORKDIR /app

# Creates a non-root user with an explicit UID and adds permission to access the /app folder
# For more info, please refer to https://aka.ms/vscode-docker-dotnet-configure-containers
RUN adduser -u 5678 --disabled-password --gecos "" appuser && chown -R appuser /app
USER appuser

FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
WORKDIR /src
COPY ["demo.csproj", "./"]
RUN dotnet restore "demo.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "demo.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "demo.csproj" -c Release -o /app/publish

FROM base AS final
ENV DOTNET_PerfMapEnabled=1
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "demo.dll"]
3 changes: 3 additions & 0 deletions dotnet/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.PHONY: build
build:
docker build -t parca-demo:dotnet .
29 changes: 29 additions & 0 deletions dotnet/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;

namespace Demo
{
class Program
{
static int Fibonacci(int n)
{
int a = 0, b = 1, tmp;

for (int i = 0; i < n; i++)
{
tmp = a;
a = b;
b += tmp;
}

return a;
}

static void Main(string[] args)
{
while (true)
{
Console.WriteLine(Fibonacci(42));
}
}
}
}
3 changes: 3 additions & 0 deletions dotnet/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# .NET

See https://learn.microsoft.com/en-us/dotnet/core/runtime-config/debugging-profiling#export-perf-maps
10 changes: 10 additions & 0 deletions dotnet/demo.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
24 changes: 24 additions & 0 deletions dotnet/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app.kubernetes.io/name: demo-dotnet
name: dotnet
namespace: parca
spec:
replicas: 3
selector:
matchLabels:
app.kubernetes.io/name: demo-dotnet
template:
metadata:
labels:
app.kubernetes.io/name: demo-dotnet
spec:
containers:
- image: parca-demo:dotnet
name: dotnet
resources:
limits:
cpu: '100m'
memory: '256Mi'