Skip to content

Commit 6e1035b

Browse files
Surayya Huseyn ZadaSurayya Huseyn Zada
authored andcommitted
fixed multi-arch e2e tests
1 parent 7b09eb9 commit 6e1035b

File tree

1 file changed

+56
-45
lines changed

1 file changed

+56
-45
lines changed

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

Lines changed: 56 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -746,16 +746,15 @@ public void EndToEndMultiArch_LocalRegistry()
746746
.Execute();
747747

748748
// Check that the app was published for each RID,
749-
// images were created locally for each RID
750-
// and image index was NOT created
749+
// one image was created locally
751750
commandResult.Should().Pass()
752751
.And.HaveStdOutContaining(GetPublishArtifactsPath(newProjectDir.FullName, "linux-x64"))
753752
.And.HaveStdOutContaining(GetPublishArtifactsPath(newProjectDir.FullName, "linux-arm64"))
754753
.And.HaveStdOutContaining($"Building image '{imageName}' for runtime identifier 'linux-x64'")
755754
.And.HaveStdOutContaining($"Building image '{imageName}' for runtime identifier 'linux-arm64'")
756755
.And.HaveStdOutContaining($"Pushed image '{image}' to local registry");
757756

758-
//Multi-arch oci images that are loaded to docker can only be run by their image id
757+
//Multi-arch oci tarballs that are loaded to docker can only be run by their image id
759758
string imageId = GetImageId(image);
760759

761760
// Check that the containers can be run
@@ -927,12 +926,10 @@ private string GetPublishArtifactsPath(string projectDir, string rid, string con
927926
public void EndToEndMultiArch_ArchivePublishing()
928927
{
929928
string imageName = NewImageName();
930-
string imageTag = "1.0";
931-
string imageX64 = $"{imageName}:{imageTag}-linux-x64";
932-
string imageArm64 = $"{imageName}:{imageTag}-linux-arm64";
929+
string tag = "1.0";
930+
string image = $"{imageName}:{tag}";
933931
string archiveOutput = Path.Combine(TestSettings.TestArtifactsDirectory, "tarballs-output");
934-
string imageX64Tarball = Path.Combine(archiveOutput, $"{imageName}-linux-x64.tar.gz");
935-
string imageArm64Tarball = Path.Combine(archiveOutput, $"{imageName}-linux-arm64.tar.gz");
932+
string imageTarball = Path.Combine(archiveOutput, $"{imageName}.tar.gz");
936933

937934
// Create a new console project
938935
DirectoryInfo newProjectDir = CreateNewProject("console");
@@ -946,49 +943,51 @@ public void EndToEndMultiArch_ArchivePublishing()
946943
$"/p:ContainerArchiveOutputPath={archiveOutput}",
947944
$"/p:ContainerBaseImage={DockerRegistryManager.FullyQualifiedBaseImageAspNet}",
948945
$"/p:ContainerRepository={imageName}",
949-
$"/p:ContainerImageTag={imageTag}",
946+
$"/p:ContainerImageTag={tag}",
950947
"/p:EnableSdkContainerSupport=true")
951948
.WithWorkingDirectory(newProjectDir.FullName)
952949
.Execute();
953950

954951
// Check that the app was published for each RID,
955-
// images were created locally for each RID
956-
// and image index was NOT created
952+
// one image was created in local archive
957953
commandResult.Should().Pass()
958954
.And.HaveStdOutContaining(GetPublishArtifactsPath(newProjectDir.FullName, "linux-x64"))
959955
.And.HaveStdOutContaining(GetPublishArtifactsPath(newProjectDir.FullName, "linux-arm64"))
960-
.And.HaveStdOutContaining($"Pushed image '{imageX64}' to local archive at '{imageX64Tarball}'")
961-
.And.HaveStdOutContaining($"Pushed image '{imageArm64}' to local archive at '{imageArm64Tarball}'")
962-
.And.NotHaveStdOutContaining("Pushed image index");
956+
.And.HaveStdOutContaining($"Building image '{imageName}' for runtime identifier 'linux-x64'")
957+
.And.HaveStdOutContaining($"Building image '{imageName}' for runtime identifier 'linux-arm64'")
958+
.And.HaveStdOutContaining($"Pushed image '{image}' to local archive at '{imageTarball}'");
963959

964960
// Check that tarballs were created
965-
File.Exists(imageX64Tarball).Should().BeTrue();
966-
File.Exists(imageArm64Tarball).Should().BeTrue();
961+
File.Exists(imageTarball).Should().BeTrue();
967962

968-
// Load the images from the tarballs
969-
ContainerCli.LoadCommand(_testOutput, "--input", imageX64Tarball)
970-
.Execute()
971-
.Should().Pass();
972-
ContainerCli.LoadCommand(_testOutput, "--input", imageArm64Tarball)
963+
// Load the multi-arch image from the tarball
964+
ContainerCli.LoadCommand(_testOutput, "--input", imageTarball)
973965
.Execute()
974966
.Should().Pass();
975967

968+
//Multi-arch oci tarballs that are loaded to docker can only be run by their image id
969+
string imageId = GetImageId(image);
970+
976971
// Check that the containers can be run
977972
CommandResult processResultX64 = ContainerCli.RunCommand(
978973
_testOutput,
979974
"--rm",
975+
"--platform",
976+
"linux/amd64",
980977
"--name",
981978
$"test-container-{imageName}-x64",
982-
imageX64)
979+
imageId)
983980
.Execute();
984981
processResultX64.Should().Pass().And.HaveStdOut("Hello, World!");
985982

