示例#1
0
        private static int BranchDeployment(BranchDeploymentOptions opts)
        {
            var logMessager = new OctopusLogMessages(opts.OctopusUrl);
            var notifier    = GetNotifier(opts.HideDeploymentProgress, opts.Teamcity, logMessager);

            var deploymentPlanner = new OctopusDeploymentPlanner(opts.OctopusUrl, opts.OctopusApiKey);
            var componentFilter   = GetComponentFilter(opts.ComponentFilterPath, opts.ComponentFilter);

            notifier.PrintActionMessage(string.Format("Retrieve branch deployment plans for TargetEnvironment=\"{0}\" Branch=\"{1}\"", opts.TargetEnvironment, opts.Branch));
            var redeployDeploymentPlans   = deploymentPlanner.GetBranchDeploymentPlans(opts.TargetEnvironment, opts.Branch, opts.DoNotUseDifferentialDeployment, componentFilter);
            var environmentDeploymentPlan = redeployDeploymentPlans.EnvironmentDeploymentPlan;

            var deploymentScheduler   = new DeploymentScheduler();
            var componentGraph        = deploymentScheduler.GetComponentDeploymentGraph(environmentDeploymentPlan);
            var environmentDeployment = deploymentScheduler.GetEnvironmentDeployment(componentGraph);

            SetUpdateVariablesOnDeploymentPlan(environmentDeployment);

            notifier.PrintEnvironmentDeploy(environmentDeployment);
            SaveEnvironmentDeploy(opts.EnvironmentDeploymentPath, environmentDeployment);

            var deployers = GetDeployers(opts.TargetEnvironment, opts.UpdateVariables, opts.Deploy, opts.OctopusUrl, opts.OctopusApiKey);

            return(Deploy(notifier, logMessager, environmentDeployment, opts.MaximumParallelDeployments, deployers));
        }
        public void GetDeploymentPlanForComponentAdjacencyGraph()
        {
            var componentDeploymentGraph = new ComponentDeploymentGraph();

            //Add vertices

            var a = new ComponentDeploymentVertex("a", "a", new SemVer("1.0.0"), PlanAction.Skip, null);
            var b = new ComponentDeploymentVertex("b", "b", new SemVer("1.0.0"), PlanAction.Change, null);
            var c = new ComponentDeploymentVertex("c", "c", new SemVer("1.0.0"), PlanAction.Skip, null);
            var d = new ComponentDeploymentVertex("d", "d", new SemVer("1.0.0"), PlanAction.Change, null);
            var e = new ComponentDeploymentVertex("e", "e", new SemVer("1.0.0"), PlanAction.Skip, null);
            var f = new ComponentDeploymentVertex("f", "f", new SemVer("1.0.0"), PlanAction.Change, null);
            var g = new ComponentDeploymentVertex("g", "g", new SemVer("1.0.0"), PlanAction.Remove, null);
            var h = new ComponentDeploymentVertex("h", "h", new SemVer("1.0.0"), PlanAction.Change, null);

            var x = new ComponentDeploymentVertex("x", "x", new SemVer("1.0.0"), PlanAction.Skip, null);
            var y = new ComponentDeploymentVertex("y", "y", new SemVer("1.0.0"), PlanAction.Change, null);
            var z = new ComponentDeploymentVertex("z", "z", new SemVer("1.0.0"), PlanAction.Skip, null);

            componentDeploymentGraph.AddVertexRange(new ComponentDeploymentVertex[]
            {
                a, b, c, d, e, f, g, h, x, y, z
            });

            //Create edges

            var b_a = new ComponentDeploymentEdge(b, a);
            var b_c = new ComponentDeploymentEdge(b, c);
            var c_b = new ComponentDeploymentEdge(c, b);
            var d_a = new ComponentDeploymentEdge(d, a);
            var e_d = new ComponentDeploymentEdge(e, d);
            var f_e = new ComponentDeploymentEdge(f, e);
            var g_d = new ComponentDeploymentEdge(g, d);
            var h_e = new ComponentDeploymentEdge(h, e);
            var h_d = new ComponentDeploymentEdge(h, d);

            var y_x = new ComponentDeploymentEdge(y, x);
            var z_y = new ComponentDeploymentEdge(z, y);

            componentDeploymentGraph.AddEdgeRange(new ComponentDeploymentEdge[]
            {
                b_a, b_c, c_b, d_a, e_d, f_e, g_d, h_e, h_d, y_x, z_y
            });

            var deploymentScheduler   = new DeploymentScheduler();
            var environmentDeployment = deploymentScheduler.GetEnvironmentDeployment(componentDeploymentGraph);

            var products0 = environmentDeployment.ProductDeployments[0];
            var products1 = environmentDeployment.ProductDeployments[1];

            products0.DeploymentSteps.Count().Should().Be(ExpectedNumberOfDeploymentStepsForProductDeployment0);
            products0.DeploymentSteps.SelectMany(productDeploymentStep => productDeploymentStep.ComponentDeployments).Count().Should().Be(ExpectedNumberOfComponentDeploymentsForProductDeployment0);

            products1.DeploymentSteps.Count().Should().Be(ExpectedNumberOfDeploymentStepsForProductDeployment1);
            products1.DeploymentSteps.SelectMany(productDeploymentStep => productDeploymentStep.ComponentDeployments).Count().Should().Be(ExpectedNumberOfComponentDeploymentsForProductDeployment1);
        }
        public void GetDeploymentPlanForComponentDeploymentList()
        {
            var componentDependancies = GetEnvironmentDeploymentPlan();

            var deploymentScheduler   = new DeploymentScheduler();
            var componentGraph        = deploymentScheduler.GetComponentDeploymentGraph(componentDependancies);
            var environmentDeployment = deploymentScheduler.GetEnvironmentDeployment(componentGraph);

            var products0 = environmentDeployment.ProductDeployments[0];
            var products1 = environmentDeployment.ProductDeployments[1];

            products0.DeploymentSteps.Count().Should().Be(ExpectedNumberOfDeploymentStepsForProductDeployment0);
            products0.DeploymentSteps.SelectMany(productDeploymentStep => productDeploymentStep.ComponentDeployments).Count().Should().Be(ExpectedNumberOfComponentDeploymentsForProductDeployment0);

            products1.DeploymentSteps.Count().Should().Be(ExpectedNumberOfDeploymentStepsForProductDeployment1);
            products1.DeploymentSteps.SelectMany(productDeploymentStep => productDeploymentStep.ComponentDeployments).Count().Should().Be(ExpectedNumberOfComponentDeploymentsForProductDeployment1);
        }
        public void GetEnvironmentMirrorDeploymentPlans()
        {
            var octopusUrl        = ConfigurationManager.AppSettings["OctopusUrl"];
            var octopusApiKey     = ConfigurationManager.AppSettings["OctopusApiKey"];
            var deploymentPlanner = new OctopusDeploymentPlanner(octopusUrl, octopusApiKey);

            var environmentFrom = ConfigurationManager.AppSettings["EnvironmentFrom"];
            var environmentTo   = ConfigurationManager.AppSettings["EnvironmentTo"];

            var dashboard = deploymentPlanner.GetEnvironmentMirrorDeploymentPlans(environmentFrom, environmentTo, false);

            var deploymentScheduler = new DeploymentScheduler();
            var products            = deploymentScheduler.GetComponentDeploymentGraph(dashboard.EnvironmentDeploymentPlan);

            var difference = JsonConvert.SerializeObject(dashboard.EnvironmentDeploymentPlan.DeploymentPlans.Where(x => x.Action != PlanAction.Skip));

            dashboard.EnvironmentDeploymentPlan.DeploymentPlans.Count.Should().BeGreaterThan(0);
        }
        public void BranchDeployment()
        {
            if (!CanBranchDeployment)
            {
                return;
            }

            IsLoadingData = true;
            Task.Factory.StartNew(() =>
            {
                try
                {
                    var deploymentPlanner = new OctopusDeploymentPlanner(_octopusUrl, _octopusApiKey);
                    var componentFilter   = new ComponentFilter
                    {
                        Expressions = ComponentFilterExpressions.Select(x => x.Text).ToList(),
                        Include     = ComponentFilterInclude
                    };

                    var branchDeploymentPlans = deploymentPlanner.GetBranchDeploymentPlans(_selectedBranchDeploymentEnvironment.Name, _selectedBranchDeploymentBranch.Name, _doNotUseDifferentialDeploymentForBranchDeployment, componentFilter);
                    EnvironmentDeploymentPlan = branchDeploymentPlans.EnvironmentDeploymentPlan;

                    var deploymentScheduler = new DeploymentScheduler();

                    var componentGraph = deploymentScheduler.GetComponentDeploymentGraph(EnvironmentDeploymentPlan);
                    Graph = componentGraph.ToBidirectionalGraph();
                    EnvironmentDeployment             = deploymentScheduler.GetEnvironmentDeployment(componentGraph);
                    EnvironmentDeploymentSaveFileName = "branch " + _selectedBranchDeploymentBranch.Name + " to " + _selectedBranchDeploymentEnvironment.Name + ".json";
                    EnvironmentToDeployTo             = _selectedBranchDeploymentEnvironment;
                }
                catch
                {
                    EnvironmentDeploymentPlan = new EnvironmentDeploymentPlan(new List <ComponentDeploymentPlan>());
                    Graph = null;
                    EnvironmentDeployment             = new EnvironmentDeployment(new List <ProductDeployment>());
                    EnvironmentDeploymentSaveFileName = string.Empty;
                    EnvironmentToDeployTo             = null;
                }
            }).ContinueWith(task =>
            {
                IsLoadingData = false;
            });
        }