From 8bcb8b4ddd09315bcbda2d3f9a274a81c911f2d7 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 1 Nov 2026 21:19:03 +0000 Subject: [PATCH 1/2] Initial plan From 7a38a16f32dd0a734500da3b2f92c8d51788c8f9 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 1 Nov 2026 21:23:29 +0000 Subject: [PATCH 2/2] Skip Dockerfile-specific dockerignore files without warnings Co-authored-by: grvillic <58237075+grvillic@users.noreply.github.com> --- .../dockerfile/DockerfileComponentDetector.cs | 1 + .../DockerfileComponentDetectorTests.cs | 34 +++++++++++++++++-- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.ComponentDetection.Detectors/dockerfile/DockerfileComponentDetector.cs b/src/Microsoft.ComponentDetection.Detectors/dockerfile/DockerfileComponentDetector.cs index 00760e336..a4c2f92b0 100644 --- a/src/Microsoft.ComponentDetection.Detectors/dockerfile/DockerfileComponentDetector.cs +++ b/src/Microsoft.ComponentDetection.Detectors/dockerfile/DockerfileComponentDetector.cs @@ -51,6 +51,7 @@ protected override Task> OnPrepareDetectionAsync( IDictionary detectorArgs, CancellationToken cancellationToken = default) => Task.FromResult(processRequests.Where(processRequest => + !processRequest.ComponentStream.Location.EndsWith(".dockerignore", StringComparison.OrdinalIgnoreCase) && !this.IsInSkippedFolder(processRequest.ComponentStream.Location))); protected override async Task OnFileFoundAsync(ProcessRequest processRequest, IDictionary detectorArgs, CancellationToken cancellationToken = default) diff --git a/test/Microsoft.ComponentDetection.Detectors.Tests/DockerfileComponentDetectorTests.cs b/test/Microsoft.ComponentDetection.Detectors.Tests/DockerfileComponentDetectorTests.cs index 90d685172..5bfb14f0e 100644 --- a/test/Microsoft.ComponentDetection.Detectors.Tests/DockerfileComponentDetectorTests.cs +++ b/test/Microsoft.ComponentDetection.Detectors.Tests/DockerfileComponentDetectorTests.cs @@ -201,18 +201,48 @@ public async Task TestDockerfile_ExtensionFilenameAsync() } [TestMethod] - public async Task TestDockerfile_PrefixedFilenameAsync() + [DataRow("Dockerfile.prod")] + [DataRow("Dockerfile.runtime")] + [DataRow("Dockerfile.dockerignore.runtime")] + public async Task TestDockerfile_PrefixedFilenameAsync(string fileName) { var dockerfile = @"FROM redis:7-alpine"; var (scanResult, componentRecorder) = await this.DetectorTestUtility - .WithFile("Dockerfile.prod", dockerfile) + .WithFile(fileName, dockerfile) .ExecuteDetectorAsync(); scanResult.ResultCode.Should().Be(ProcessingResultCode.Success); componentRecorder.GetDetectedComponents().Should().ContainSingle(); } + [TestMethod] + [DataRow("Dockerfile.dockerignore", "node_modules\n*.log")] + [DataRow("Dockerfile.runtime.dockerignore", "node_modules\n*.log")] + [DataRow("app.dockerfile.dockerignore", "node_modules\n*.log")] + [DataRow("DOCKERFILE.DOCKERIGNORE", "node_modules\n*.log")] + [DataRow("Dockerfile.dockerignore", "FROM redis:7-alpine")] + public async Task TestDockerfile_DockerignoreIsSilentlyIgnoredAsync(string fileName, string contents) + { + var loggerMock = new Mock>(); + + var (scanResult, componentRecorder) = await this.DetectorTestUtility + .WithFile(fileName, contents) + .AddServiceMock(loggerMock) + .ExecuteDetectorAsync(); + + scanResult.ResultCode.Should().Be(ProcessingResultCode.Success); + componentRecorder.GetDetectedComponents().Should().BeEmpty(); + loggerMock.Verify( + logger => logger.Log( + It.Is(level => level == LogLevel.Warning || level == LogLevel.Error), + It.IsAny(), + It.IsAny(), + It.IsAny(), + It.IsAny>()), + Times.Never); + } + [TestMethod] [DataRow("dockerfile.mjs")] [DataRow("dockerfile.d.mts")]