Skip to content

Commit e9b3e24

Browse files
committed
Use Dockerfile paths to determine which test data is in scope (#4207)
(cherry picked from commit 6609af4)
1 parent 9b731e9 commit e9b3e24

19 files changed

+251
-192
lines changed

eng/common/templates/stages/build-test-publish-repo.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ stages:
6060
# values aren't actually used for the pre-build tests.
6161
- powershell: |
6262
echo "##vso[task.setvariable variable=productVersion]"
63+
echo "##vso[task.setvariable variable=imageBuilderPaths]"
6364
echo "##vso[task.setvariable variable=osVersions]"
6465
echo "##vso[task.setvariable variable=architecture]"
6566
displayName: Initialize Test Variables

eng/common/templates/steps/parse-os-versions.yml renamed to eng/common/templates/steps/parse-test-arg-arrays.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@ steps:
44
$osVersionsDisplayName = '$(osVersions)' -Replace '--os-version ', '' -Replace ' ', '/'
55
66
# Defines a PowerShell snippet in string-form that can be used to initialize an array of the OS versions
7-
$osVersionsArrayInitStr="@('" + $($osVersionsDisplayName -Replace "/", "', '") + "')"
7+
$osVersionsArrayInitStr = "@('" + $($osVersionsDisplayName -Replace "/", "', '") + "')"
88
99
echo "##vso[task.setvariable variable=osVersionsDisplayName]$osVersionsDisplayName"
1010
echo "##vso[task.setvariable variable=osVersionsArrayInitStr]$osVersionsArrayInitStr"
11-
displayName: Parse OS Versions
11+
12+
# Defines a PowerShell snippet in string-form that can be used to initialize an array of the image builder paths
13+
$pathInitStr = "@('" + $('$(imageBuilderPaths)' -Replace '--path', '' -Replace " ", "', '") + "')"
14+
echo "##vso[task.setvariable variable=imageBuilderPathsArrayInitStr]$pathInitStr"
15+
displayName: Parse Test Arg Arrays

eng/common/templates/steps/test-images-linux-client.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@ steps:
5050
parameters:
5151
targetPath: $(Build.ArtifactStagingDirectory)
5252
condition: ${{ parameters.condition }}
53-
- template: parse-os-versions.yml
53+
- template: parse-test-arg-arrays.yml
5454
- powershell: >
5555
$(test.init);
5656
docker exec
5757
$(testRunner.options)
5858
$(testRunner.container)
5959
pwsh
6060
-Command "$(testScriptPath)
61-
-Version '$(productVersion)'
61+
-Paths $(imageBuilderPathsArrayInitStr)
6262
-OSVersions $(osVersionsArrayInitStr)
6363
-Architecture '$(architecture)'
6464
$(optionalTestArgs)"

eng/common/templates/steps/test-images-windows-client.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ steps:
3333
parameters:
3434
targetPath: $(Build.ArtifactStagingDirectory)
3535
condition: ${{ parameters.condition }}
36-
- template: parse-os-versions.yml
36+
- template: parse-test-arg-arrays.yml
3737
- powershell: >
3838
$(test.init);
3939
$(testScriptPath)
40-
-Version '$(productVersion)'
40+
-Paths $(imageBuilderPathsArrayInitStr)
4141
-OSVersions $(osVersionsArrayInitStr)
4242
$(optionalTestArgs)
4343
displayName: Test Images

tests/Microsoft.DotNet.Docker.Tests/AspnetImageTests.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ public AspnetImageTests(ITestOutputHelper outputHelper)
2020

2121
protected override DotNetImageType ImageType => DotNetImageType.Aspnet;
2222

23+
public static IEnumerable<object[]> GetImageData() => GetImageData(DotNetImageType.Aspnet);
24+
2325
[DotNetTheory]
2426
[MemberData(nameof(GetImageData))]
2527
public async Task VerifyAppScenario(ProductImageData imageData)
@@ -70,6 +72,20 @@ public void VerifyPackageInstallation(ProductImageData imageData)
7072
.Concat(RuntimeImageTests.GetExpectedRpmPackagesInstalled(imageData)));
7173
}
7274

