Skip to content

Add IIS Support to Windows Server Core images for .NET 6 - #2908

Merged
mthalman merged 11 commits into
dotnet:nightlyfrom
richlander:ancm2
Jul 2, 2021
Merged

mthalman merged 11 commits into
dotnet:nightlyfrom
richlander:ancm2

Conversation

@richlander

Copy link
Copy Markdown
Member

This PR replaces #2868.

  • This one adds support via Docker templates.
  • I didn't know how to make the SHA checks work (since this change switches files) so I just deleted that. I'll need help on that.
  • I added a new IIS sample and added a Windows Server Core entry to the ASP.NET Core README.

I wanted to add a new row in table the ASP.NET Core sample that demonstrated which server was being used. From what I can tell, that's not possible. Maybe there is an ASP.NET Core API to do that but I didn't spend any time looking for that.

@ghost ghost added the area-samples label Jun 19, 2021

@mthalman mthalman left a comment

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.

I also see that the tests are failing for this change. The test fails when attempting to connect to an ASP.NET container that uses this base image. It runs the command docker run --name 6.0-app-run-132687101791254395 --rm -d -t -p 80 6.0-build-132687101214184088 dotnet run --urls http://0.0.0.0:80 and fails with 403 - Forbidden: Access is denied.

exit 1; `
}; `
Invoke-WebRequest -OutFile c:\aspnetcore-hosting.exe https://dotnetcli.azureedge.net/dotnet/aspnetcore/Runtime/$Env:ASPNET_VERSION/dotnet-hosting-$Env:ASPNET_VERSION-win.exe; `
$process = start-process -Filepath C:\aspnetcore-hosting.exe -ArgumentList @('/install', '/q', '/norestart', 'OPT_NO_RUNTIME=1') -Wait -PassThru ; `

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.

Suggested change
$process = start-process -Filepath C:\aspnetcore-hosting.exe -ArgumentList @('/install', '/q', '/norestart', 'OPT_NO_RUNTIME=1') -Wait -PassThru ; `
$process = Start-Process -Filepath C:\aspnetcore-hosting.exe -ArgumentList @('/install', '/q', '/norestart', 'OPT_NO_RUNTIME=1') -Wait -PassThru ; `

exit 1; `
}; `
Invoke-WebRequest -OutFile c:\aspnetcore-hosting.exe https://dotnetcli.azureedge.net/dotnet/aspnetcore/Runtime/$Env:ASPNET_VERSION/dotnet-hosting-$Env:ASPNET_VERSION-win.exe; `
$process = start-process -Filepath C:\aspnetcore-hosting.exe -ArgumentList @('/install', '/q', '/norestart', 'OPT_NO_RUNTIME=1') -Wait -PassThru ; `

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 really not need to explicitly install ASP.NET Core runtime? Is this being implicitly done by the the dotnet hosting exe? What about the OPT_NO_RUNTIME flag?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This configuration installs ASP.NET Core. I validated that. By default, the installer installs ACM, .NET Runtime and ASP.NET Core Runtime. All other configurations are opt-out.

I removed OPT_NO_RUNTIME and then the .NET Core Runtime was installed.

Write-Host 'CHECKSUM VERIFICATION FAILED!'; `
exit 1; `
}; `
Invoke-WebRequest -OutFile c:\aspnetcore-hosting.exe https://dotnetcli.azureedge.net/dotnet/aspnetcore/Runtime/$Env:ASPNET_VERSION/dotnet-hosting-$Env:ASPNET_VERSION-win.exe; `

@mthalman mthalman Jun 21, 2021 •

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.

We're going to need to do checksum validation here on the downloaded exe. This requires a bunch of changes.

Update manifest.versions.json file

We'll need a new entry defined here:

"aspnet|6.0|build-version": "6.0.0-preview.6.21306.3",
"aspnet|6.0|linux-musl|x64|sha": "0f4be76de67a4e78860592d1ce6cd5a9db464d1d67e41eec98386617eae47adabb754ae3db9cf0d9bd2f6f4ad2cbeb96e0d85df73a709cf9a132ab1c324c0f18",
"aspnet|6.0|linux-musl|arm|sha": "0fd505e9561c1b7e63e0797392679a94760befeb28a22f3300f019a6459ba07e7161db4fa161bed1f6b669b47ad99b7c93779de6fc44ec36b1dc9bfdeb783749",
"aspnet|6.0|linux-musl|arm64|sha": "95e4377220d3379b4baa0030e73f3cd391c955916f6ee95493a4d325b80d89a6193c9f87ba993e57ba43c11a4cc0ee9b67c3e8ef552005c9488085e06fbdad73",
"aspnet|6.0|linux-rpm|x64|sha": "acd308fe6e14324af35644c4a27d8295aaf9c81aed0a0d602ca92e7bead9d94e37ebc2cda8d6f1af5a924be5d74f70cc5d5f76bf4b1089084ac36d466d36198b",
"aspnet|6.0|linux|arm|sha": "c4c036371c1ea8934e97a36eb3a3b4768adfb8f6a58445e0af3ea2b295647b7e535faa5d8c96b1aff9a8265419e1ec62bf3945cadd499f1d11119ead9fc934a5",
"aspnet|6.0|linux|x64|sha": "4ddfc3a4adecbd767a615bb1d11871ab6d3a3ed6ba0be43fef1a589269896442838ffa7a23c5d3afd308506ac37420bd149226b11a3233714a508c2f91df4b82",
"aspnet|6.0|linux|arm64|sha": "29bbe516a31b04bff08969897692240f4bfe18e9f88f8c3a71656ec62f0562ca936dba398a45146a20b56fd8393654b7deb6732e0e0c62c9a63b0419377c841c",
"aspnet|6.0|win|x64|sha": "049c9c489a6461677abeb7646874ebf59f11d404214c14c138a2ed6ce10a276302815864e9594f470fb407280edbfc10f27b8fd3fb585e3df27d02ab2cf14635",
"aspnet-runtime-targeting-pack|6.0|linux-rpm|x64|sha": "57465a82e8c33b24fb056069521f72ab9248f9cb78486649036d6eb1fd0ae591e2c6d75812cfff833ae384cc0b63b852b14ec2ca80a27982ac32b6abe8a1613f",

I would propose something like:

"aspnet-dotnet-hosting|6.0|win|x64|sha": "<checksum>"

Update update-dependencies tool

That will then require a change to the update-dependencies tool to populate the checksum value at

private static readonly Dictionary<string, string[]> s_urls = new() {
{"powershell", new string[] { "https://pwshtool.blob.core.windows.net/tool/$VERSION_DIR/PowerShell.$OS.$ARCH.$VERSION_FILE.nupkg" }},
{"monitor", new string[] { $"{DotnetBaseUrl}/diagnostics/monitor$CHANNEL_NAME/dotnet-monitor.$VERSION_FILE.nupkg" }},
{"runtime", new string[] { $"{DotnetBaseUrl}/Runtime/$VERSION_DIR/dotnet-runtime-$VERSION_FILE$OPTIONAL_OS-$ARCH.$ARCHIVE_EXT" }},
{"runtime-host", new string[] { $"{DotnetBaseUrl}/Runtime/$VERSION_DIR/dotnet-host-$VERSION_FILE-$ARCH.$ARCHIVE_EXT" }},
{"runtime-hostfxr", new string[] { $"{DotnetBaseUrl}/Runtime/$VERSION_DIR/dotnet-hostfxr-$VERSION_FILE-$ARCH.$ARCHIVE_EXT" }},
{"runtime-targeting-pack", new string[]
{
$"{DotnetBaseUrl}/Runtime/$VERSION_DIR/dotnet-targeting-pack-$VERSION_FILE-$ARCH.$ARCHIVE_EXT",
$"{DotnetBaseUrl}/Runtime/$DF_VERSION.0/dotnet-targeting-pack-$DF_VERSION.0-$ARCH.$ARCHIVE_EXT"
}
},
{"runtime-apphost-pack", new string[] { $"{DotnetBaseUrl}/Runtime/$VERSION_DIR/dotnet-apphost-pack-$VERSION_FILE-$ARCH.$ARCHIVE_EXT" }},
{NetStandard21TargetingPack, new string[] { $"{DotnetBaseUrl}/Runtime/3.1.0/netstandard-targeting-pack-2.1.0-$ARCH.$ARCHIVE_EXT" }},
{"runtime-deps-cm.1", new string[] { $"{DotnetBaseUrl}/Runtime/$VERSION_DIR/dotnet-runtime-deps-$VERSION_FILE-cm.1-$ARCH.$ARCHIVE_EXT" }},
{"aspnet", new string[] { $"{DotnetBaseUrl}/aspnetcore/Runtime/$VERSION_DIR/aspnetcore-runtime-$VERSION_FILE$OPTIONAL_OS-$ARCH.$ARCHIVE_EXT" }},
{"aspnet-runtime-targeting-pack", new string[]
{
$"{DotnetBaseUrl}/aspnetcore/Runtime/$VERSION_DIR/aspnetcore-targeting-pack-$VERSION_FILE.$ARCHIVE_EXT",
$"{DotnetBaseUrl}/aspnetcore/Runtime/$DF_VERSION.0/aspnetcore-targeting-pack-$DF_VERSION.0.$ARCHIVE_EXT"
}
},
{"sdk", new string[] { $"{DotnetBaseUrl}/Sdk/$VERSION_DIR/dotnet-sdk-$VERSION_FILE$OPTIONAL_OS-$ARCH.$ARCHIVE_EXT" }},
{"lzma", new string[] { $"{DotnetBaseUrl}/Sdk/$VERSION_DIR/nuGetPackagesArchive.lzma" }}
};