986983
CommandResult processResultArm64 = ContainerCli.RunCommand(
987984
_testOutput,
988985
"--rm",
986+
"--platform",
987+
"linux/arm64",
989988
"--name",
990989
$"test-container-{imageName}-arm64",
991-
imageArm64)
990+
imageId)
992991
.Execute();
993992
processResultArm64.Should().Pass().And.HaveStdOut("Hello, World!");
994993

@@ -1118,8 +1117,8 @@ public void EndToEndMultiArch_ContainerRuntimeIdentifiersOverridesRuntimeIdentif
11181117
commandResult.Should().Pass()
11191118
.And.NotHaveStdOutContaining(GetPublishArtifactsPath(newProjectDir.FullName, "linux-x64"))
11201119
.And.HaveStdOutContaining(GetPublishArtifactsPath(newProjectDir.FullName, "linux-arm64"))
1121-
.And.NotHaveStdOutContaining($"Pushed image '{imageName}:{imageTag}-linux-x64' to local registry")
1122-
.And.HaveStdOutContaining($"Pushed image '{imageName}:{imageTag}-linux-arm64' to local registry");
1120+
.And.NotHaveStdOutContaining($"Building image '{imageName}' for runtime identifier 'linux-x64'")
1121+
.And.HaveStdOutContaining($"Building image '{imageName}' for runtime identifier 'linux-arm64'");
11231122

11241123
// Cleanup
11251124
newProjectDir.Delete(true);
@@ -1129,9 +1128,8 @@ public void EndToEndMultiArch_ContainerRuntimeIdentifiersOverridesRuntimeIdentif
11291128
public void EndToEndMultiArch_EnvVariables()
11301129
{
11311130
string imageName = NewImageName();
1132-
string imageTag = "1.0";
1133-
string imageX64 = $"{imageName}:{imageTag}-linux-x64";
1134-
string imageArm64 = $"{imageName}:{imageTag}-linux-arm64";
1131+
string tag = "1.0";
1132+
string image = $"{imageName}:{tag}";
11351133

11361134
// Create new console app, set ContainerEnvironmentVariables, and set to output env variable
11371135
DirectoryInfo newProjectDir = CreateNewProject("console");
@@ -1160,31 +1158,37 @@ public void EndToEndMultiArch_EnvVariables()
11601158
"/p:RuntimeIdentifiers=\"linux-x64;linux-arm64\"",
11611159
$"/p:ContainerBaseImage={DockerRegistryManager.FullyQualifiedBaseImageAspNet}",
11621160
$"/p:ContainerRepository={imageName}",
1163-
$"/p:ContainerImageTag={imageTag}",
1161+
$"/p:ContainerImageTag={tag}",
11641162
"/p:EnableSdkContainerSupport=true")
11651163
.WithWorkingDirectory(newProjectDir.FullName)
11661164
.Execute()
11671165
.Should().Pass();
11681166

1169-
// Check that the env var is printed
1167+
string imageId = GetImageId(image);
1168+
1169+
// Check that the env var is printed for linux/amd64 platform
11701170
string containerNameX64 = $"test-container-{imageName}-x64";
11711171
CommandResult processResultX64 = ContainerCli.RunCommand(
11721172
_testOutput,
11731173
"--rm",
1174+
"--platform",
1175+
"linux/amd64",
11741176
"--name",
11751177
containerNameX64,
1176-
imageX64)
1178+
imageId)
11771179
.Execute();
11781180
processResultX64.Should().Pass().And.HaveStdOut("FooBar");
11791181

1180-
// Check that the env var is printed
1182+
// Check that the env var is printed for linux/arm64 platform
11811183
string containerNameArm64 = $"test-container-{imageName}-arm64";
11821184
CommandResult processResultArm64 = ContainerCli.RunCommand(
11831185
_testOutput,
11841186
"--rm",
1187+
"--platform",
1188+
"linux/arm64",
11851189
"--name",
11861190
containerNameArm64,
1187-
imageArm64)
1191+
imageId)
11881192
.Execute();
11891193
processResultArm64.Should().Pass().And.HaveStdOut("FooBar");
11901194

