Skip to content

Commit d80ffd0

Browse files
committed
add end to end test for .NEt 8
1 parent f4f46c6 commit d80ffd0

File tree

2 files changed

+49
-3
lines changed

2 files changed

+49
-3
lines changed

Microsoft.NET.Build.Containers.IntegrationTests/DockerRegistryManager.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public class DockerRegistryManager
1212
public const string BaseImageSource = "mcr.microsoft.com/";
1313
public const string Net6ImageTag = "6.0";
1414
public const string Net7ImageTag = "7.0";
15+
public const string Net8PreviewImageTag = "8.0-preview";
1516
public const string LocalRegistry = "localhost:5010";
1617
public const string FullyQualifiedBaseImageDefault = $"{BaseImageSource}{BaseImage}:{Net6ImageTag}";
1718
private static string? s_registryContainerId;

Microsoft.NET.Build.Containers.IntegrationTests/EndToEndTests.cs

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public async Task ApiEndToEndWithLocalLoad()
110110
.Should().Pass();
111111
}
112112

113-
private string BuildLocalApp([CallerMemberName] string testName = "TestName", string tfm = "net6.0", string rid = "linux-x64")
113+
private string BuildLocalApp([CallerMemberName] string testName = "TestName", string tfm = "net6.0", string rid = "linux-x64", string configuration = "Debug")
114114
{
115115
string workingDirectory = Path.Combine(TestSettings.TestArtifactsDirectory, testName);
116116

@@ -126,12 +126,12 @@ private string BuildLocalApp([CallerMemberName] string testName = "TestName", st
126126
.Execute()
127127
.Should().Pass();
128128

129-
new DotnetCommand(_testOutput, "publish", "-bl", "MinimalTestApp", "-r", rid, "-f", tfm)
129+
new DotnetCommand(_testOutput, "publish", "-bl", "-c", configuration, "MinimalTestApp", "-r", rid, "-f", tfm)
130130
.WithWorkingDirectory(workingDirectory)
131131
.Execute()
132132
.Should().Pass();
133133

134-
string publishDirectory = Path.Join(workingDirectory, "MinimalTestApp", "bin", "Debug", tfm, rid, "publish");
134+
string publishDirectory = Path.Join(workingDirectory, "MinimalTestApp", "bin", configuration, tfm, rid, "publish");
135135
return publishDirectory;
136136
}
137137

@@ -328,4 +328,49 @@ string[] DecideEntrypoint(string rid, string appName, string workingDir)
328328
return new[] { $"{workingDir}/{binary}" };
329329
}
330330
}
331+
332+
[Fact]
333+
public async Task CanSetContainerUserAndUseRootless()
334+
{
335+
var rid = "linux-x64";
336+
string publishDirectory = BuildLocalApp(tfm: "net8.0", rid: rid, configuration: "Release");
337+
338+
// Build the image
339+
Registry registry = new(ContainerHelpers.TryExpandRegistryToUri(DockerRegistryManager.BaseImageSource));
340+
341+
ImageBuilder? imageBuilder = await registry.GetImageManifestAsync(
342+
DockerRegistryManager.BaseImage,
343+
DockerRegistryManager.Net8PreviewImageTag,
344+
rid,
345+
ToolsetUtils.GetRuntimeGraphFilePath(),
346+
cancellationToken: default).ConfigureAwait(false);
347+
Assert.NotNull(imageBuilder);
348+
349+
Layer l = Layer.FromDirectory(publishDirectory, "/app", false);
350+
351+
imageBuilder.AddLayer(l);
352+
imageBuilder.SetWorkingDirectory("/app");
353+
354+
imageBuilder.SetEntryPoint(new[] { "/app/MinimalTestApp" });
355+
imageBuilder.SetUser("app");
356+
BuiltImage builtImage = imageBuilder.Build();
357+
358+
// Load the image into the local Docker daemon
359+
var sourceReference = new ImageReference(registry, DockerRegistryManager.BaseImage, DockerRegistryManager.Net8PreviewImageTag);
360+
var destinationReference = new ImageReference(registry, NewImageName(), rid);
361+
await new LocalDocker(Console.WriteLine).LoadAsync(builtImage, sourceReference, destinationReference, default).ConfigureAwait(false);
362+
363+
// Run the image
364+
new BasicCommand(
365+
_testOutput,
366+
"docker",
367+
"run",
368+
"--rm",
369+
"--tty",
370+
$"{NewImageName()}:{rid}")
371+
.Execute()
372+
.Should()
373+
.Pass();
374+
375+
}
331376
}

0 commit comments

Comments
 (0)