public async Task <ActionResult> GetLaunchManifestAsync(DeploymentParameters parameters) { OperationContext context = new OperationContext(new Context(parameters.ContextId, _logger)); if (!await _service.IsAuthorizedAsync(context, parameters)) { return(Unauthorized()); } var result = await _service.UploadFilesAndGetManifestAsync(context, parameters, waitForCompletion : false); return(new JsonResult(result, DeploymentUtilities.ConfigurationSerializationOptions)); }
public async Task TestFullDeployment() { var sources = new Dictionary <string, string>() { { @"Stamp3\info.txt", "" }, { @"Env\RootFile.json", "{ 'key1': 1, 'key2': 2 }" }, { @"Env\Subfolder\Hello.txt", "Hello world" }, { @"Env\Foo.txt", "Baz" }, { @"Files\Foo.txt", "Bar" }, }; Dictionary <string, string> getSourceDrop(string root, string prefix) { return(sources.Where(e => e.Key.StartsWith(root)) .ToDictionary(e => e.Key.Substring(prefix.Length), e => e.Value)); } var drops = new Dictionary <string, Dictionary <string, string> >() { { "https://dev.azure.com/buildxlcachetest/drop/drops/dev/testdrop1?root=release/win-x64", new Dictionary <string, string> { { @"file1.bin", "File content 1" }, { @"file2.txt", "File content 2" }, { @"sub\file3.dll", "File content 3" } } }, { "https://dev.azure.com/buildxlcachetest/drop/drops/dev/testdrop2?root=debug", new Dictionary <string, string> { { @"file1.bin", "File content 1" }, { @"file2.txt", "File content 2 changed" }, { @"sub\file5.dll", "File content 5" } } }, { DeploymentUtilities.ConfigDropUri.OriginalString, new Dictionary <string, string>() { { DeploymentUtilities.DeploymentConfigurationFileName, ConfigString } } }, { "file://Env", getSourceDrop(@"Env\", @"Env\") }, { "file://Files/Foo.txt", getSourceDrop(@"Files\Foo.txt", @"Files\") }, { "file://Env/Foo.txt", getSourceDrop(@"Env\Foo.txt", @"Env\") }, { "file://Stamp3", getSourceDrop(@"Stamp3\", @"Stamp3\") } }; var deploymentRoot = TestRootDirectoryPath / "deploy"; var ingester = new DeploymentIngester( Context, sourceRoot: base.TestRootDirectoryPath / "src", deploymentRoot: deploymentRoot, deploymentConfigurationPath: base.TestRootDirectoryPath / "DeploymentConfiguration.json", FileSystem, dropExeFilePath: base.TestRootDirectoryPath / @"dropbin\drop.exe", retentionSizeGb: 1, dropToken: DropToken); // Write source files WriteFiles(ingester.SourceRoot, sources); FileSystem.WriteAllText(ingester.DeploymentConfigurationPath, ConfigString); ingester.OverrideLaunchDropProcess = t => { var dropContents = drops[t.dropUrl]; WriteFiles(new AbsolutePath(t.targetDirectory) / (t.relativeRoot ?? ""), dropContents); return(BoolResult.Success); }; await ingester.RunAsync().ShouldBeSuccess(); var manifestText = FileSystem.ReadAllText(ingester.DeploymentManifestPath); var deploymentManifest = JsonSerializer.Deserialize <DeploymentManifest>(manifestText); foreach (var drop in drops) { var uri = new Uri(drop.Key); var expectedDropContents = drops[drop.Key]; var layoutSpec = deploymentManifest.Drops[drop.Key]; layoutSpec.Count.Should().Be(expectedDropContents.Count); foreach (var fileAndContent in expectedDropContents) { var hash = new ContentHash(layoutSpec[fileAndContent.Key].Hash); var expectedPath = ingester.DeploymentRoot / DeploymentUtilities.GetContentRelativePath(hash); var text = FileSystem.ReadAllText(expectedPath); text.Should().Be(fileAndContent.Value); } } var clock = new MemoryClock(); var deploymentService = new DeploymentService(new DeploymentServiceConfiguration(), deploymentRoot, _ => new TestSecretsProvider(), clock); BoxRef <Task> uploadFileCompletion = Task.CompletedTask; deploymentService.OverrideCreateCentralStorage = t => new DeploymentTestCentralStorage(t.storageSecretName) { UploadFileCompletion = uploadFileCompletion }; await verifyLaunchManifestAsync(new DeploymentParameters() { Stamp = "ST_S3", Ring = "Ring_1" }, new HashSet <(string targetPath, string drop)>() { ("bin", "https://dev.azure.com/buildxlcachetest/drop/drops/dev/testdrop2?root=debug"), ("", "file://Env"), ("info", "file://Stamp3"), }); async Task <LauncherManifest> verifyLaunchManifestAsync(DeploymentParameters parameters, HashSet <(string targetPath, string drop)> expectedDrops) { var launchManifest = await deploymentService.UploadFilesAndGetManifestAsync(Context, parameters, waitForCompletion : true); var expectedDeploymentPathToHashMap = new Dictionary <string, string>(); launchManifest.Drops.Count.Should().Be(expectedDrops.Count); foreach (var drop in launchManifest.Drops) { var targetRelativePath = drop.TargetRelativePath ?? string.Empty; expectedDrops.Should().Contain((targetRelativePath, drop.Url)); var dropSpec = deploymentManifest.Drops[drop.Url]; foreach (var dropFile in drops[drop.Url]) { expectedDeploymentPathToHashMap[Path.Combine(targetRelativePath, dropFile.Key)] = dropSpec[dropFile.Key].Hash; } } launchManifest.Deployment.Count.Should().Be(expectedDeploymentPathToHashMap.Count); foreach (var file in launchManifest.Deployment) { var expectedHash = expectedDeploymentPathToHashMap[file.Key]; file.Value.Hash.Should().Be(expectedHash); } return(launchManifest); } }
public Task <LauncherManifest> Get(DeploymentParameters parameters) { OperationContext context = new OperationContext(new Context(_logger)); return(_service.UploadFilesAndGetManifestAsync(context, parameters, waitForCompletion: false)); }