Skip to content

Commit

Permalink
chore: Add dotnet SDKv8 support for examples (#3493)
Browse files Browse the repository at this point in the history
This uses a multi-stage build in order to overcome build problems on
sdk7+ on Rosetta based macs.

It will cross compile using the linxu/arm64 dotnet sdk for the linux/amd64 target.
  • Loading branch information
simonswine authored Aug 19, 2024
1 parent e97c746 commit ed5162d
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 16 deletions.
30 changes: 25 additions & 5 deletions examples/language-sdk-instrumentation/dotnet/rideshare/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,33 @@
FROM mcr.microsoft.com/dotnet/sdk:6.0
ARG SDK_VERSION=8.0
# The build images takes an SDK image of the buildplatform, so the platform the build is running on.
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:$SDK_VERSION AS build

ARG TARGETPLATFORM
ARG BUILDPLATFORM
ARG SDK_VERSION

WORKDIR /dotnet

COPY --from=pyroscope/pyroscope-dotnet:0.8.19-glibc /Pyroscope.Profiler.Native.so ./Pyroscope.Profiler.Native.so
COPY --from=pyroscope/pyroscope-dotnet:0.8.19-glibc /Pyroscope.Linux.ApiWrapper.x64.so ./Pyroscope.Linux.ApiWrapper.x64.so
ADD example .

# Set the target framework to SDK_VERSION
RUN sed -i -E 's|<TargetFramework>.*</TargetFramework>|<TargetFramework>net'$SDK_VERSION'</TargetFramework>|' Example.csproj

# We hardcode linux-x64 here, as the profiler doesn't support any other platform
RUN dotnet publish -o . --framework net$SDK_VERSION --runtime linux-x64 --no-self-contained

ADD example .
# This fetches the SDK
FROM --platform=linux/amd64 pyroscope/pyroscope-dotnet:0.8.20-glibc AS sdk

# Runtime only image of the targetplatfrom, so the platform the image will be running on.
FROM --platform=linux/amd64 mcr.microsoft.com/dotnet/aspnet:$SDK_VERSION

WORKDIR /dotnet

COPY --from=sdk /Pyroscope.Profiler.Native.so ./Pyroscope.Profiler.Native.so
COPY --from=sdk /Pyroscope.Linux.ApiWrapper.x64.so ./Pyroscope.Linux.ApiWrapper.x64.so
COPY --from=build /dotnet/ ./

RUN dotnet publish -o . -r $(dotnet --info | grep RID | cut -b 6- | tr -d ' ')

ENV CORECLR_ENABLE_PROFILING=1
ENV CORECLR_PROFILER={BD1A650D-AC5D-4896-B64F-D6FA25D6B26A}
Expand All @@ -22,6 +41,7 @@ ENV PYROSCOPE_PROFILING_ENABLED=1
ENV PYROSCOPE_PROFILING_ALLOCATION_ENABLED=true
ENV PYROSCOPE_PROFILING_CONTENTION_ENABLED=true
ENV PYROSCOPE_PROFILING_EXCEPTION_ENABLED=true
ENV PYROSCOPE_PROFILING_HEAP_ENABLED=true
ENV RIDESHARE_LISTEN_PORT=5000


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ services:
ports:
- 4040:4040
us-east:
platform: linux/amd64
ports:
- 5000
environment:
Expand All @@ -16,7 +15,6 @@ services:
build:
context: .
eu-north:
platform: linux/amd64
ports:
- 5000
environment:
Expand All @@ -26,8 +24,9 @@ services:
- RIDESHARE_LISTEN_PORT=5000
build:
context: .
args:
SDK_VERSION: "6.0"
ap-south:
platform: linux/amd64
ports:
- 5000
environment:
Expand All @@ -38,7 +37,6 @@ services:
build:
context: .
ap-south-alpine:
platform: linux/amd64
ports:
- 5000
environment:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<AssemblyName>example</AssemblyName>
<OutputType>Exe</OutputType>
<PackageId>example</PackageId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,33 @@
FROM mcr.microsoft.com/dotnet/sdk:6.0-alpine
ARG SDK_VERSION=8.0
# The build images takes an SDK image of the buildplatform, so the platform the build is running on.
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:$SDK_VERSION-alpine AS build

ARG TARGETPLATFORM
ARG BUILDPLATFORM
ARG SDK_VERSION

WORKDIR /dotnet

COPY --from=pyroscope/pyroscope-dotnet:0.8.19-musl /Pyroscope.Profiler.Native.so ./Pyroscope.Profiler.Native.so
COPY --from=pyroscope/pyroscope-dotnet:0.8.19-musl /Pyroscope.Linux.ApiWrapper.x64.so ./Pyroscope.Linux.ApiWrapper.x64.so
ADD example .

# Set the target framework to SDK_VERSION
RUN sed -i -E 's|<TargetFramework>.*</TargetFramework>|<TargetFramework>net'$SDK_VERSION'</TargetFramework>|' Example.csproj

ADD example .
# We hardcode linux-x64 here, as the profiler doesn't support any other platform
RUN dotnet publish -o . --framework net$SDK_VERSION --runtime linux-musl-x64 --no-self-contained

# This fetches the SDK
FROM --platform=linux/amd64 pyroscope/pyroscope-dotnet:0.8.20-musl AS sdk

# Runtime only image of the targetplatfrom, so the platform the image will be running on.
FROM --platform=linux/amd64 mcr.microsoft.com/dotnet/aspnet:$SDK_VERSION-alpine

WORKDIR /dotnet

COPY --from=sdk /Pyroscope.Profiler.Native.so ./Pyroscope.Profiler.Native.so
COPY --from=sdk /Pyroscope.Linux.ApiWrapper.x64.so ./Pyroscope.Linux.ApiWrapper.x64.so
COPY --from=build /dotnet/ ./

RUN dotnet publish -o . -r $(dotnet --info | grep RID | cut -b 6- | tr -d ' ')

ENV CORECLR_ENABLE_PROFILING=1
ENV CORECLR_PROFILER={BD1A650D-AC5D-4896-B64F-D6FA25D6B26A}
Expand All @@ -22,6 +41,8 @@ ENV PYROSCOPE_PROFILING_ENABLED=1
ENV PYROSCOPE_PROFILING_ALLOCATION_ENABLED=true
ENV PYROSCOPE_PROFILING_CONTENTION_ENABLED=true
ENV PYROSCOPE_PROFILING_EXCEPTION_ENABLED=true
ENV PYROSCOPE_PROFILING_HEAP_ENABLED=true
ENV RIDESHARE_LISTEN_PORT=5000


CMD sh -c "ASPNETCORE_URLS=http://*:${RIDESHARE_LISTEN_PORT} exec dotnet /dotnet/example.dll"
1 change: 0 additions & 1 deletion examples/tracing/tempo/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ services:
dockerfile: Dockerfile.otel-instrumentation

rideshare-dotnet-eu-west:
platform: linux/amd64
ports:
- 5000
hostname: rideshare-dotnet-eu-west
Expand Down

0 comments on commit ed5162d

Please sign in to comment.