示例#1
0
        public async Task CopyAcrImagesCommand_RuntimeDepsSharing()
        {
            const string subscriptionId = "my subscription";

            using TempFolderContext tempFolderContext = TestHelper.UseTempFolder();
            Mock <IRegistriesOperations> registriesOperationsMock = AzureHelper.CreateRegistriesOperationsMock();
            IAzure azure = AzureHelper.CreateAzureMock(registriesOperationsMock);
            Mock <IAzureManagementFactory> azureManagementFactoryMock =
                AzureHelper.CreateAzureManagementFactoryMock(subscriptionId, azure);

            Mock <IEnvironmentService> environmentServiceMock = new Mock <IEnvironmentService>();

            CopyAcrImagesCommand command = new CopyAcrImagesCommand(azureManagementFactoryMock.Object, Mock.Of <ILoggerService>());

            command.Options.Manifest         = Path.Combine(tempFolderContext.Path, "manifest.json");
            command.Options.Subscription     = subscriptionId;
            command.Options.ResourceGroup    = "my resource group";
            command.Options.SourceRepoPrefix = command.Options.RepoPrefix = "test/";
            command.Options.ImageInfoPath    = "image-info.json";

            string dockerfileRelativePath = DockerfileHelper.CreateDockerfile("3.1/runtime-deps/os", tempFolderContext);

            Manifest manifest = CreateManifest(
                CreateRepo("runtime-deps",
                           CreateImage(
                               new Platform[]
            {
                CreatePlatform(dockerfileRelativePath, new string[] { "3.1" }, osVersion: "focal")
            },
                               productVersion: "3.1"),
                           CreateImage(
                               new Platform[]
            {
                CreatePlatform(dockerfileRelativePath, new string[] { "5.0" }, osVersion: "focal")
            },
                               productVersion: "5.0"))
                );

            manifest.Registry = "mcr.microsoft.com";

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

            RepoData runtimeRepo;

            ImageArtifactDetails imageArtifactDetails = new ImageArtifactDetails
            {
                Repos =
                {
                    {
                        runtimeRepo = new RepoData
                        {
                            Repo   = "runtime-deps",
                            Images =
                            {
                                new ImageData
                                {
                                    Platforms =
                                    {
                                        CreatePlatform(
                                            PathHelper.NormalizePath(dockerfileRelativePath),
                                            simpleTags: new List <string>
                                        {
                                            "3.1"
                                        },
                                            osVersion: "focal")
                                    },
                                    ProductVersion = "3.1"
                                },
                                new ImageData
                                {
                                    Platforms =
                                    {
                                        CreatePlatform(
                                            PathHelper.NormalizePath(dockerfileRelativePath),
                                            simpleTags: new List <string>
                                        {
                                            "5.0"
                                        },
                                            osVersion: "focal")
                                    },
                                    ProductVersion = "5.0"
                                }
                            }
                        }
                    }
                }
            };

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

            command.LoadManifest();
            await command.ExecuteAsync();

            List <string> expectedTags = new List <string>
            {
                $"{command.Options.RepoPrefix}{runtimeRepo.Repo}:3.1",
                $"{command.Options.RepoPrefix}{runtimeRepo.Repo}:5.0"
            };

            foreach (string expectedTag in expectedTags)
            {
                registriesOperationsMock
                .Verify(o => o.ImportImageWithHttpMessagesAsync(
                            command.Options.ResourceGroup,
                            manifest.Registry,
                            It.Is <ImportImageParametersInner>(parameters =>
                                                               VerifyImportImageParameters(parameters, new List <string> {
                    expectedTag
                })),
                            It.IsAny <Dictionary <string, List <string> > >(),
                            It.IsAny <CancellationToken>()));
            }
        }
