diff --git a/deployment/docker/Dockerfile b/deployment/docker/Dockerfile index 3cff936..7d87b9c 100644 --- a/deployment/docker/Dockerfile +++ b/deployment/docker/Dockerfile @@ -14,7 +14,6 @@ ENV NUGET_XMLDOC_MODE=skip COPY ["NLWebNet.sln", "./"] COPY ["src/NLWebNet/NLWebNet.csproj", "src/NLWebNet/"] COPY ["samples/Demo/NLWebNet.Demo.csproj", "samples/Demo/"] -COPY ["samples/AspireHost/NLWebNet.AspireHost.csproj", "samples/AspireHost/"] COPY ["tests/NLWebNet.Tests/NLWebNet.Tests.csproj", "tests/NLWebNet.Tests/"] # Restore dependencies diff --git a/test-docker-fix.sh b/test-docker-fix.sh new file mode 100755 index 0000000..2586955 --- /dev/null +++ b/test-docker-fix.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +# Test script to verify Docker build functionality for NLWebNet Demo +# This script verifies that the Docker build can successfully copy all project files + +set -e + +echo "Testing Docker build file copying stage..." + +# Build only up to the file copying stage to verify all referenced files exist +docker build -f deployment/docker/Dockerfile --target build --no-cache -t nlwebnet-build-test . 2>&1 | head -20 + +echo "" +echo "Docker build file copying stage test completed successfully!" +echo "All project files referenced in the Dockerfile exist and can be copied." \ No newline at end of file diff --git a/tests/NLWebNet.Tests/Docker/DockerfileTests.cs b/tests/NLWebNet.Tests/Docker/DockerfileTests.cs new file mode 100644 index 0000000..e14029d --- /dev/null +++ b/tests/NLWebNet.Tests/Docker/DockerfileTests.cs @@ -0,0 +1,71 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.IO; +using System.Text.RegularExpressions; + +namespace NLWebNet.Tests.Docker; + +[TestClass] +public class DockerfileTests +{ + [TestMethod] + public void Dockerfile_AllReferencedProjectFilesExist() + { + // Arrange + var rootPath = GetRepositoryRoot(); + var dockerfilePath = Path.Combine(rootPath, "deployment/docker/Dockerfile"); + + Assert.IsTrue(File.Exists(dockerfilePath), $"Dockerfile not found at {dockerfilePath}"); + + var dockerfileContent = File.ReadAllText(dockerfilePath); + + // Extract COPY commands that reference .csproj files + var copyPattern = @"COPY \[""([^""]+\.csproj)"", ""[^""]+/""\]"; + var matches = Regex.Matches(dockerfileContent, copyPattern); + + // Act & Assert + foreach (Match match in matches) + { + var projectPath = match.Groups[1].Value; + var fullPath = Path.Combine(rootPath, projectPath); + + Assert.IsTrue(File.Exists(fullPath), + $"Project file referenced in Dockerfile does not exist: {projectPath} (Full path: {fullPath})"); + } + + // Verify we found at least the expected project files + Assert.IsTrue(matches.Count >= 3, + "Expected to find at least 3 project file references in Dockerfile (NLWebNet, Demo, Tests)"); + } + + [TestMethod] + public void Dockerfile_DoesNotReferenceAspireHostProject() + { + // Arrange + var rootPath = GetRepositoryRoot(); + var dockerfilePath = Path.Combine(rootPath, "deployment/docker/Dockerfile"); + + Assert.IsTrue(File.Exists(dockerfilePath), $"Dockerfile not found at {dockerfilePath}"); + + var dockerfileContent = File.ReadAllText(dockerfilePath); + + // Act & Assert + Assert.IsFalse(dockerfileContent.Contains("AspireHost"), + "Dockerfile should not contain references to AspireHost project"); + Assert.IsFalse(dockerfileContent.Contains("NLWebNet.AspireHost.csproj"), + "Dockerfile should not contain references to NLWebNet.AspireHost.csproj"); + } + + private static string GetRepositoryRoot() + { + var currentDirectory = Directory.GetCurrentDirectory(); + var directory = new DirectoryInfo(currentDirectory); + + while (directory != null && !File.Exists(Path.Combine(directory.FullName, "NLWebNet.sln"))) + { + directory = directory.Parent; + } + + Assert.IsNotNull(directory, "Could not find repository root (NLWebNet.sln not found)"); + return directory.FullName; + } +} \ No newline at end of file