Skip to content
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

[Samples] Update IIS sample Dockerfile #5805

Merged
merged 6 commits into from
Jul 30, 2024
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
8 changes: 8 additions & 0 deletions tracer/samples/IISInDocker/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.idea
.vs
.vscode
README.md
src/bin/
src/obj/
src/**/*.user
src/**/*.suo
24 changes: 7 additions & 17 deletions tracer/samples/IISInDocker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ FROM mcr.microsoft.com/dotnet/framework/sdk:4.8 AS build
WORKDIR /app

# copy csproj and restore as distinct layers
COPY *.sln .
COPY *.sln ./
COPY src/*.csproj ./src/
COPY src/*.config ./src/
RUN nuget restore
Expand All @@ -15,24 +15,14 @@ RUN msbuild /p:Configuration=Release

### Stage: runtime
FROM mcr.microsoft.com/dotnet/framework/aspnet:4.8-windowsservercore-ltsc2019 AS runtime
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]

WORKDIR /inetpub/wwwroot
COPY --from=build /app/src/. ./
COPY startup.ps1 .
COPY install-dd-trace-dotnet.ps1 startup.ps1 ./

# Install the Datadog SDK for .NET using the msi installer
RUN .\install-dd-trace-dotnet.ps1

# Install the .NET Tracer MSI
# Note: Normally an IIS reset is also required but 'C:\ServiceMonitor.exe w3svc'
# will restart IIS and update the environment variables received by the child w3wp processes
RUN Write-Host 'Determining latest release' ;\
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason this can't be done here and instead has to be moved to a file? 🤔 I don't know of a good reason it needs to be?

Copy link
Member Author

@lucaspimentel lucaspimentel Jul 25, 2024

Choose a reason for hiding this comment

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

Level of care low on this one, but I can think of a few very "mild" reasons 😅

  • If a script is going to be more than a handful of lines, I think it deserves its own file (cleaner code, separation of concerns, etc)
  • This particular script is not Docker-specific. A separate file makes it easier to copy and use elsewhere.
  • It definitely made it easier and faster for me to fix it outside of Docker. (probably the main reason I did it)

$releases = 'https://api.github.com/repos/DataDog/dd-trace-dotnet/releases' ;\
$tag = (Invoke-WebRequest $releases -UseBasicParsing | ConvertFrom-Json)[0].tag_name ;\
$version = $tag.Split('v')[1] ;\
Write-Host "Downloading Datadog .NET Tracer $tag" ;\
(New-Object System.Net.WebClient).DownloadFile('https://github.com/DataDog/dd-trace-dotnet/releases/download/' + $tag + '/datadog-dotnet-apm-' + $version + '-x64.msi', 'datadog-apm.msi') ;\
Write-Host 'Installing Datadog .NET Tracer' ;\
Start-Process -Wait msiexec -ArgumentList '/i datadog-apm.msi /quiet /qn /norestart /log datadog-apm-msi-installer.log' ; \
Write-Host 'Datadog .NET Tracer installed, removing installer file' ;\
Remove-Item 'datadog-apm.msi' ;

ENTRYPOINT ["powershell.exe", ".\\startup.ps1"]
# Replace the default ENTRYPOINT "C:\ServiceMonitor.exe w3svc"
ENTRYPOINT .\startup.ps1
2 changes: 1 addition & 1 deletion tracer/samples/IISInDocker/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ASP.NET Docker Sample
This sample demonstrates how to build and deploy an ASP.NET Framework application in IIS using a Windows container. This also demonstrates how to configure environment variables using at the time of container startup, which may be the earliest that time that IP's and networking values are populated.
This sample demonstrates how to build and deploy an ASP.NET application in IIS using a Windows container. This also demonstrates how to configure environment variables during container startup, which may be the earliest time that IPs and networking values are populated.

## Build and Run
To build and run the application, open a terminal in this directory and run the following commands:
Expand Down
23 changes: 23 additions & 0 deletions tracer/samples/IISInDocker/install-dd-trace-dotnet.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
$outPath = $env:TEMP # change this to save the msi and log file to a different path

$ErrorActionPreference = 'Stop'
$ProgressPreference = 'SilentlyContinue'

Write-Host 'Finding latest release of Datadog SDK for .NET.'
$releases = 'https://api.github.com/repos/DataDog/dd-trace-dotnet/releases/latest'
$tag = (Invoke-WebRequest $releases -UseBasicParsing | ConvertFrom-Json)[0].tag_name
$version = $tag.Substring(1)
$msiFilename = "$outPath\datadog-dotnet-apm-$version-x64.msi"
$logFilename = "$outPath\datadog-dotnet-apm-$version-x64.log"
$url = "https://github.com/DataDog/dd-trace-dotnet/releases/download/$tag/datadog-dotnet-apm-$version-x64.msi"

Write-Host "Found installer for Datadog SDK for .NET $tag"
Write-Host "- downloading from ""$url"""
Write-Host "- saving to ""$msiFilename"""
Invoke-WebRequest -Uri $url -OutFile $msiFilename

Write-Host "Installing. Logs will be saved to ""$logFilename""."
Start-Process -Wait 'C:\Windows\system32\msiexec.exe' -ArgumentList "/i ""$msiFilename"" /quiet /qn /norestart /log ""$logFilename"""

Write-Host "Installation finished. Deleting installer file ""$msiFilename""."
Remove-Item $msiFilename
3 changes: 3 additions & 0 deletions tracer/samples/IISInDocker/startup.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# startup.ps1: Startup script to customize the environment when the container starts but before starting IIS

$ErrorActionPreference = 'Stop'
$ProgressPreference = 'SilentlyContinue'

# For example, set DD_AGENT_HOST at launch time, which may be necessary for ECS applications sending traces to their EC2 instance
# $dockerHost = (curl http://169.254.169.254/latest/meta-data/local-ipv4).Content
# [Environment]::SetEnvironmentVariable("DD_AGENT_HOST", "$dockerHost")
Expand Down
Loading