示例#2
0
        public async Task SyndicatedTags()
        {
            const string subscriptionId = "my subscription";

            using TempFolderContext tempFolderContext = TestHelper.UseTempFolder();
            Mock <IRegistriesOperations> registriesOperationsMock = AzureHelper.CreateRegistriesOperationsMock();
            IAzure azure = AzureHelper.CreateAzureMock(registriesOperationsMock);
            Mock <IAzureManagementFactory> azureManagementFactoryMock =
                AzureHelper.CreateAzureManagementFactoryMock(subscriptionId, azure);

            Mock <IEnvironmentService> environmentServiceMock = new Mock <IEnvironmentService>();

            CopyAcrImagesCommand command = new CopyAcrImagesCommand(azureManagementFactoryMock.Object, Mock.Of <ILoggerService>());

            command.Options.Manifest         = Path.Combine(tempFolderContext.Path, "manifest.json");
            command.Options.Subscription     = subscriptionId;
            command.Options.ResourceGroup    = "my resource group";
            command.Options.SourceRepoPrefix = command.Options.RepoPrefix = "test/";
            command.Options.ImageInfoPath    = "image-info.json";

            const string runtimeRelativeDir = "1.0/runtime/os";

            Directory.CreateDirectory(Path.Combine(tempFolderContext.Path, runtimeRelativeDir));
            string dockerfileRelativePath = Path.Combine(runtimeRelativeDir, "Dockerfile");

            File.WriteAllText(Path.Combine(tempFolderContext.Path, dockerfileRelativePath), "FROM repo:tag");

            Manifest manifest = ManifestHelper.CreateManifest(
                ManifestHelper.CreateRepo("runtime",
                                          ManifestHelper.CreateImage(
                                              ManifestHelper.CreatePlatform(dockerfileRelativePath, new string[] { "tag1", "tag2", "tag3" })))
                );

            manifest.Registry = "mcr.microsoft.com";

            const string syndicatedRepo2 = "runtime2";
            const string syndicatedRepo3 = "runtime3";

            Platform platform = manifest.Repos.First().Images.First().Platforms.First();

            platform.Tags["tag2"].Syndication = new TagSyndication
            {
                Repo = syndicatedRepo2,
            };
            platform.Tags["tag3"].Syndication = new TagSyndication
            {
                Repo            = syndicatedRepo3,
                DestinationTags = new string[]
                {
                    "tag3a",
                    "tag3b"
                }
            };

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

            RepoData runtimeRepo;

            ImageArtifactDetails imageArtifactDetails = new ImageArtifactDetails
            {
                Repos =
                {
                    {
                        runtimeRepo = new RepoData
                        {
                            Repo   = "runtime",
                            Images =
                            {
                                new ImageData
                                {
                                    Platforms =
                                    {
                                        CreatePlatform(
                                            PathHelper.NormalizePath(dockerfileRelativePath),
                                            simpleTags: new List <string>
                                        {
                                            "tag1",
                                            "tag2",
                                            "tag3"
                                        })
                                    }
                                }
                            }
                        }
                    }
                }
            };

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

            command.LoadManifest();
            await command.ExecuteAsync();

            List <string> expectedTags = new List <string>
            {
                $"{command.Options.RepoPrefix}{runtimeRepo.Repo}:tag1",
                $"{command.Options.RepoPrefix}{runtimeRepo.Repo}:tag2",
                $"{command.Options.RepoPrefix}{runtimeRepo.Repo}:tag3",
                $"{command.Options.RepoPrefix}{syndicatedRepo2}:tag2",
                $"{command.Options.RepoPrefix}{syndicatedRepo3}:tag3a",
                $"{command.Options.RepoPrefix}{syndicatedRepo3}:tag3b"
            };

            foreach (string expectedTag in expectedTags)
            {
                registriesOperationsMock
                .Verify(o => o.ImportImageWithHttpMessagesAsync(
                            command.Options.ResourceGroup,
                            manifest.Registry,
                            It.Is <ImportImageParametersInner>(parameters =>
                                                               VerifyImportImageParameters(parameters, new List <string> {
                    expectedTag
                })),
                            It.IsAny <Dictionary <string, List <string> > >(),
                            It.IsAny <CancellationToken>()));
            }
        }
示例#3
0
        public async Task CopyAcrImagesCommand_CustomDockerfileName()
        {
            const string subscriptionId = "my subscription";

            using (TempFolderContext tempFolderContext = TestHelper.UseTempFolder())
            {
                Mock <IRegistriesOperations> registriesOperationsMock = CreateRegistriesOperationsMock();
                IAzure azure = CreateAzureMock(registriesOperationsMock);
                Mock <IAzureManagementFactory> azureManagementFactoryMock = CreateAzureManagementFactoryMock(subscriptionId, azure);

                Mock <IEnvironmentService> environmentServiceMock = new Mock <IEnvironmentService>();

                CopyAcrImagesCommand command = new CopyAcrImagesCommand(
                    azureManagementFactoryMock.Object, environmentServiceMock.Object);
                command.Options.Manifest         = Path.Combine(tempFolderContext.Path, "manifest.json");
                command.Options.Subscription     = subscriptionId;
                command.Options.ResourceGroup    = "my resource group";
                command.Options.SourceRepoPrefix = command.Options.RepoPrefix = "test/";
                command.Options.ImageInfoPath    = "image-info.json";

                const string runtimeRelativeDir = "1.0/runtime/os";
                Directory.CreateDirectory(Path.Combine(tempFolderContext.Path, runtimeRelativeDir));
                string dockerfileRelativePath = Path.Combine(runtimeRelativeDir, "Dockerfile.custom");
                File.WriteAllText(Path.Combine(tempFolderContext.Path, dockerfileRelativePath), "FROM repo:tag");

                Manifest manifest = ManifestHelper.CreateManifest(
                    ManifestHelper.CreateRepo("runtime",
                                              ManifestHelper.CreateImage(
                                                  ManifestHelper.CreatePlatform(dockerfileRelativePath, new string[] { "runtime" })))
                    );
                manifest.Registry = "mcr.microsoft.com";

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

                RepoData runtimeRepo;

                RepoData[] repos = new RepoData[]
                {
                    runtimeRepo = new RepoData
                    {
                        Repo   = "runtime",
                        Images = new SortedDictionary <string, ImageData>
                        {
                            {
                                PathHelper.NormalizePath(dockerfileRelativePath),
                                new ImageData
                                {
                                    SimpleTags =
                                    {
                                        "tag1",
                                        "tag2"
                                    }
                                }
                            }
                        }
                    }
                };

                File.WriteAllText(command.Options.ImageInfoPath, JsonConvert.SerializeObject(repos));

                command.LoadManifest();
                await command.ExecuteAsync();

                IList <string> expectedTags = runtimeRepo.Images.First().Value.SimpleTags
                                              .Select(tag => $"{command.Options.RepoPrefix}{runtimeRepo.Repo}:{tag}")
                                              .ToList();

                foreach (string expectedTag in expectedTags)
                {
                    registriesOperationsMock
                    .Verify(o => o.ImportImageWithHttpMessagesAsync(
                                command.Options.ResourceGroup,
                                manifest.Registry,
                                It.Is <ImportImageParametersInner>(parameters =>
                                                                   VerifyImportImageParameters(parameters, new List <string> {
                        expectedTag
                    })),
                                It.IsAny <Dictionary <string, List <string> > >(),
                                It.IsAny <CancellationToken>()));
                }

                environmentServiceMock.Verify(o => o.Exit(It.IsAny <int>()), Times.Never);
            }
        }