forked from DataDog/dd-trace-dotnet
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Build Alpine (musl) version of the CLR Profiler (DataDog#621)
Issue Previously, only one version of the CLR Profiler was built for Linux distributions, and the library linked against glibc as the C standard library. Musl-based distributions (meaning they use musl as the C standard library instead of glibc) then required a combination of additional `libc6-compat` and `gcompat` packages to properly load and run the profiler library. However, on Alpine versions 3.10+ the additional compatibility packages fail and we're left with no support for these distributions. Changes proposed in this pull request: - Build `Datadog.Trace.ClrProfiler.Native.so` on an Alpine container so it is linked against musl, and package it as `datadog-dotnet-apm-$VERSION-musl.tar.gz`. - Create new Alpine dockerfiles and docker-compose services for building, testing, and packaging the new version of the library in parallel with the existing Linux pipelines. Note: There are currently no apk packages for .NET Core so there is a separate dockerfile for each version of the .NET Core runtime on Alpine image. - Modify the IntegrationTests bash file to directly invoke `dotnet vstest` so the command directly tests the test binaries instead of trying to rebuild the test projects, which causes issues on the Alpine images that only have .NET Core SDK installed - Add a minimal ConsoleApp .NET Core app that shows how to build a Docker container with the automatic instrumentation for a Debian container and various Alpine containers - Run Datadog.Trace.IntegrationTests.csproj and Datadog.Trace.OpenTracing.IntegrationTests.csproj in Windows integration-tests CI run
- Loading branch information
1 parent
49edc6d
commit d584520
Showing
20 changed files
with
456 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
bin\ | ||
obj\ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build | ||
WORKDIR /app | ||
|
||
# Copy csproj and restore as distinct layers | ||
COPY *.csproj ./ | ||
RUN dotnet restore | ||
|
||
# Copy everything else and build | ||
COPY . ./ | ||
RUN dotnet publish -c Release -f netcoreapp3.1 -o out | ||
|
||
# Build runtime image | ||
FROM mcr.microsoft.com/dotnet/core/runtime:3.1-alpine3.10 | ||
WORKDIR /app | ||
COPY --from=build /app/out . | ||
|
||
# Set up Datadog APM | ||
RUN apk --no-cache update && apk add curl | ||
ARG TRACER_VERSION=1.12.0 | ||
RUN mkdir -p /var/log/datadog | ||
RUN mkdir -p /opt/datadog | ||
RUN curl -L https://github.com/DataDog/dd-trace-dotnet/releases/download/v${TRACER_VERSION}/datadog-dotnet-apm-${TRACER_VERSION}-musl.tar.gz \ | ||
| tar xzf - -C /opt/datadog | ||
|
||
ENV CORECLR_ENABLE_PROFILING=1 | ||
ENV CORECLR_PROFILER={846F5F1C-F9AE-4B07-969E-05C26BC060D8} | ||
ENV CORECLR_PROFILER_PATH=/opt/datadog/Datadog.Trace.ClrProfiler.Native.so | ||
ENV DD_INTEGRATIONS=/opt/datadog/integrations.json | ||
ENV DD_DOTNET_TRACER_HOME=/opt/datadog | ||
|
||
CMD ["dotnet", "ConsoleApp.dll"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build | ||
WORKDIR /app | ||
|
||
# Copy csproj and restore as distinct layers | ||
COPY *.csproj ./ | ||
RUN dotnet restore | ||
|
||
# Copy everything else and build | ||
COPY . ./ | ||
RUN dotnet publish -c Release -f netcoreapp2.1 -o out | ||
|
||
# Build runtime image | ||
FROM mcr.microsoft.com/dotnet/core/runtime:2.1-alpine3.9 | ||
WORKDIR /app | ||
COPY --from=build /app/out . | ||
|
||
# Set up Datadog APM | ||
RUN apk --no-cache update && apk add curl | ||
ARG TRACER_VERSION=1.12.0 | ||
RUN mkdir -p /var/log/datadog | ||
RUN mkdir -p /opt/datadog | ||
RUN curl -L https://github.com/DataDog/dd-trace-dotnet/releases/download/v${TRACER_VERSION}/datadog-dotnet-apm-${TRACER_VERSION}-musl.tar.gz \ | ||
| tar xzf - -C /opt/datadog | ||
|
||
ENV CORECLR_ENABLE_PROFILING=1 | ||
ENV CORECLR_PROFILER={846F5F1C-F9AE-4B07-969E-05C26BC060D8} | ||
ENV CORECLR_PROFILER_PATH=/opt/datadog/Datadog.Trace.ClrProfiler.Native.so | ||
ENV DD_INTEGRATIONS=/opt/datadog/integrations.json | ||
ENV DD_DOTNET_TRACER_HOME=/opt/datadog | ||
|
||
CMD ["dotnet", "ConsoleApp.dll"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFrameworks>netcoreapp2.1;netcoreapp3.1</TargetFrameworks> | ||
</PropertyGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build | ||
WORKDIR /app | ||
|
||
# Copy csproj and restore as distinct layers | ||
COPY *.csproj ./ | ||
RUN dotnet restore | ||
|
||
# Copy everything else and build | ||
COPY . ./ | ||
RUN dotnet publish -c Release -f netcoreapp3.1 -o out | ||
|
||
# Build runtime image | ||
FROM mcr.microsoft.com/dotnet/core/runtime:3.1 | ||
WORKDIR /app | ||
COPY --from=build /app/out . | ||
|
||
# Set up Datadog APM | ||
ARG TRACER_VERSION=1.12.0 | ||
RUN mkdir -p /var/log/datadog | ||
RUN mkdir -p /opt/datadog | ||
RUN curl -LO https://github.com/DataDog/dd-trace-dotnet/releases/download/v${TRACER_VERSION}/datadog-dotnet-apm_${TRACER_VERSION}_amd64.deb | ||
RUN dpkg -i ./datadog-dotnet-apm_${TRACER_VERSION}_amd64.deb | ||
|
||
ENV CORECLR_ENABLE_PROFILING=1 | ||
ENV CORECLR_PROFILER={846F5F1C-F9AE-4B07-969E-05C26BC060D8} | ||
ENV CORECLR_PROFILER_PATH=/opt/datadog/Datadog.Trace.ClrProfiler.Native.so | ||
ENV DD_INTEGRATIONS=/opt/datadog/integrations.json | ||
ENV DD_DOTNET_TRACER_HOME=/opt/datadog | ||
|
||
CMD ["dotnet", "ConsoleApp.dll"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using System; | ||
using System.Net.Http; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace ConsoleApp | ||
{ | ||
internal class Program | ||
{ | ||
private static async Task<int> Main() | ||
{ | ||
var baseAddress = new Uri("https://www.example.com/"); | ||
var regularHttpClient = new HttpClient { BaseAddress = baseAddress }; | ||
|
||
Console.WriteLine("Calling regularHttpClient.GetAsync"); | ||
await regularHttpClient.GetAsync("default-handler"); | ||
Console.WriteLine("Called regularHttpClient.GetAsync"); | ||
|
||
return 0; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# .NET Core Docker Sample | ||
This sample demonstrates how to build container images for .NET Core apps that use the Datadog .NET Tracer. | ||
|
||
The instructions assume that you have cloned this repo, have [Docker](https://www.docker.com/products/docker) installed, and have a command prompt open in the `customer-samples/ConsoleApp` directory. | ||
|
||
## Build a .NET Core image | ||
You can build and run a .NET Core-based container image using the following instructions, specifying the desire dockerfile with the `-f` argument: | ||
|
||
```console | ||
docker build -f Debian.dockerfile -t consoleapp . | ||
docker run --rm -it consoleapp | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<Project> | ||
<!-- | ||
This file intentionally left blank... | ||
to stop msbuild from looking up the folder hierarchy | ||
--> | ||
</Project> |
Oops, something went wrong.