Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
16 changes: 16 additions & 0 deletions user-management/scripts/target.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash
set -e

# Map TARGETPLATFORM to Rust target
case "$TARGETPLATFORM" in

@jeastham1993 jeastham1993 Jun 17, 2025

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pulled directly from your Rust example @scottgerring 🎉

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Semi-related: there was an amazing article about the horror of target triples that popped up recently. Worth reading if you want to cry.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naaa, all good for crying thanks :)

"linux/amd64")
export TRACER_ARCHITECTURE="amd64"
;;
"linux/arm64")
export TRACER_ARCHITECTURE="arm64"
;;
*)
echo "Unsupported platform: $TARGETPLATFORM"
exit 1
;;
esac
30 changes: 28 additions & 2 deletions user-management/src/Stickerlandia.UserManagement.Api/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
FROM --platform=${BUILDPLATFORM} mcr.microsoft.com/dotnet/sdk:8.0 AS build

ARG TARGETPLATFORM

WORKDIR /App

COPY ./scripts ./scripts

# Download the latest version of the tracer but don't install yet
RUN . scripts/target.sh && TRACER_VERSION=$(curl -s \https://api.github.com/repos/DataDog/dd-trace-dotnet/releases/latest | grep tag_name | cut -d '"' -f 4 | cut -c2-) \
Comment thread
jeastham1993 marked this conversation as resolved.
Outdated
&& curl -Lo /tmp/datadog-dotnet-apm.deb https://github.com/DataDog/dd-trace-dotnet/releases/download/v${TRACER_VERSION}/datadog-dotnet-apm_${TRACER_VERSION}_${TRACER_ARCHITECTURE}.deb

# Deps
COPY src/Stickerlandia.UserManagement.Api/Stickerlandia.UserManagement.Api.csproj src/Stickerlandia.UserManagement.Api/
RUN dotnet restore src/Stickerlandia.UserManagement.Api/Stickerlandia.UserManagement.Api.csproj
Expand All @@ -12,11 +20,29 @@ COPY . ./
# Publish the application
RUN dotnet publish src/Stickerlandia.UserManagement.Api/Stickerlandia.UserManagement.Api.csproj -o out -c Release
Comment thread
scottgerring marked this conversation as resolved.

FROM mcr.microsoft.com/dotnet/aspnet:8.0-noble-chiseled AS runtime
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS runtime

# Copy the tracer from build target
COPY --from=build /tmp/datadog-dotnet-apm.deb /tmp/datadog-dotnet-apm.deb
# Install the tracer
RUN mkdir -p /opt/datadog \
&& mkdir -p /var/log/datadog \
&& dpkg -i /tmp/datadog-dotnet-apm.deb \
&& rm /tmp/datadog-dotnet-apm.deb

ARG DD_GIT_REPOSITORY_URL
ARG DD_GIT_COMMIT_SHA

ENV DD_GIT_REPOSITORY_URL=${DD_GIT_REPOSITORY_URL}
ENV DD_GIT_COMMIT_SHA=${DD_GIT_COMMIT_SHA}

ENV CORECLR_ENABLE_PROFILING=1
ENV CORECLR_PROFILER={846F5F1C-F9AE-4B07-969E-05C26BC060D8}
Comment thread
jeastham1993 marked this conversation as resolved.
ENV CORECLR_PROFILER_PATH=/opt/datadog/Datadog.Trace.ClrProfiler.Native.so
ENV DD_DOTNET_TRACER_HOME=/opt/datadog
ENV DD_INTEGRATIONS=/opt/datadog/integrations.json
ENV DD_LOGS_INJECTION=true
ENV DD_RUNTIME_METRICS_ENABLED=true
WORKDIR /App
COPY --from=build /App/out .
EXPOSE 80
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need Dockerfile-x86 ? You should just be able to build the regular Dockerfile with --target and have everything work. This is already happening in the container build:

- name: Build and push Docker image
id: push
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
with:
context: ./user-management
file: ./user-management/src/Stickerlandia.UserManagement.Api/Dockerfile
platforms: linux/amd64,linux/arm64

WORKDIR /App

# Download the latest version of the tracer but don't install yet
RUN TRACER_VERSION=$(curl -s \https://api.github.com/repos/DataDog/dd-trace-dotnet/releases/latest | grep tag_name | cut -d '"' -f 4 | cut -c2-) \
&& curl -Lo /tmp/datadog-dotnet-apm.deb https://github.com/DataDog/dd-trace-dotnet/releases/download/v${TRACER_VERSION}/datadog-dotnet-apm_${TRACER_VERSION}_amd64.deb

Copilot AI Jun 17, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Fetching the latest tracer on every build impedes reproducibility. Consider accepting a build ARG for TRACER_VERSION or pinning to a known release.

Suggested change
# Download the latest version of the tracer but don't install yet
RUN TRACER_VERSION=$(curl -s \https://api.github.com/repos/DataDog/dd-trace-dotnet/releases/latest | grep tag_name | cut -d '"' -f 4 | cut -c2-) \
&& curl -Lo /tmp/datadog-dotnet-apm.deb https://github.com/DataDog/dd-trace-dotnet/releases/download/v${TRACER_VERSION}/datadog-dotnet-apm_${TRACER_VERSION}_amd64.deb
# Download the specified version of the tracer but don't install yet
ARG TRACER_VERSION=2.30.0
RUN curl -Lo /tmp/datadog-dotnet-apm.deb https://github.com/DataDog/dd-trace-dotnet/releases/download/v${TRACER_VERSION}/datadog-dotnet-apm_${TRACER_VERSION}_amd64.deb

Copilot uses AI. Check for mistakes.

# Deps
COPY src/Stickerlandia.UserManagement.Api/Stickerlandia.UserManagement.Api.csproj src/Stickerlandia.UserManagement.Api/
RUN dotnet restore src/Stickerlandia.UserManagement.Api/Stickerlandia.UserManagement.Api.csproj
Expand All @@ -12,11 +16,29 @@ COPY . ./
# Publish the application
RUN dotnet publish src/Stickerlandia.UserManagement.Api/Stickerlandia.UserManagement.Api.csproj -o out -c Release -r linux-x64

FROM mcr.microsoft.com/dotnet/aspnet:8.0-noble-chiseled AS runtime
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS runtime

# Copy the tracer from build target
COPY --from=build /tmp/datadog-dotnet-apm.deb /tmp/datadog-dotnet-apm.deb
# Install the tracer
RUN mkdir -p /opt/datadog \
&& mkdir -p /var/log/datadog \
&& dpkg -i /tmp/datadog-dotnet-apm.deb \
Comment thread
scottgerring marked this conversation as resolved.
Outdated
&& rm /tmp/datadog-dotnet-apm.deb

ARG DD_GIT_REPOSITORY_URL
ARG DD_GIT_COMMIT_SHA

ENV DD_GIT_REPOSITORY_URL=${DD_GIT_REPOSITORY_URL}
ENV DD_GIT_COMMIT_SHA=${DD_GIT_COMMIT_SHA}

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_DOTNET_TRACER_HOME=/opt/datadog
ENV DD_INTEGRATIONS=/opt/datadog/integrations.json
ENV DD_LOGS_INJECTION=true
ENV DD_RUNTIME_METRICS_ENABLED=true
WORKDIR /App
COPY --from=build /App/out .
EXPOSE 80
Expand Down
Loading