Proposed value for that is:

{"aspnet-dotnet-hosting", new string[] { $"{DotnetBaseUrl}/aspnetcore/Runtime/$VERSION_DIR/dotnet-hosting-$VERSION_FILE-$OS.exe" }

Update script

And then the script which invokes update-dependencies needs to be updated to include this new entry:

$updateDepsArgs += @("--product-version", "aspnet=$AspnetVersion", "--product-version", "aspnet-runtime-targeting-pack=$AspnetVersion")

It should be changed to

$updateDepsArgs += @("--product-version", "aspnet=$AspnetVersion", "--product-version", "aspnet-runtime-targeting-pack=$AspnetVersion", "--product-version", "aspnet-dotnet-hosting=$AspnetVersion")

Consume checksum in template

Finally the Dockerfile needs to validate the checksum:

        $dotnet_hosting_sha512 = '{{VARIABLES["aspnet-dotnet-hosting|6.0|win|x64|sha"]}}'; `
        if ((Get-FileHash aspnetcore-hosting.exe -Algorithm sha512).Hash -ne $dotnet_hosting_sha512) { `
            Write-Host 'CHECKSUM VERIFICATION FAILED!'; `
            exit 1; `
        }; `

@richlander

Copy link
Copy Markdown
Member Author

Is it possible for you to finish this off @mthalman, pretty please? The rest of the PR is all stuff that I don't know anything about and will be very slow at addressing. The main thing I wanted to do was prove out the model, and that's now been accomplished.

@mthalman

Copy link
Copy Markdown
Member

@richlander - Ok, because you said pretty please, I guess I can do it.

@mthalman mthalman self-assigned this Jun 21, 2021
@richlander

Copy link
Copy Markdown
Member Author

Thanks, Matt. You are the best!

@mthalman

Copy link
Copy Markdown
Member

The test failure is very interesting. It appears that the container is crashing as a result of the test logic making a request before the service is ready for it. It first yields the 403 response. A second attempt yields a 503 response and then the container crashes. By putting in a 10 second delay (for good measure) before attempting the first request, the test passes. What I don't understand is why these changes cause this difference in behavior. In theory, the app configuration used for the test is no different than prior to these changes.

@richlander

Copy link
Copy Markdown
Member Author

@mthalman -- That's probably doing to servicemonitor.exe. Do you not see that with .NET Framework images?

@mthalman

mthalman commented Jun 23, 2021 •

Copy link
Copy Markdown
Member

But servicemonitor.exe isn't even being executed in this context. It exists in the image, but that's it. And now I can't even repro it on my machine any more. It was reproing and now it's not. 🤦‍♂️

@richlander

Copy link
Copy Markdown
Member Author

OK. I was wondering if you were just talking about the base image vs the sample. Makes sense. Very odd!

@mthalman

Copy link
Copy Markdown
Member

I made the following updates:

  • Added checksum validation
  • When installing dotnet-hosting, opted out of x86 installation
  • Need to disable w3svc service. Otherwise IIS will start when container starts, causing race condition between accepting of requests between IIS and Kestrel. Plus, it's unneeded by default.

@richlander

Copy link
Copy Markdown
Member Author

Do you think that this will make the July release?

@mthalman
mthalman requested a review from MichaelSimons June 29, 2021 12:43
@mthalman

mthalman commented Jun 29, 2021 •

Copy link
Copy Markdown
Member

Do you think that this will make the July release?

I would think so. I realized that @MichaelSimons wasn't declared as a reviewer so I'll want to get his review on this before merging.

}; `
$process = Start-Process -Filepath C:\aspnetcore-hosting.exe -ArgumentList @('/install', '/q', '/norestart', 'OPT_NO_RUNTIME=1', 'OPT_NO_X86=1') -Wait -PassThru ; `
if ($process.ExitCode -ne 0) { `
exit $process.ExitCode ; `

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.

Suggested change
exit $process.ExitCode ; `
exit $process.ExitCode; `

Write-Host 'CHECKSUM VERIFICATION FAILED!'; `
exit 1; `
}; `
$process = Start-Process -Filepath C:\aspnetcore-hosting.exe -ArgumentList @('/install', '/q', '/norestart', 'OPT_NO_RUNTIME=1', 'OPT_NO_X86=1') -Wait -PassThru ; `

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.

Does this leave any log files that should be cleaned up?

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.

Yes, just a few in the temp folder. I'll get those cleaned up.

Invoke-WebRequest -OutFile aspnetcore.zip https://dotnetcli.azureedge.net/dotnet/aspnetcore/Runtime/$Env:ASPNET_VERSION/aspnetcore-runtime-$Env:ASPNET_VERSION-win-x64.zip; `
$aspnetcore_sha512 = '{{VARIABLES["aspnet|6.0|win|x64|sha"]}}'; `
if ((Get-FileHash aspnetcore.zip -Algorithm sha512).Hash -ne $aspnetcore_sha512) { `
# Install IIS and disable it for startup

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.

