示例#1
0
        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);
            }
        }
示例#2
0
        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);
            }
        }
示例#3
0
        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);
        }
示例#4
0
        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);
            }
        }
示例#5
0
        public void PlatformVersionedOs_Cached(bool isRuntimeCached, bool isAspnetCached, bool isSdkCached, string expectedPaths)
        {
            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.ImageInfoPath            = Path.Combine(tempFolderContext.Path, "imageinfo.json");
            command.Options.ProductVersionComponents = 2;

            string   runtimeDockerfilePath;
            string   aspnetDockerfilePath;
            string   sdkDockerfilePath;
            Manifest manifest = CreateManifest(
                CreateRepo("runtime",
                           CreateImage(
                               new Platform[]
            {
                CreatePlatform(
                    runtimeDockerfilePath = DockerfileHelper.CreateDockerfile("1.0/runtime/os", tempFolderContext),
                    new string[] { "tag" })
            },
                               productVersion: "1.0")),
                CreateRepo("aspnet",
                           CreateImage(
                               new Platform[]
            {
                CreatePlatform(
                    aspnetDockerfilePath = DockerfileHelper.CreateDockerfile("1.0/aspnet/os", tempFolderContext, "runtime:tag"),
                    new string[] { "tag" })
            },
                               productVersion: "1.0")),
                CreateRepo("sdk",
                           CreateImage(
                               new Platform[]
            {
                CreatePlatform(
                    sdkDockerfilePath = DockerfileHelper.CreateDockerfile("1.0/sdk/os", tempFolderContext, "aspnet:tag"),
                    new string[] { "tag" })
            },
                               productVersion: "1.0"))
                );

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

            ImageArtifactDetails imageArtifactDetails = new ImageArtifactDetails
            {
                Repos =
                {
                    new RepoData
                    {
                        Repo   = "runtime",
                        Images =
                        {
                            new ImageData
                            {
                                ProductVersion = "1.0",
                                Platforms      =
                                {
                                    CreateSimplePlatformData(runtimeDockerfilePath, isCached: isRuntimeCached)
                                }
                            }
                        }
                    },
                    new RepoData
                    {
                        Repo   = "aspnet",
                        Images =
                        {
                            new ImageData
                            {
                                ProductVersion = "1.0",
                                Platforms      =
                                {
                                    CreateSimplePlatformData(aspnetDockerfilePath, isCached: isAspnetCached)
                                }
                            }
                        }
                    },
                    new RepoData
                    {
                        Repo   = "sdk",
                        Images =
                        {
                            new ImageData
                            {
                                ProductVersion = "1.0",
                                Platforms      =
                                {
                                    CreateSimplePlatformData(sdkDockerfilePath, isCached: isSdkCached)
                                }
                            }
                        }
                    }
                }
            };

            File.WriteAllText(command.Options.ImageInfoPath, JsonHelper.SerializeObject(imageArtifactDetails));

            command.LoadManifest();
            IEnumerable <BuildMatrixInfo> matrixInfos = command.GenerateMatrixInfo();

            if (isRuntimeCached && isAspnetCached && isSdkCached)
            {
                Assert.Empty(matrixInfos);
            }
            else
            {
                Assert.Single(matrixInfos);
                Assert.Single(matrixInfos.First().Legs);

                BuildLegInfo buildLeg          = matrixInfos.First().Legs.First();
                string       imageBuilderPaths = buildLeg.Variables.First(variable => variable.Name == "imageBuilderPaths").Value;

                Assert.Equal(expectedPaths, imageBuilderPaths);
            }
        }
示例#6
0
        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);
        }
示例#7
0
        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);
        }