75+
[LinuxImageTheory]
76+
[MemberData(nameof(GetImageData))]
77+
public void VerifyInsecureFiles(ProductImageData imageData)
78+
{
79+
base.VerifyCommonInsecureFiles(imageData);
80+
}
81+
82+
[LinuxImageTheory]
83+
[MemberData(nameof(GetImageData))]
84+
public void VerifyShellNotInstalledForDistroless(ProductImageData imageData)
85+
{
86+
base.VerifyCommonShellNotInstalledForDistroless(imageData);
87+
}
88+
7389
[DotNetTheory]
7490
[MemberData(nameof(GetImageData))]
7591
public void VerifyNoSasToken(ProductImageData imageData)

tests/Microsoft.DotNet.Docker.Tests/CommonRuntimeImageTests.cs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ protected CommonRuntimeImageTests(ITestOutputHelper outputHelper)
1717
{
1818
}
1919

20-
public static IEnumerable<object[]> GetImageData()
20+
public static IEnumerable<object[]> GetImageData(DotNetImageType imageType)
2121
{
22-
return TestData.GetImageData()
22+
return TestData.GetImageData(imageType)
2323
.Select(imageData => new object[] { imageData });
2424
}
2525

@@ -46,16 +46,7 @@ protected void VerifyCommonEnvironmentVariables(
4646
EnvironmentVariableInfo.Validate(variables, imageTag, imageData, DockerHelper);
4747
}
4848

49-
[LinuxImageTheory]
50-
[MemberData(nameof(GetImageData))]
51-
public void VerifyInsecureFiles(ProductImageData imageData)
52-
{
53-
base.VerifyCommonInsecureFiles(imageData);
54-
}
55-
56-
[LinuxImageTheory]
57-
[MemberData(nameof(GetImageData))]
58-
public void VerifyShellNotInstalledForDistroless(ProductImageData imageData)
49+
public void VerifyCommonShellNotInstalledForDistroless(ProductImageData imageData)
5950
{
6051
if (!imageData.IsDistroless)
6152
{

tests/Microsoft.DotNet.Docker.Tests/Config.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ public static class Config
3434
Environment.GetEnvironmentVariable("SAS_QUERY_STRING") ?? string.Empty;
3535
public static string NuGetFeedPassword { get; } =
3636
Environment.GetEnvironmentVariable("NUGET_FEED_PASSWORD") ?? string.Empty;
37+
public static string[] Paths { get; } =
38+
Environment.GetEnvironmentVariable("DOCKERFILE_PATHS")?
39+
.Split(',', StringSplitOptions.RemoveEmptyEntries) ?? Array.Empty<string>();
3740

3841
public static bool IsInternal(string dotnetVersion)
3942
{

tests/Microsoft.DotNet.Docker.Tests/DotNetImageType.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ public enum DotNetImageType
1010
Runtime,
1111
Runtime_Deps,
1212
Aspnet,
13+
Monitor
1314
}
1415
}

tests/Microsoft.DotNet.Docker.Tests/ImageData.cs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -147,22 +147,23 @@ protected string GetTagName(string tagPrefix, string os) =>
147147

148148
protected virtual string GetArchTagSuffix()
149149
{
150-
if (Arch == Arch.Amd64 && DockerHelper.IsLinuxContainerModeEnabled)
150+
if (Arch == Arch.Amd64 && !DockerHelper.IsLinuxContainerModeEnabled)
151151
{
152-
return "-amd64";
153-
}
154-
else if (Arch == Arch.Arm)
155-
{
156-
return "-arm32v7";
157-
}
158-
else if (Arch == Arch.Arm64)
159-
{
160-
return "-arm64v8";
152+
return string.Empty;
161153
}
162154

163-
return string.Empty;
155+
return $"-{GetArchLabel()}";
164156
}
165157

158+
protected string GetArchLabel() =>
159+
Arch switch
160+
{
161+
Arch.Amd64 => "amd64",
162+
Arch.Arm => "arm32v7",
163+
Arch.Arm64 => "arm64v8",
164+
_ => throw new NotSupportedException()
165+
};
166+
166167
private static string GetRegistryName(string repo, string tag)
167168
{
168169
bool imageExistsInStaging = true;

tests/Microsoft.DotNet.Docker.Tests/MonitorImageData.cs

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)