What is the size impact of these changes? How much bigger is the image?

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.

As a whole, these changes add about 217 MB. The vast majority of that, ~200 MB, is from IIS. This changes the image size from roughly 5.7 GB to 5.9 GB.

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.

Granted the base image is huge, but that aside, this is a non-trivial addition. How many users will want to use IIS over Kestrel? Is this something better provided by an image variant or a scenario doc?

@richlander richlander Jun 29, 2021 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We could go that path. Certainly, we've had very little call for this. That said, it's a relatively small % change for one of our key scenarios on Windows. It's also not an easy/intuitive component to install. If we were going to go that direction, I'd request that the ASP.NET team create an distribution with only ANCM to make it easier. None of the options are super attractive.

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.

The runtime and aspnetcore .NET layers combined are ~90 MB. I lean towards not adding to the size problem ServerCore based images have if this is not considered the mainline use case.

@richlander richlander Jun 30, 2021 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Sure, but what's the alternative? My issue is that the ANCM installer is difficult to use. It is easy to make your images worse if done incorrectly. See this conversation for evidence of that: #2908 (comment).

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.

Add scenario documentation for this. Concurrently get the ASP.NET team create an distribution with only ANCM to make it easier.

Invoke-WebRequest -OutFile aspnetcore.zip https://dotnetcli.azureedge.net/dotnet/aspnetcore/Runtime/$Env:ASPNET_VERSION/aspnetcore-runtime-$Env:ASPNET_VERSION-win-x64.zip; `
$aspnetcore_sha512 = 'aa10762145e5db33db667d4c563b7a0098ebe95b744add06686879172d7e2e3796fad0fbae9d631fed2019e882798bc6f5ab064ab6ba3342082ca4eafc2256c4'; `
if ((Get-FileHash aspnetcore.zip -Algorithm sha512).Hash -ne $aspnetcore_sha512) { `
# Install IIS and disable it for startup

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.

I see value in adding a unit test that uses IIS to validate the installation is correct.

@@ -0,0 +1,30 @@
# https://hub.docker.com/_/microsoft-dotnet
FROM mcr.microsoft.com/dotnet/sdk:6.0-windowsservercore-ltsc2019 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.

It's strange IMO that this sample is using 6.0 images when the rest don't.

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.

Agreed. But it's only temporary until 6.0 GAs, just a few months.

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.

IMO the samples should be on the same version. Given this isn't supported in the production images, my preference would be to track this with an issue and added at RTM.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

How about we target moving all the samples to .NET 6 for Preview 6.

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.

I can get onboard with that.

@mthalman

Copy link
Copy Markdown
Member

Because of the amount of size that IIS adds to the image, we've decided to not add IIS to the aspnet image at this time. As a consequence, ServiceMonitor and the ASP.NET Core Module won't be added either. Instead, this pattern of installation will be demonstrated and tested in the sample Dockerfile.

@MichaelSimons MichaelSimons left a comment

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.

LGTM

Comment thread eng/Set-DotnetVersions.ps1 Outdated

if ($AspnetVersion) {
$updateDepsArgs += @("--product-version", "aspnet=$AspnetVersion", "--product-version", "aspnet-runtime-targeting-pack=$AspnetVersion")
$updateDepsArgs += @("--product-version", "aspnet=$AspnetVersion", "--product-version", "aspnet-runtime-targeting-pack=$AspnetVersion", "--product-version")

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.

What is the trailing --product-version needed for?

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.

Just a mistake. Deleted.

# final stage/image
FROM mcr.microsoft.com/dotnet/aspnet:6.0-windowsservercore-ltsc2019

WORKDIR /inetpub/wwwroot

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.

Thoughts on moving this after the IIS setup just before the COPY? I think it would help may the COPY more clear.

@mthalman mthalman mentioned this pull request Jul 12, 2021
39 of 40 tasks
mthalman pushed a commit to mthalman/dotnet-docker that referenced this pull request Jul 12, 2021
@richlander
richlander deleted the ancm2 branch October 19, 2021 21:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants