public async Task MultipleBaseTags() { 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>(); CopyDockerHubBaseImagesCommand command = new CopyDockerHubBaseImagesCommand( 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.RepoPrefix = "custom-repo/"; 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"); const string registry = "mcr.microsoft.com"; Manifest manifest = CreateManifest( CreateRepo("runtime", CreateImage( CreatePlatform( CreateDockerfile("1.0/runtime/os/arm32v7", tempFolderContext, "arm32v7/base:tag"), new string[] { "arm32v7" }), CreatePlatform( CreateDockerfile("1.0/runtime/os/amd64", tempFolderContext, "amd64/base:tag"), new string[] { "amd64" }))), CreateRepo("aspnet", CreateImage( CreatePlatformWithRepoBuildArg( CreateDockerfile("1.0/aspnet/os/arm32v7", tempFolderContext, "$REPO:arm32v7"), $"{registry}/{command.Options.RepoPrefix}aspnet", new string[] { "arm32v7" }), CreatePlatformWithRepoBuildArg( CreateDockerfile("1.0/aspnet/os/amd64", tempFolderContext, "$REPO:amd64"), $"{registry}/{command.Options.RepoPrefix}aspnet", new string[] { "amd64" }))) ); manifest.Registry = registry; File.WriteAllText(Path.Combine(tempFolderContext.Path, command.Options.Manifest), JsonConvert.SerializeObject(manifest)); command.LoadManifest(); await command.ExecuteAsync(); var expectedTagInfos = new (string SourceImage, string TargetTag)[]
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>())); } }
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>())); } }