public void Load_Include_Repos() { const string includeManifestPath1 = "manifest.custom1.json"; const string includeManifestPath2 = "manifest.custom2.json"; string manifest = $@" {{ ""includes"": [ ""{includeManifestPath1}"", ""{includeManifestPath2}"" ] }}"; string includeManifest1 = $@" {{ ""repos"": [ {CreateRepo("testRepo1", s_dockerfilePath, "testTag1")}, {CreateRepo("testRepo2", s_dockerfilePath)} ] }}"; string includeManifest2 = $@" {{ ""repos"": [ {CreateRepo("testRepo1", s_dockerfilePath, "testTag2")}, {CreateRepo("testRepo3", s_dockerfilePath)} ] }}"; using TempFolderContext tempFolderContext = TestHelper.UseTempFolder(); string manifestPath = Path.Combine(tempFolderContext.Path, "manifest.json"); File.WriteAllText(manifestPath, manifest); File.WriteAllText(Path.Combine(tempFolderContext.Path, includeManifestPath1), includeManifest1); File.WriteAllText(Path.Combine(tempFolderContext.Path, includeManifestPath2), includeManifest2); DockerfileHelper.CreateDockerfile(s_dockerfilePath, tempFolderContext); IManifestOptionsInfo manifestOptions = ManifestHelper.GetManifestOptions(manifestPath); ManifestInfo manifestInfo = ManifestInfo.Load(manifestOptions); Assert.Equal(3, manifestInfo.Model.Repos.Length); Assert.Equal("testRepo1", manifestInfo.Model.Repos[0].Name); Assert.Equal("testRepo2", manifestInfo.Model.Repos[1].Name); Assert.Equal("testRepo3", manifestInfo.Model.Repos[2].Name); Assert.Equal(2, manifestInfo.Model.Repos[0].Images.Length); Assert.Equal(1, manifestInfo.Model.Repos[1].Images.Length); Assert.Equal(1, manifestInfo.Model.Repos[2].Images.Length); }
private static ManifestInfo LoadManifestInfo(string manifest, string includeManifestPath = null, string includeManifest = null) { using TempFolderContext tempFolderContext = TestHelper.UseTempFolder(); string manifestPath = Path.Combine(tempFolderContext.Path, "manifest.json"); File.WriteAllText(manifestPath, manifest); if (includeManifestPath != null) { string fullIncludeManifestPath = Path.Combine(tempFolderContext.Path, includeManifestPath); File.WriteAllText(fullIncludeManifestPath, includeManifest); } DockerfileHelper.CreateDockerfile(s_dockerfilePath, tempFolderContext); IManifestOptionsInfo manifestOptions = ManifestHelper.GetManifestOptions(manifestPath); return(ManifestInfo.Load(manifestOptions)); }
public void DockerfileUrl(string sourceRepoBranch) { using TempFolderContext tempFolderContext = TestHelper.UseTempFolder(); const string SourceRepoUrl = "https://www.github.com/dotnet/dotnet-docker"; const string RepoName = "repo"; const string TagName = "tag"; // Create Dockerfile string DockerfileDir = $"1.0/{RepoName}/os"; Directory.CreateDirectory(Path.Combine(tempFolderContext.Path, DockerfileDir)); string dockerfileRelativePath = Path.Combine(DockerfileDir, "Dockerfile"); string dockerfileFullPath = PathHelper.NormalizePath(Path.Combine(tempFolderContext.Path, dockerfileRelativePath)); File.WriteAllText(dockerfileFullPath, "FROM base:tag"); // Create MCR tags metadata template file StringBuilder tagsMetadataTemplateBuilder = new StringBuilder(); tagsMetadataTemplateBuilder.AppendLine($"$(McrTagsYmlRepo:{RepoName})"); tagsMetadataTemplateBuilder.Append($"$(McrTagsYmlTagGroup:{TagName})"); string tagsMetadataTemplatePath = Path.Combine(tempFolderContext.Path, "tags.yaml"); File.WriteAllText(tagsMetadataTemplatePath, tagsMetadataTemplateBuilder.ToString()); string emptyFileName = "emptyFile.md"; string emptyFilePath = Path.Combine(tempFolderContext.Path, emptyFileName); File.WriteAllText(emptyFilePath, string.Empty); // Create manifest Manifest manifest = ManifestHelper.CreateManifest( ManifestHelper.CreateRepo(RepoName, new Image[] { ManifestHelper.CreateImage( ManifestHelper.CreatePlatform(dockerfileRelativePath, new string[] { TagName })) }, readme: emptyFileName, readmeTemplate: emptyFileName, mcrTagsMetadataTemplate: Path.GetFileName(tagsMetadataTemplatePath)) ); string manifestPath = Path.Combine(tempFolderContext.Path, "manifest.json"); File.WriteAllText(manifestPath, JsonConvert.SerializeObject(manifest)); // Load manifest IManifestOptionsInfo manifestOptions = ManifestHelper.GetManifestOptions(manifestPath); ManifestInfo manifestInfo = ManifestInfo.Load(manifestOptions); RepoInfo repo = manifestInfo.AllRepos.First(); Mock <IGitService> gitServiceMock = new Mock <IGitService>(); const string DockerfileSha = "random_sha"; if (sourceRepoBranch == null) { gitServiceMock .Setup(o => o.GetCommitSha(dockerfileFullPath, true)) .Returns(DockerfileSha); } // Execute generator string result = McrTagsMetadataGenerator.Execute( gitServiceMock.Object, manifestInfo, repo, SourceRepoUrl, sourceRepoBranch); TagsMetadata tagsMetadata = new DeserializerBuilder() .WithNamingConvention(CamelCaseNamingConvention.Instance) .Build() .Deserialize <TagsMetadata>(result); string branchOrSha = sourceRepoBranch ?? DockerfileSha; Assert.Equal($"{SourceRepoUrl}/blob/{branchOrSha}/{DockerfileDir}/Dockerfile", tagsMetadata.Repos[0].TagGroups[0].Dockerfile); }
public void DuplicatedPlatform() { using TempFolderContext tempFolderContext = TestHelper.UseTempFolder(); const string SourceRepoUrl = "https://www.github.com/dotnet/dotnet-docker"; const string RepoName = "repo"; const string SourceBranch = "branch"; // Create MCR tags metadata template file StringBuilder tagsMetadataTemplateBuilder = new StringBuilder(); tagsMetadataTemplateBuilder.AppendLine($"$(McrTagsYmlRepo:{RepoName})"); tagsMetadataTemplateBuilder.AppendLine($"$(McrTagsYmlTagGroup:concreteTagA)"); string tagsMetadataTemplatePath = Path.Combine(tempFolderContext.Path, "tags.yaml"); File.WriteAllText(tagsMetadataTemplatePath, tagsMetadataTemplateBuilder.ToString()); string emptyFileName = "emptyFile.md"; string emptyFilePath = Path.Combine(tempFolderContext.Path, emptyFileName); File.WriteAllText(emptyFilePath, string.Empty); // Create manifest Manifest manifest = ManifestHelper.CreateManifest( ManifestHelper.CreateRepo(RepoName, new Image[] { ManifestHelper.CreateImage( new Platform[] { ManifestHelper.CreatePlatform( DockerfileHelper.CreateDockerfile($"1.0/{RepoName}/os", tempFolderContext), new string[] { "concreteTagZ", "concreteTagA" }) }, sharedTags: new Dictionary <string, Tag> { { "shared1", new Tag() }, { "latest", new Tag() }, }), ManifestHelper.CreateImage( new Platform[] { ManifestHelper.CreatePlatform( DockerfileHelper.CreateDockerfile($"1.0/{RepoName}/os", tempFolderContext), Array.Empty <string>()) }, sharedTags: new Dictionary <string, Tag> { { "shared2", new Tag() } }) }, readme: emptyFileName, readmeTemplate: emptyFileName, mcrTagsMetadataTemplate: Path.GetFileName(tagsMetadataTemplatePath)) ); string manifestPath = Path.Combine(tempFolderContext.Path, "manifest.json"); File.WriteAllText(manifestPath, JsonConvert.SerializeObject(manifest)); // Load manifest IManifestOptionsInfo manifestOptions = ManifestHelper.GetManifestOptions(manifestPath); ManifestInfo manifestInfo = ManifestInfo.Load(manifestOptions); RepoInfo repo = manifestInfo.AllRepos.First(); Mock <IGitService> gitServiceMock = new Mock <IGitService>(); // Execute generator string result = McrTagsMetadataGenerator.Execute( gitServiceMock.Object, manifestInfo, repo, SourceRepoUrl, SourceBranch); TagsMetadata tagsMetadata = new DeserializerBuilder() .WithNamingConvention(CamelCaseNamingConvention.Instance) .Build() .Deserialize <TagsMetadata>(result); // Verify the output only contains the platform with the documented tag Assert.Single(tagsMetadata.Repos[0].TagGroups); Assert.Equal( $"{SourceRepoUrl}/blob/{SourceBranch}/1.0/{RepoName}/os/Dockerfile", tagsMetadata.Repos[0].TagGroups[0].Dockerfile); List <string> expectedTags = new List <string> { "concreteTagZ", "concreteTagA", "shared2", "shared1", "latest" }; Assert.Equal(expectedTags, tagsMetadata.Repos[0].TagGroups[0].Tags); }