@@ -1196,9 +1200,8 @@ public void EndToEndMultiArch_EnvVariables()
11961200
public void EndToEndMultiArch_Ports()
11971201
{
11981202
string imageName = NewImageName();
1199-
string imageTag = "1.0";
1200-
string imageX64 = $"{imageName}:{imageTag}-linux-x64";
1201-
string imageArm64 = $"{imageName}:{imageTag}-linux-arm64";
1203+
string tag = "1.0";
1204+
string image = $"{imageName}:{tag}";
12021205

12031206
// Create new web app, set ContainerPort
12041207
DirectoryInfo newProjectDir = CreateNewProject("webapp");
@@ -1222,38 +1225,44 @@ public void EndToEndMultiArch_Ports()
12221225
"/p:RuntimeIdentifiers=\"linux-x64;linux-arm64\"",
12231226
$"/p:ContainerBaseImage={DockerRegistryManager.FullyQualifiedBaseImageAspNet}",
12241227
$"/p:ContainerRepository={imageName}",
1225-
$"/p:ContainerImageTag={imageTag}",
1228+
$"/p:ContainerImageTag={tag}",
12261229
"/p:EnableSdkContainerSupport=true")
12271230
.WithWorkingDirectory(newProjectDir.FullName)
12281231
.Execute()
12291232
.Should().Pass();
12301233

1231-
// Check that the ports are correct
1234+
string imageId = GetImageId(image);
1235+
1236+
// Check that the ports are correct for linux/amd64 platform
12321237
var containerNameX64 = $"test-container-{imageName}-x64";
12331238
CommandResult processResultX64 = ContainerCli.RunCommand(
12341239
_testOutput,
12351240
"--rm",
1241+
"--platform",
1242+
"linux/amd64",
12361243
"--name",
12371244
containerNameX64,
12381245
"-P",
12391246
"--detach",
1240-
imageX64)
1247+
imageId)
12411248
.Execute();
12421249
processResultX64.Should().Pass();
12431250

12441251
// 8080 is the default port
12451252
CheckPorts(containerNameX64, [8080, 8082, 8083], [8081]);
12461253

1247-
// Check that the ports are correct
1254+
// Check that the ports are correct for linux/arm64 platform
12481255
var containerNameArm64 = $"test-container-{imageName}-arm64";
12491256
CommandResult processResultArm64 = ContainerCli.RunCommand(
12501257
_testOutput,
12511258
"--rm",
1259+
"--platform",
1260+
"linux/arm64",
12521261
"--name",
12531262
containerNameArm64,
12541263
"-P",
12551264
"--detach",
1256-
imageArm64)
1265+
imageId)
12571266
.Execute();
12581267
processResultArm64.Should().Pass();
12591268

@@ -1291,8 +1300,8 @@ private void CheckPorts(string containerName, int[] correctPorts, int[] incorrec
12911300
public void EndToEndMultiArch_Labels()
12921301
{
12931302
string imageName = NewImageName();
1294-
string imageTag = "1.0";
1295-
string imageX64 = $"{imageName}:{imageTag}-linux-x64";
1303+
string tag = "1.0";
1304+
string image = $"{imageName}:{tag}";
12961305

12971306
// Create new console app
12981307
DirectoryInfo newProjectDir = CreateNewProject("webapp");
@@ -1305,17 +1314,19 @@ public void EndToEndMultiArch_Labels()
13051314
"/p:RuntimeIdentifiers=\"linux-x64;linux-arm64\"",
13061315
$"/p:ContainerBaseImage={DockerRegistryManager.FullyQualifiedBaseImageAspNet}",
13071316
$"/p:ContainerRepository={imageName}",
1308-
$"/p:ContainerImageTag={imageTag}",
1317+
$"/p:ContainerImageTag={tag}",
13091318
"/p:EnableSdkContainerSupport=true")
13101319
.WithWorkingDirectory(newProjectDir.FullName)
13111320
.Execute()
13121321
.Should().Pass();
13131322

1323+
string imageId = GetImageId(image);
1324+
13141325
// Check that labels are set
13151326
CommandResult inspectResult = ContainerCli.InspectCommand(
13161327
_testOutput,
13171328
"--format={{json .Config.Labels}}",
1318-
imageX64)
1329+
imageId)
13191330
.Execute();
13201331
inspectResult.Should().Pass();
13211332
var labels = JsonSerializer.Deserialize<Dictionary<string, string>>(inspectResult.StdOut);

0 commit comments

Comments
 (0)