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
Original file line number Diff line number Diff line change
Expand Up @@ -407,17 +407,22 @@ private static string FormatMatrixName(IEnumerable<string> parts)

private async Task<IEnumerable<PlatformInfo>> GetPlatformsAsync()
{
IEnumerable<PlatformInfo> filteredPlatforms = Manifest.GetFilteredPlatforms().ToList();

if (_imageArtifactDetails.Value is null)
{
return Manifest.GetFilteredPlatforms();
return filteredPlatforms;
}

IEnumerable<(PlatformInfo PlatformInfo, ImageData ImageData, PlatformData PlatformData)> platformMappings =
_imageArtifactDetails.Value.Repos
.SelectMany(repo => repo.Images)
.SelectMany(image =>
image.Platforms
.Where(platform => !platform.IsUnchanged && platform.PlatformInfo is not null)
.Where(platform =>
!platform.IsUnchanged &&
platform.PlatformInfo is not null &&
filteredPlatforms.Contains(platform.PlatformInfo))
.Select(platform => (platform.PlatformInfo!, image, platform)));

if (!Options.TrimCachedImages)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,24 +177,34 @@ private static void SetCacheResult(Mock<IImageCacheService> imageCacheServiceMoc
[InlineData(
ImageCacheState.Cached,
ImageCacheState.Cached,
"--path 2.0/runtime/os/amd64/Dockerfile --path 2.0/sdk/os/amd64/Dockerfile",
null)]
"--path 2.0/runtime/os/amd64/Dockerfile --path 2.0/sdk/os/amd64/Dockerfile")]
[InlineData(
ImageCacheState.CachedWithMissingTags,
ImageCacheState.Cached,
"--path 2.0/runtime/os/amd64/Dockerfile --path 2.0/sdk/os/amd64/Dockerfile",
null)]
"--path 2.0/runtime/os/amd64/Dockerfile --path 2.0/sdk/os/amd64/Dockerfile")]
[InlineData(
ImageCacheState.Cached,
ImageCacheState.NotCached,
"--path 1.0/runtime/os/amd64/Dockerfile --path 1.0/sdk/os/amd64/Dockerfile",
"--path 2.0/runtime/os/amd64/Dockerfile --path 2.0/sdk/os/amd64/Dockerfile")]
[InlineData(
ImageCacheState.NotCached,
ImageCacheState.NotCached,
"--path 1.0/runtime/os/amd64/Dockerfile --path 1.0/sdk/os/amd64/Dockerfile",
"--path 1.0/standalone/os/amd64/Dockerfile",
"--path 2.0/runtime/os/amd64/Dockerfile --path 2.0/sdk/os/amd64/Dockerfile",
"")] // Clear out the path filters to ensure all images are included
public async Task FilterOutCachedImages(
ImageCacheState runtime1CacheState,
ImageCacheState sdk1CacheState,
string leg1ExpectedPaths,
string leg2ExpectedPaths)
string? leg2ExpectedPaths = null,
string? leg3ExpectedPaths = null,
string inputPathFilters = "*runtime* *sdk*")
{
const string StandaloneRelativeDir = "1.0/standalone/os/amd64";
string dockerfileStandalonePath;

const string Runtime1RelativeDir = "1.0/runtime/os/amd64";
string dockerfileRuntime1Path;
const string Runtime2RelativeDir = "2.0/runtime/os/amd64";
Expand All @@ -208,6 +218,9 @@ public async Task FilterOutCachedImages(
using TempFolderContext tempFolderContext = TestHelper.UseTempFolder();

Manifest manifest = CreateManifest(
CreateRepo("standalone",
CreateImage(
CreatePlatform(dockerfileStandalonePath = CreateDockerfile(StandaloneRelativeDir, tempFolderContext), ["1.0"]))),
CreateRepo("runtime",
CreateImage(
CreatePlatform(dockerfileRuntime1Path = CreateDockerfile(Runtime1RelativeDir, tempFolderContext, "base"), ["1.0"])),
Expand All @@ -221,6 +234,7 @@ public async Task FilterOutCachedImages(
);

Mock<IImageCacheService> imageCacheServiceMock = new();
SetCacheResult(imageCacheServiceMock, dockerfileStandalonePath, ImageCacheState.NotCached);
SetCacheResult(imageCacheServiceMock, dockerfileRuntime1Path, runtime1CacheState);
SetCacheResult(imageCacheServiceMock, dockerfileSdk1Path, sdk1CacheState);
SetCacheResult(imageCacheServiceMock, dockerfileRuntime2Path, ImageCacheState.NotCached);
Expand All @@ -231,13 +245,28 @@ public async Task FilterOutCachedImages(
command.Options.MatrixType = MatrixType.PlatformDependencyGraph;
command.Options.ImageInfoPath = Path.Combine(tempFolderContext.Path, "imageinfo.json");
command.Options.TrimCachedImages = true;
command.Options.FilterOptions.Paths = inputPathFilters.Split(" ", StringSplitOptions.RemoveEmptyEntries);

File.WriteAllText(Path.Combine(tempFolderContext.Path, command.Options.Manifest), JsonConvert.SerializeObject(manifest));

ImageArtifactDetails imageArtifactDetails = new()
{
Repos =
{
new RepoData
{
Repo = "standalone",
Images =
{
new ImageData
{
Platforms =
{
CreateSimplePlatformData(dockerfileStandalonePath)
}
}
}
},
new RepoData
{
Repo = "runtime",
Expand Down Expand Up @@ -299,6 +328,13 @@ public async Task FilterOutCachedImages(
imageBuilderPaths = leg.Variables.First(variable => variable.Name == "imageBuilderPaths").Value;
Assert.Equal(leg2ExpectedPaths, imageBuilderPaths);
}

if (leg3ExpectedPaths is not null)
{
leg = matrixInfo.Legs.Skip(2).First();
imageBuilderPaths = leg.Variables.First(variable => variable.Name == "imageBuilderPaths").Value;
Assert.Equal(leg3ExpectedPaths, imageBuilderPaths);
}
}

/// <summary>
Expand Down