public void GenerateBuildMatrixCommand_CustomMatrixOsVersion() { const string CustomMatrixOsVersion = "custom"; using TempFolderContext tempFolderContext = TestHelper.UseTempFolder(); GenerateBuildMatrixCommand command = new(); command.Options.Manifest = Path.Combine(tempFolderContext.Path, "manifest.json"); command.Options.MatrixType = MatrixType.PlatformDependencyGraph; command.Options.DistinctMatrixOsVersions = new string[] { CustomMatrixOsVersion }; Manifest manifest = CreateManifest( CreateRepo("aspnet", CreateImage( CreatePlatform( CreateDockerfile("1.0/aspnet/os/amd64", tempFolderContext), new string[] { "os" })), CreateImage( CreatePlatform( CreateDockerfile("1.0/aspnet/os2/amd64", tempFolderContext), new string[] { "os2" }, osVersion: CustomMatrixOsVersion))), CreateRepo("sdk", CreateImage( CreatePlatform( CreateDockerfile("1.0/sdk/os/amd64", tempFolderContext, "aspnet:os"), new string[] { "tag" })), CreateImage( CreatePlatform( CreateDockerfile("1.0/sdk/os2/amd64", tempFolderContext, "aspnet:os2"), new string[] { "tag2" }, osVersion: CustomMatrixOsVersion))) ); File.WriteAllText(Path.Combine(tempFolderContext.Path, command.Options.Manifest), JsonConvert.SerializeObject(manifest)); command.LoadManifest(); IEnumerable <BuildMatrixInfo> matrixInfos = command.GenerateMatrixInfo(); Assert.Equal(2, matrixInfos.Count()); BuildMatrixInfo matrixInfo = matrixInfos.ElementAt(0); Assert.Equal($"{CustomMatrixOsVersion}Amd64", matrixInfo.Name); Assert.Single(matrixInfo.Legs); Assert.Equal( "--path 1.0/aspnet/os2/amd64/Dockerfile --path 1.0/sdk/os2/amd64/Dockerfile", matrixInfo.Legs.First().Variables.First(variable => variable.Name == "imageBuilderPaths").Value); matrixInfo = matrixInfos.ElementAt(1); Assert.Equal($"linuxAmd64", matrixInfo.Name); Assert.Single(matrixInfo.Legs); Assert.Equal( "--path 1.0/aspnet/os/amd64/Dockerfile --path 1.0/sdk/os/amd64/Dockerfile", matrixInfo.Legs.First().Variables.First(variable => variable.Name == "imageBuilderPaths").Value); }
public void DuplicatedPlatforms(MatrixType matrixType) { TempFolderContext tempFolderContext = TestHelper.UseTempFolder(); GenerateBuildMatrixCommand command = new GenerateBuildMatrixCommand(); command.Options.Manifest = Path.Combine(tempFolderContext.Path, "manifest.json"); command.Options.MatrixType = matrixType; command.Options.ProductVersionComponents = 2; Manifest manifest = CreateManifest( CreateRepo("runtime", CreateImage( new Platform[] { CreatePlatform( DockerfileHelper.CreateDockerfile("3.1/runtime/os", tempFolderContext), new string[] { "tag" }) }, productVersion: "3.1"), CreateImage( new Platform[] { CreatePlatform( DockerfileHelper.CreateDockerfile("3.1/runtime/os", tempFolderContext), Array.Empty <string>()) }, productVersion: "3.1"))); File.WriteAllText(Path.Combine(tempFolderContext.Path, command.Options.Manifest), JsonConvert.SerializeObject(manifest)); command.LoadManifest(); IEnumerable <BuildMatrixInfo> matrixInfos = command.GenerateMatrixInfo(); Assert.Single(matrixInfos); BuildMatrixInfo matrixInfo = matrixInfos.First(); Assert.Single(matrixInfo.Legs); string expectedLegName; if (matrixType == MatrixType.PlatformDependencyGraph) { expectedLegName = "3.1-runtime-os-Dockerfile-graph"; } else { expectedLegName = "3.1-focal-runtime"; } Assert.Equal(expectedLegName, matrixInfo.Legs[0].Name); string imageBuilderPaths = matrixInfo.Legs[0].Variables.First(variable => variable.Name == "imageBuilderPaths").Value; Assert.Equal($"--path 3.1/runtime/os/Dockerfile", imageBuilderPaths); }
public void PlatformDependencyGraph_CrossReferencedDockerfileFromMultipleRepos_SingleDockerfile() { TempFolderContext tempFolderContext = TestHelper.UseTempFolder(); GenerateBuildMatrixCommand command = new GenerateBuildMatrixCommand(); command.Options.Manifest = Path.Combine(tempFolderContext.Path, "manifest.json"); command.Options.MatrixType = MatrixType.PlatformDependencyGraph; command.Options.ProductVersionComponents = 2; const string runtimeDepsRelativeDir = "3.1/runtime-deps/os"; DirectoryInfo runtimeDepsDir = Directory.CreateDirectory( Path.Combine(tempFolderContext.Path, runtimeDepsRelativeDir)); string dockerfileRuntimeDepsFullPath = Path.Combine(runtimeDepsDir.FullName, "Dockerfile"); File.WriteAllText(dockerfileRuntimeDepsFullPath, "FROM base"); Manifest manifest = CreateManifest( CreateRepo("core/runtime-deps", CreateImage( new Platform[] { CreatePlatform(runtimeDepsRelativeDir, new string[] { "tag" }) }, productVersion: "3.1")), CreateRepo("runtime-deps", CreateImage( new Platform[] { CreatePlatform(runtimeDepsRelativeDir, new string[] { "tag" }) }, productVersion: "5.0")), CreateRepo("new/runtime-deps", CreateImage( new Platform[] { CreatePlatform(runtimeDepsRelativeDir, new string[] { "tag" }) }, productVersion: "5.1")) ); File.WriteAllText(Path.Combine(tempFolderContext.Path, command.Options.Manifest), JsonConvert.SerializeObject(manifest)); command.LoadManifest(); IEnumerable <BuildMatrixInfo> matrixInfos = command.GenerateMatrixInfo(); Assert.Single(matrixInfos); BuildMatrixInfo matrixInfo = matrixInfos.First(); Assert.Single(matrixInfo.Legs); Assert.Equal("3.1-runtime-deps-os-graph", matrixInfo.Legs[0].Name); string imageBuilderPaths = matrixInfo.Legs[0].Variables.First(variable => variable.Name == "imageBuilderPaths").Value; Assert.Equal($"--path {runtimeDepsRelativeDir}", imageBuilderPaths); }
public void GenerateBuildMatrixCommand_PlatformDependencyGraph(string filterPaths, string expectedPaths) { using (TempFolderContext tempFolderContext = TestHelper.UseTempFolder()) { GenerateBuildMatrixCommand command = new GenerateBuildMatrixCommand(); command.Options.Manifest = Path.Combine(tempFolderContext.Path, "manifest.json"); command.Options.MatrixType = MatrixType.PlatformDependencyGraph; if (filterPaths != null) { command.Options.FilterOptions.Paths = filterPaths.Replace("--path ", "").Split(" "); } const string runtimeDepsRelativeDir = "1.0/runtimedeps/os/amd64"; DirectoryInfo runtimeDepsDir = Directory.CreateDirectory( Path.Combine(tempFolderContext.Path, runtimeDepsRelativeDir)); string dockerfileRuntimeDepsFullPath = Path.Combine(runtimeDepsDir.FullName, "Dockerfile"); File.WriteAllText(dockerfileRuntimeDepsFullPath, "FROM base"); const string sdkRelativeDir = "1.0/sdk/os/amd64"; DirectoryInfo sdkDir = Directory.CreateDirectory( Path.Combine(tempFolderContext.Path, sdkRelativeDir)); string dockerfileSdkPath = Path.Combine(sdkDir.FullName, "Dockerfile"); File.WriteAllText(dockerfileSdkPath, "FROM runtime-deps:tag"); const string sampleRelativeDir = "1.0/sample/os/amd64"; DirectoryInfo sampleDir = Directory.CreateDirectory( Path.Combine(tempFolderContext.Path, sampleRelativeDir)); string dockerfileSamplePath = Path.Combine(sampleDir.FullName, "Dockerfile"); File.WriteAllText(dockerfileSamplePath, "FROM sdk:tag"); Manifest manifest = CreateManifest( CreateRepo("runtime-deps", CreateImage( CreatePlatform(runtimeDepsRelativeDir, new string[] { "tag" }))), CreateRepo("sdk", CreateImage( CreatePlatform(sdkRelativeDir, new string[] { "tag" }))), CreateRepo("sample", CreateImage( CreatePlatform(sampleRelativeDir, new string[] { "tag" }))) ); File.WriteAllText(Path.Combine(tempFolderContext.Path, command.Options.Manifest), JsonConvert.SerializeObject(manifest)); command.LoadManifest(); IEnumerable <BuildMatrixInfo> matrixInfos = command.GenerateMatrixInfo(); Assert.Single(matrixInfos); BuildMatrixInfo matrixInfo = matrixInfos.First(); BuildLegInfo leg = matrixInfo.Legs.First(); string imageBuilderPaths = leg.Variables.First(variable => variable.Name == "imageBuilderPaths").Value; Assert.Equal(expectedPaths, imageBuilderPaths); } }
public void GenerateBuildMatrixCommand_PlatformVersionedOs(string filterPaths, string expectedPaths, string verificationLegName) { using (TempFolderContext tempFolderContext = TestHelper.UseTempFolder()) { GenerateBuildMatrixCommand command = new GenerateBuildMatrixCommand(); command.Options.Manifest = Path.Combine(tempFolderContext.Path, "manifest.json"); command.Options.MatrixType = MatrixType.PlatformVersionedOs; command.Options.ProductVersionComponents = 3; if (filterPaths != null) { command.Options.FilterOptions.Paths = filterPaths.Replace("--path ", "").Split(" "); } const string runtimeDepsRelativeDir = "2.1.1/runtime-deps/os"; DirectoryInfo runtimeDepsDir = Directory.CreateDirectory( Path.Combine(tempFolderContext.Path, runtimeDepsRelativeDir)); string dockerfileRuntimeDepsFullPath = Path.Combine(runtimeDepsDir.FullName, "Dockerfile"); File.WriteAllText(dockerfileRuntimeDepsFullPath, "FROM base"); const string runtimeRelativeDir = "2.2/runtime/os"; DirectoryInfo runtimeDir = Directory.CreateDirectory( Path.Combine(tempFolderContext.Path, runtimeRelativeDir)); string dockerfileRuntimePath = Path.Combine(runtimeDir.FullName, "Dockerfile"); File.WriteAllText(dockerfileRuntimePath, "FROM runtime-deps:tag"); Manifest manifest = CreateManifest( CreateRepo("runtime-deps", CreateImage( new Platform[] { CreatePlatform(runtimeDepsRelativeDir, new string[] { "tag" }) }, productVersion: "2.1.1")), CreateRepo("runtime", CreateImage( new Platform[] { CreatePlatform(runtimeRelativeDir, new string[] { "runtime" }) }, productVersion: "2.2.3-preview")) ); File.WriteAllText(Path.Combine(tempFolderContext.Path, command.Options.Manifest), JsonConvert.SerializeObject(manifest)); command.LoadManifest(); IEnumerable <BuildMatrixInfo> matrixInfos = command.GenerateMatrixInfo(); Assert.Single(matrixInfos); BuildMatrixInfo matrixInfo = matrixInfos.First(); BuildLegInfo leg = matrixInfo.Legs.First(leg => leg.Name.StartsWith(verificationLegName)); string imageBuilderPaths = leg.Variables.First(variable => variable.Name == "imageBuilderPaths").Value; Assert.Equal(expectedPaths, imageBuilderPaths); } }
public void NonDependentReposWithSameProductVersion(MatrixType matrixType) { TempFolderContext tempFolderContext = TestHelper.UseTempFolder(); GenerateBuildMatrixCommand command = new(); command.Options.Manifest = Path.Combine(tempFolderContext.Path, "manifest.json"); command.Options.MatrixType = matrixType; command.Options.ProductVersionComponents = 2; Manifest manifest = CreateManifest( CreateRepo("repo1", CreateImage( new Platform[] { CreatePlatform( CreateDockerfile("1.0/repo1/os", tempFolderContext), new string[] { "tag" }) }, productVersion: "1.0")), CreateRepo("repo2", CreateImage( new Platform[] { CreatePlatform( CreateDockerfile("1.0/repo2/os", tempFolderContext), new string[] { "tag" }) }, productVersion: "1.0")) ); File.WriteAllText(Path.Combine(tempFolderContext.Path, command.Options.Manifest), JsonConvert.SerializeObject(manifest)); command.LoadManifest(); IEnumerable <BuildMatrixInfo> matrixInfos = command.GenerateMatrixInfo(); Assert.Single(matrixInfos); BuildMatrixInfo matrixInfo = matrixInfos.First(); Assert.Equal(2, matrixInfo.Legs.Count); Assert.Equal(matrixType == MatrixType.PlatformDependencyGraph ? "1.0-repo1-os-Dockerfile" : "1.0-focal-repo1", matrixInfo.Legs[0].Name); string imageBuilderPaths = matrixInfo.Legs[0].Variables.First(variable => variable.Name == "imageBuilderPaths").Value; Assert.Equal($"--path 1.0/repo1/os/Dockerfile", imageBuilderPaths); Assert.Equal(matrixType == MatrixType.PlatformDependencyGraph ? "1.0-repo2-os-Dockerfile" : "1.0-focal-repo2", matrixInfo.Legs[1].Name); imageBuilderPaths = matrixInfo.Legs[1].Variables.First(variable => variable.Name == "imageBuilderPaths").Value; Assert.Equal($"--path 1.0/repo2/os/Dockerfile", imageBuilderPaths); }
public void GenerateBuildMatrixCommand_ServerCoreAndNanoServerDependency() { using TempFolderContext tempFolderContext = TestHelper.UseTempFolder(); const string customBuildLegGrouping = "custom"; GenerateBuildMatrixCommand command = new GenerateBuildMatrixCommand(); command.Options.Manifest = Path.Combine(tempFolderContext.Path, "manifest.json"); command.Options.MatrixType = MatrixType.PlatformDependencyGraph; command.Options.ProductVersionComponents = 2; command.Options.CustomBuildLegGrouping = customBuildLegGrouping; Manifest manifest = CreateManifest( CreateRepo("runtime", CreateImage( new Platform[] { CreatePlatform( DockerfileHelper.CreateDockerfile("1.0/runtime/nanoserver-1909", tempFolderContext), new string[] { "nanoserver-1909" }, os: OS.Windows, osVersion: "nanoserver-1909") }, productVersion: "1.0"), CreateImage( new Platform[] { CreatePlatform( DockerfileHelper.CreateDockerfile("1.0/runtime/windowsservercore-1909", tempFolderContext), new string[] { "windowsservercore-1909" }, os: OS.Windows, osVersion: "windowsservercore-1909") }, productVersion: "1.0")), CreateRepo("aspnet", CreateImage( new Platform[] { CreatePlatform( DockerfileHelper.CreateDockerfile("1.0/aspnet/nanoserver-1909", tempFolderContext, "runtime:nanoserver-1909"), new string[] { "nanoserver-1909" }, os: OS.Windows, osVersion: "nanoserver-1909") }, productVersion: "1.0"), CreateImage( new Platform[] { CreatePlatform( DockerfileHelper.CreateDockerfile("1.0/aspnet/windowsservercore-1909", tempFolderContext, "runtime:windowsservercore-1909"), new string[] { "windowsservercore-1909" }, os: OS.Windows, osVersion: "windowsservercore-1909", customBuildLegGroupings: new CustomBuildLegGrouping[] { new CustomBuildLegGrouping { Name = customBuildLegGrouping, Dependencies = new string[] { "aspnet:nanoserver-1909" } } }) }, productVersion: "1.0")) ); File.WriteAllText(Path.Combine(tempFolderContext.Path, command.Options.Manifest), JsonConvert.SerializeObject(manifest)); command.LoadManifest(); IEnumerable <BuildMatrixInfo> matrixInfos = command.GenerateMatrixInfo(); Assert.Single(matrixInfos); BuildMatrixInfo matrixInfo = matrixInfos.First(); BuildLegInfo leg = matrixInfo.Legs.First(); string imageBuilderPaths = leg.Variables.First(variable => variable.Name == "imageBuilderPaths").Value; Assert.Equal( "--path 1.0/runtime/nanoserver-1909/Dockerfile --path 1.0/aspnet/nanoserver-1909/Dockerfile --path 1.0/runtime/windowsservercore-1909/Dockerfile --path 1.0/aspnet/windowsservercore-1909/Dockerfile", imageBuilderPaths); string osVersions = leg.Variables.First(variable => variable.Name == "osVersions").Value; Assert.Equal( "--os-version nanoserver-1909 --os-version windowsservercore-1909", osVersions); }
public void GenerateBuildMatrixCommand_CustomBuildLegGroupingParentGraph() { using (TempFolderContext tempFolderContext = TestHelper.UseTempFolder()) { const string customBuildLegGrouping = "custom"; GenerateBuildMatrixCommand command = new GenerateBuildMatrixCommand(); command.Options.Manifest = Path.Combine(tempFolderContext.Path, "manifest.json"); command.Options.MatrixType = MatrixType.PlatformVersionedOs; command.Options.ProductVersionComponents = 2; command.Options.CustomBuildLegGrouping = customBuildLegGrouping; string dockerfileRuntimeDepsFullPath = DockerfileHelper.CreateDockerfile("1.0/runtime-deps/os", tempFolderContext); string dockerfileRuntimePath = DockerfileHelper.CreateDockerfile("1.0/runtime/os", tempFolderContext, "runtime-deps:tag"); string dockerfileRuntime2FullPath = DockerfileHelper.CreateDockerfile("2.0/runtime/os2", tempFolderContext); string dockerfileSdk2FullPath = DockerfileHelper.CreateDockerfile("2.0/sdk/os2", tempFolderContext, "runtime2:tag"); Manifest manifest = CreateManifest( CreateRepo("runtime-deps", CreateImage( new Platform[] { CreatePlatform(dockerfileRuntimeDepsFullPath, new string[] { "tag" }) }, productVersion: "1.0")), CreateRepo("runtime", CreateImage( new Platform[] { CreatePlatform(dockerfileRuntimePath, new string[] { "runtime" }, customBuildLegGroupings: new CustomBuildLegGrouping[] { new CustomBuildLegGrouping { Name = customBuildLegGrouping, Dependencies = new string[] { "sdk2:tag" } } }) }, productVersion: "1.0")), CreateRepo("runtime2", CreateImage( new Platform[] { CreatePlatform(dockerfileRuntime2FullPath, new string[] { "tag" }, osVersion: "buster-slim") }, productVersion: "2.0")), CreateRepo("sdk2", CreateImage( new Platform[] { CreatePlatform(dockerfileSdk2FullPath, new string[] { "tag" }, osVersion: "buster") }, productVersion: "2.0")) ); File.WriteAllText(Path.Combine(tempFolderContext.Path, command.Options.Manifest), JsonConvert.SerializeObject(manifest)); command.LoadManifest(); IEnumerable <BuildMatrixInfo> matrixInfos = command.GenerateMatrixInfo(); Assert.Single(matrixInfos); BuildMatrixInfo matrixInfo = matrixInfos.First(); BuildLegInfo leg_1_0 = matrixInfo.Legs.First(); string imageBuilderPaths = leg_1_0.Variables.First(variable => variable.Name == "imageBuilderPaths").Value; Assert.Equal("--path 1.0/runtime-deps/os/Dockerfile --path 1.0/runtime/os/Dockerfile --path 2.0/sdk/os2/Dockerfile --path 2.0/runtime/os2/Dockerfile", imageBuilderPaths); string osVersions = leg_1_0.Variables.First(variable => variable.Name == "osVersions").Value; Assert.Equal("--os-version disco --os-version buster --os-version buster-slim", osVersions); BuildLegInfo leg_2_0 = matrixInfo.Legs.ElementAt(1); imageBuilderPaths = leg_2_0.Variables.First(variable => variable.Name == "imageBuilderPaths").Value; Assert.Equal("--path 2.0/runtime/os2/Dockerfile --path 2.0/sdk/os2/Dockerfile", imageBuilderPaths); osVersions = leg_2_0.Variables.First(variable => variable.Name == "osVersions").Value; Assert.Equal("--os-version buster-slim --os-version buster", osVersions); } }
public void CrossReferencedDockerfileFromMultipleRepos_ImageGraph(MatrixType matrixType) { TempFolderContext tempFolderContext = TestHelper.UseTempFolder(); GenerateBuildMatrixCommand command = new GenerateBuildMatrixCommand(); command.Options.Manifest = Path.Combine(tempFolderContext.Path, "manifest.json"); command.Options.MatrixType = matrixType; command.Options.ProductVersionComponents = 2; Manifest manifest = CreateManifest( CreateRepo("core/runtime-deps", CreateImage( new Platform[] { CreatePlatform( DockerfileHelper.CreateDockerfile("3.1/runtime-deps/os", tempFolderContext), new string[] { "tag" }) }, productVersion: "3.1")), CreateRepo("core/runtime", CreateImage( new Platform[] { CreatePlatform( DockerfileHelper.CreateDockerfile("3.1/runtime/os", tempFolderContext, "core/runtime-deps:tag"), new string[] { "tag" }) }, productVersion: "3.1")), CreateRepo("runtime-deps", CreateImage( new Platform[] { CreatePlatform( "3.1/runtime-deps/os/Dockerfile", new string[] { "tag" }) }, productVersion: "5.0")), CreateRepo("runtime", CreateImage( new Platform[] { CreatePlatform( DockerfileHelper.CreateDockerfile("5.0/runtime/os", tempFolderContext, "runtime-deps:tag"), new string[] { "tag" }) }, productVersion: "5.0")) ); File.WriteAllText(Path.Combine(tempFolderContext.Path, command.Options.Manifest), JsonConvert.SerializeObject(manifest)); command.LoadManifest(); IEnumerable <BuildMatrixInfo> matrixInfos = command.GenerateMatrixInfo(); Assert.Single(matrixInfos); BuildMatrixInfo matrixInfo = matrixInfos.First(); if (matrixType == MatrixType.PlatformDependencyGraph) { Assert.Single(matrixInfo.Legs); Assert.Equal("3.1-runtime-deps-os-Dockerfile-graph", matrixInfo.Legs[0].Name); string imageBuilderPaths = matrixInfo.Legs[0].Variables.First(variable => variable.Name == "imageBuilderPaths").Value; Assert.Equal($"--path 3.1/runtime-deps/os/Dockerfile --path 3.1/runtime/os/Dockerfile --path 5.0/runtime/os/Dockerfile", imageBuilderPaths); } else { Assert.Equal(2, matrixInfo.Legs.Count); Assert.Equal("3.1-focal-core-runtime-deps", matrixInfo.Legs[0].Name); string imageBuilderPaths = matrixInfo.Legs[0].Variables.First(variable => variable.Name == "imageBuilderPaths").Value; Assert.Equal($"--path 3.1/runtime-deps/os/Dockerfile --path 3.1/runtime/os/Dockerfile", imageBuilderPaths); Assert.Equal("5.0-focal-runtime-deps", matrixInfo.Legs[1].Name); imageBuilderPaths = matrixInfo.Legs[1].Variables.First(variable => variable.Name == "imageBuilderPaths").Value; Assert.Equal($"--path 3.1/runtime-deps/os/Dockerfile --path 5.0/runtime/os/Dockerfile", imageBuilderPaths); } }
public void GenerateBuildMatrixCommand_MultiBuildLegGroups() { using TempFolderContext tempFolderContext = TestHelper.UseTempFolder(); const string customBuildLegGroup1 = "custom1"; const string customBuildLegGroup2 = "custom2"; GenerateBuildMatrixCommand command = new GenerateBuildMatrixCommand(); command.Options.Manifest = Path.Combine(tempFolderContext.Path, "manifest.json"); command.Options.MatrixType = MatrixType.PlatformVersionedOs; command.Options.ProductVersionComponents = 2; command.Options.CustomBuildLegGroups = new string[] { customBuildLegGroup1, customBuildLegGroup2 }; Manifest manifest = CreateManifest( CreateRepo("repo1", CreateImage( new Platform[] { CreatePlatform( DockerfileHelper.CreateDockerfile("1.0/repo1/os", tempFolderContext), new string[] { "tag" }, osVersion: "bionic") }, productVersion: "1.0")), CreateRepo("repo2", CreateImage( new Platform[] { CreatePlatform( DockerfileHelper.CreateDockerfile("1.0/repo2/os", tempFolderContext), new string[] { "tag" }, osVersion: "focal", customBuildLegGroups: new CustomBuildLegGroup[] { new CustomBuildLegGroup { Name = customBuildLegGroup1, Type = CustomBuildLegDependencyType.Supplemental, Dependencies = new string[] { "repo1:tag" } } }) }, productVersion: "1.0")), CreateRepo("repo3", CreateImage( new Platform[] { CreatePlatform( DockerfileHelper.CreateDockerfile("1.0/repo3/os", tempFolderContext), new string[] { "tag" }, osVersion: "buster") }, productVersion: "1.0")), CreateRepo("repo4", CreateImage( new Platform[] { CreatePlatform( DockerfileHelper.CreateDockerfile("1.0/repo4/os", tempFolderContext), new string[] { "tag" }, osVersion: "bullseye", customBuildLegGroups: new CustomBuildLegGroup[] { new CustomBuildLegGroup { Name = customBuildLegGroup1, Type = CustomBuildLegDependencyType.Integral, Dependencies = new string[] { "repo3:tag" } } }) }, productVersion: "1.0")) ); File.WriteAllText(Path.Combine(tempFolderContext.Path, command.Options.Manifest), JsonConvert.SerializeObject(manifest)); command.LoadManifest(); IEnumerable <BuildMatrixInfo> matrixInfos = command.GenerateMatrixInfo(); Assert.Single(matrixInfos); BuildMatrixInfo matrixInfo = matrixInfos.First(); Assert.Equal(3, matrixInfo.Legs.Count()); BuildLegInfo leg = matrixInfo.Legs.First(); string imageBuilderPaths = leg.Variables.First(variable => variable.Name == "imageBuilderPaths").Value; Assert.Equal( "--path 1.0/repo1/os/Dockerfile", imageBuilderPaths); leg = matrixInfo.Legs.ElementAt(1); imageBuilderPaths = leg.Variables.First(variable => variable.Name == "imageBuilderPaths").Value; Assert.Equal( "--path 1.0/repo2/os/Dockerfile --path 1.0/repo1/os/Dockerfile", imageBuilderPaths); leg = matrixInfo.Legs.ElementAt(2); imageBuilderPaths = leg.Variables.First(variable => variable.Name == "imageBuilderPaths").Value; Assert.Equal( "--path 1.0/repo3/os/Dockerfile --path 1.0/repo4/os/Dockerfile", imageBuilderPaths); }
public void GenerateBuildMatrixCommand_ParentGraphOutsidePlatformGroup() { using TempFolderContext tempFolderContext = TestHelper.UseTempFolder(); GenerateBuildMatrixCommand command = new GenerateBuildMatrixCommand(); command.Options.Manifest = Path.Combine(tempFolderContext.Path, "manifest.json"); command.Options.MatrixType = MatrixType.PlatformVersionedOs; command.Options.ProductVersionComponents = 2; string dockerfileRuntimeFullPath = DockerfileHelper.CreateDockerfile("1.0/runtime/os", tempFolderContext); string dockerfileRuntime2FullPath = DockerfileHelper.CreateDockerfile("1.0/runtime2/os", tempFolderContext, "sdk3:tag"); string dockerfileRuntime3FullPath = DockerfileHelper.CreateDockerfile("1.0/runtime3/os2", tempFolderContext); string dockerfileSdk3FullPath = DockerfileHelper.CreateDockerfile("1.0/sdk3/os2", tempFolderContext, "runtime3:tag"); Manifest manifest = CreateManifest( // Define a Dockerfile that has the same OS version and product version as runtime2 but no actual dependency to // ensure it gets its own matrix leg. CreateRepo("runtime", CreateImage( new Platform[] { CreatePlatform(dockerfileRuntimeFullPath, new string[] { "tag" }, osVersion: "buster") }, productVersion: "1.0")), CreateRepo("runtime2", CreateImage( new Platform[] { CreatePlatform(dockerfileRuntime2FullPath, new string[] { "runtime" }, osVersion: "bullseye") }, productVersion: "1.0")), CreateRepo("runtime3", CreateImage( new Platform[] { CreatePlatform(dockerfileRuntime3FullPath, new string[] { "tag" }, osVersion: "alpine3.12") }, productVersion: "1.0")), CreateRepo("sdk3", CreateImage( new Platform[] { CreatePlatform(dockerfileSdk3FullPath, new string[] { "tag" }, osVersion: "alpine3.12") }, productVersion: "1.0")) ); File.WriteAllText(Path.Combine(tempFolderContext.Path, command.Options.Manifest), JsonConvert.SerializeObject(manifest)); command.LoadManifest(); IEnumerable <BuildMatrixInfo> matrixInfos = command.GenerateMatrixInfo(); Assert.Single(matrixInfos); BuildMatrixInfo matrixInfo = matrixInfos.First(); Assert.Equal(2, matrixInfo.Legs.Count); BuildLegInfo leg_1_0 = matrixInfo.Legs.First(); string imageBuilderPaths = leg_1_0.Variables.First(variable => variable.Name == "imageBuilderPaths").Value; Assert.Equal("--path 1.0/runtime/os/Dockerfile", imageBuilderPaths); BuildLegInfo leg_2_0 = matrixInfo.Legs.ElementAt(1); imageBuilderPaths = leg_2_0.Variables.First(variable => variable.Name == "imageBuilderPaths").Value; Assert.Equal("--path 1.0/runtime2/os/Dockerfile --path 1.0/sdk3/os2/Dockerfile --path 1.0/runtime3/os2/Dockerfile", imageBuilderPaths); }