Skip to content
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
1 change: 0 additions & 1 deletion deployment/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions test-docker-fix.sh
Original file line number Diff line number Diff line change
@@ -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."
71 changes: 71 additions & 0 deletions tests/NLWebNet.Tests/Docker/DockerfileTests.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}