示例#1
0
        internal void Deploy(
            [Required, Description("Location where loose source files should be drawn from.")] string sourceRoot,
            [Required, Description("Target directory for deployment.")] string targetDirectory,
            [Required, Description("Location of deployment manifest json file")] string deploymentConfigPath,
            [Required, Description("Location of drop.exe to run to download drops")] string dropExePath,
            [Required, Description("Personal access token to use to authenticate to drop service")] string dropToken,
            [Description("Maximum size of files to retain"), DefaultValue(50)] int retentionSizeGb)
        {
            try
            {
                Initialize();
                var deploymentRoot = new AbsolutePath(targetDirectory);

                var deploymentRunner = new DeploymentRunner(
                    context: new OperationContext(new Context(_logger)),
                    sourceRoot: new AbsolutePath(sourceRoot),
                    deploymentRoot: deploymentRoot,
                    deploymentConfigurationPath: new AbsolutePath(deploymentConfigPath),
                    fileSystem: _fileSystem,
                    retentionSizeGb: retentionSizeGb,
                    dropExeFilePath: new AbsolutePath(dropExePath),
                    dropToken: dropToken
                    );

                deploymentRunner.RunAsync().GetAwaiter().GetResult().ThrowIfFailure();
            }
            catch (Exception e)
            {
                _logger.Error(e.ToString());
                throw;
            }
        }
示例#2
0
 public abstract DeploymentModule <TRunner> Deploy(DeploymentRunner <TRunner> runner);
示例#3
0
 public override DeploymentModule <TRunner> Deploy(DeploymentRunner <TRunner> runner)
 {
     throw new System.NotImplementedException();
 }
示例#4
0
 public App(PackageManager packman, DeploymentRunner runner, ILogger <App> logger)
 {
     this._packman = packman;
     this._runner  = runner;
     this._logger  = logger;
 }
        public async Task TestFullDeployment()
        {
            var sources = new Dictionary <string, string>()
            {
                { @"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 expectedSourceDrops = new Dictionary <string, Dictionary <string, string> >()
            {
                {
                    "file://Env", getSourceDrop(@"Env\", @"Env\")
                },
                {
                    "file://Files/Foo.txt", getSourceDrop(@"Files\Foo.txt", @"Files\")
                },
                {
                    "file://Env/Foo.txt", getSourceDrop(@"Env\Foo.txt", @"Env\")
                }
            };

            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" }
                    }
                }
            };

            var config = new TestDeploymentConfig()
            {
                Drops =
                {
                    new TestDeploymentConfig.DropDeploymentConfiguration()
                    {
                        { "Url [Ring:Ring_0]",        "https://dev.azure.com/buildxlcachetest/drop/drops/dev/testdrop1?root=release/win-x64" },
                        { "Url [Ring:Ring_1]",        "https://dev.azure.com/buildxlcachetest/drop/drops/dev/testdrop2?root=debug"           },
                    },
                    new TestDeploymentConfig.DropDeploymentConfiguration()
                    {
                        { "Url",                      "file://Env"                                                                           },
                    },
                    new TestDeploymentConfig.DropDeploymentConfiguration()
                    {
                        { "Url [Stamp:DefaultStamp]", "file://Files/Foo.txt"                                                                 },
                    },
                    new TestDeploymentConfig.DropDeploymentConfiguration()
                    {
                        { "Url [Stamp:DefaultStamp]", "file://Env/Foo.txt"                                                                   },
                    }
                }
            };

            var deploymentRunner = new DeploymentRunner(
                Context,
                sourceRoot: TestRootDirectoryPath / "src",
                deploymentRoot: TestRootDirectoryPath / "deploy",
                deploymentConfigurationPath: TestRootDirectoryPath / "DeploymentConfiguration.json",
                FileSystem,
                dropExeFilePath: TestRootDirectoryPath / @"dropbin\drop.exe",
                retentionSizeGb: 1,
                dropToken: DropToken);

            // Write source files
            WriteFiles(deploymentRunner.SourceRoot, sources);

            var configText = JsonSerializer.Serialize(config, new JsonSerializerOptions()
            {
                WriteIndented = true
            });

            FileSystem.WriteAllText(deploymentRunner.DeploymentConfigurationPath, configText);

            deploymentRunner.OverrideLaunchDropProcess = t =>
            {
                var dropContents = drops[t.dropUrl];
                WriteFiles(new AbsolutePath(t.targetDirectory) / (t.relativeRoot ?? ""), dropContents);
                return(BoolResult.Success);
            };

            await deploymentRunner.RunAsync().ShouldBeSuccess();

            var manifestText       = FileSystem.ReadAllText(deploymentRunner.DeploymentManifestPath);
            var deploymentManifest = JsonSerializer.Deserialize <DeploymentManifest>(manifestText);

            foreach (var drop in deploymentManifest.Drops)
            {
                var uri = new Uri(drop.Key);

                var expectedDropContents = uri.IsFile ? expectedSourceDrops[drop.Key] : 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 = deploymentRunner.DeploymentRoot / DeploymentUtilities.GetContentRelativePath(hash);

                    var text = FileSystem.ReadAllText(expectedPath);
                    text.Should().Be(fileAndContent.Value);
                }
            }
        }
示例#6
0
 public DeployController(DeploymentRunner deploymentRunner, IQuasarConfiguration quasarConfiguration, PackageManager packageManager)
 {
     this._packageManager   = packageManager;
     this._deploymentRunner = deploymentRunner;
     this._config           = quasarConfiguration;
 }