OpenSSF Scorecard - pin docker images to exact digest - ASP.NET Framework (#4124)

This commit is contained in:
Piotr Kiełkowicz 2025-04-03 12:06:34 +02:00 committed by GitHub
parent de5f0267bb
commit b07874afc4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 36 additions and 27 deletions

View File

@ -136,15 +136,7 @@ partial class Build
.Executes(() => .Executes(() =>
{ {
var aspNetProject = Solution.GetProjectByName(Projects.Tests.Applications.AspNet); var aspNetProject = Solution.GetProjectByName(Projects.Tests.Applications.AspNet);
BuildDockerImage(aspNetProject); BuildDockerImage(aspNetProject, "integrated", "classic");
DockerBuild(x => x
.SetPath(".")
.SetFile(aspNetProject.Directory / "Classic.Dockerfile")
.EnableRm()
.SetTag(($"{Path.GetFileNameWithoutExtension(aspNetProject).Replace(".", "-")}-classic").ToLowerInvariant())
.SetProcessWorkingDirectory(aspNetProject.Directory)
);
var wcfProject = Solution.GetProjectByName(Projects.Tests.Applications.WcfIis); var wcfProject = Solution.GetProjectByName(Projects.Tests.Applications.WcfIis);
BuildDockerImage(wcfProject); BuildDockerImage(wcfProject);
@ -153,7 +145,7 @@ partial class Build
BuildDockerImage(owinProject); BuildDockerImage(owinProject);
}); });
void BuildDockerImage(Project project) void BuildDockerImage(Project project, params string[] targets)
{ {
const string moduleName = "OpenTelemetry.DotNet.Auto.psm1"; const string moduleName = "OpenTelemetry.DotNet.Auto.psm1";
var sourceModulePath = InstallationScriptsDirectory / moduleName; var sourceModulePath = InstallationScriptsDirectory / moduleName;
@ -176,13 +168,31 @@ partial class Build
project.Directory / "Properties" / "PublishProfiles" / $"FolderProfile.{BuildConfiguration}.pubxml") project.Directory / "Properties" / "PublishProfiles" / $"FolderProfile.{BuildConfiguration}.pubxml")
.SetTargetPath(project)); .SetTargetPath(project));
DockerBuild(x => x if (targets.Length > 0)
.SetPath(".") {
.SetBuildArg($"configuration={BuildConfiguration}") foreach (var target in targets)
.EnableRm() {
.SetTag(Path.GetFileNameWithoutExtension(project).Replace(".", "-").ToLowerInvariant()) DockerBuild(x => x
.SetProcessWorkingDirectory(project.Directory) .SetPath(".")
); .SetBuildArg($"configuration={BuildConfiguration}")
.EnableRm()
.SetProcessWorkingDirectory(project.Directory)
.SetTag($"{Path.GetFileNameWithoutExtension(project).Replace(".", "-")}-{target}".ToLowerInvariant())
.SetTarget(target)
);
}
}
else
{
DockerBuild(x => x
.SetPath(".")
.SetBuildArg($"configuration={BuildConfiguration}")
.EnableRm()
.SetProcessWorkingDirectory(project.Directory)
.SetTag(Path.GetFileNameWithoutExtension(project).Replace(".", "-").ToLowerInvariant())
);
}
} }
finally finally
{ {

View File

@ -146,7 +146,7 @@ public class AspNetTests
}; };
var webPort = TcpPortProvider.GetOpenPort(); var webPort = TcpPortProvider.GetOpenPort();
await using var container = await IISContainerTestHelper.StartContainerAsync("testapplication-aspnet-netframework", webPort, environmentVariables, Output); await using var container = await IISContainerTestHelper.StartContainerAsync("testapplication-aspnet-netframework-integrated", webPort, environmentVariables, Output);
await CallTestApplicationEndpoint(webPort); await CallTestApplicationEndpoint(webPort);
collector.ResourceExpector.AssertExpectations(); collector.ResourceExpector.AssertExpectations();
@ -175,7 +175,7 @@ public class AspNetTests
["OTEL_DOTNET_AUTO_METRICS_ASPNET_INSTRUMENTATION_ENABLED"] = "true" // Helps to reduce noise by enabling only AspNet metrics. ["OTEL_DOTNET_AUTO_METRICS_ASPNET_INSTRUMENTATION_ENABLED"] = "true" // Helps to reduce noise by enabling only AspNet metrics.
}; };
var webPort = TcpPortProvider.GetOpenPort(); var webPort = TcpPortProvider.GetOpenPort();
await using var container = await IISContainerTestHelper.StartContainerAsync("testapplication-aspnet-netframework", webPort, environmentVariables, Output); await using var container = await IISContainerTestHelper.StartContainerAsync("testapplication-aspnet-netframework-integrated", webPort, environmentVariables, Output);
await CallTestApplicationEndpoint(webPort); await CallTestApplicationEndpoint(webPort);
collector.AssertExpectations(); collector.AssertExpectations();
@ -183,7 +183,7 @@ public class AspNetTests
private static string GetTestImageName(string appPoolMode) private static string GetTestImageName(string appPoolMode)
{ {
return appPoolMode == "Classic" ? "testapplication-aspnet-netframework-classic" : "testapplication-aspnet-netframework"; return appPoolMode == "Classic" ? "testapplication-aspnet-netframework-classic" : "testapplication-aspnet-netframework-integrated";
} }
private async Task CallTestApplicationEndpoint(int webPort) private async Task CallTestApplicationEndpoint(int webPort)

View File

@ -1,6 +0,0 @@
# escape=`
FROM testapplication-aspnet-netframework:latest
RUN Start-IISCommitDelay;`
(Get-IISAppPool -Name DefaultAppPool).ManagedPipelineMode = 'Classic';`
Stop-IISCommitDelay -Commit $True

View File

@ -1,6 +1,6 @@
# escape=` # escape=`
FROM mcr.microsoft.com/dotnet/framework/aspnet:4.8-windowsservercore-ltsc2022@sha256:84079c734ab5aec702409ef7967ec47af9468c56ff4046882239cabacda78097 FROM mcr.microsoft.com/dotnet/framework/aspnet:4.8-windowsservercore-ltsc2022@sha256:84079c734ab5aec702409ef7967ec47af9468c56ff4046882239cabacda78097 AS integrated
ARG configuration=Debug ARG configuration=Debug
ARG platform=x64 ARG platform=x64
WORKDIR /opentelemetry WORKDIR /opentelemetry
@ -16,3 +16,8 @@ ENV OTEL_DOTNET_AUTO_LOG_DIRECTORY=C:\inetpub\wwwroot\logs `
OTEL_LOG_LEVEL=debug OTEL_LOG_LEVEL=debug
WORKDIR /inetpub/wwwroot WORKDIR /inetpub/wwwroot
COPY bin/${configuration}/app.publish . COPY bin/${configuration}/app.publish .
FROM integrated AS classic
RUN Start-IISCommitDelay;`
(Get-IISAppPool -Name DefaultAppPool).ManagedPipelineMode = 'Classic';`
Stop-IISCommitDelay -Commit $True