Example #1
0
		public static void Main(string[] args)
		{
			DeployerInfrastructureDependencyRegistrar.RegisterInfrastructure();

			if (args.Length != 4)
			{
				OutputUsageAndClose("Supply the correct number of command line arguments");
			}

			var requestedAction = args[0];
			var requestedApplicationName = args[1];
			var requestedEnvironment = args[2];
			var requestedVersion = args[3];

			var applicationRepository = ObjectFactory.GetInstance<IApplicationRepository>();

			var selectedApplication = applicationRepository.GetByName(requestedApplicationName);

			if (selectedApplication == null)
			{
				OutputUsageAndClose("Specify an application name included in the configuration file 'Tarantino.Deployer.Console.exe.config'");
			}

			if (selectedApplication != null)
			{
				var selectedEnvironment = selectedApplication.GetEnvironmentByName(requestedEnvironment);

				if (selectedEnvironment == null)
				{
					OutputUsageAndClose(
						string.Format(
							"Specify an environment included in the configuration file 'Tarantino.Deployer.Console.exe.config' for application '{0}'",
							selectedApplication.Name));
				}

				if (selectedEnvironment != null)
				{
					if (requestedAction == "Deploy")
					{
						string versionNumber = requestedVersion;

						if (requestedVersion == "CurrentCertified")
						{
							var repository = ObjectFactory.GetInstance<IDeploymentRepository>();
							var certifiedDeployments = repository.FindCertified(selectedApplication.Name, selectedEnvironment.Predecessor);
							if (certifiedDeployments.Count() > 0)
							{
								var lastCertified = certifiedDeployments.OrderByDescending(d => d.CertifiedOn).ElementAt(0);
								versionNumber = lastCertified.Version;
							}
						}
						else if (requestedVersion == "Current")
						{
							versionNumber = null;
						}

						var result = PackageDownloader.DownloadAndExtract(selectedApplication.Name, selectedEnvironment.Name, versionNumber,
						                                                              selectedApplication.Url, selectedApplication.ZipFile,
						                                                              selectedApplication.Username, selectedApplication.Password);

						var caller = new SimpleProcessCaller(result.Executable, string.Empty, result.WorkingDirectory)
						{
							StdOutReceived = Caller_OnStdOutReceived,
							StdErrorReceived = Caller_OnStdErrorReceived
						};

						caller.ExecuteProcess();
						var exitCode = caller.ExitCode;

						var recorder = ObjectFactory.GetInstance<IDeploymentRecorder>();
						var version = recorder.RecordDeployment(selectedApplication.Name, selectedEnvironment.Name, _buildOutput.ToString(), result.Version, _buildFailed);

						if (exitCode == 0)
						{
							using (var writer = new StreamWriter("TarantinoDeploymentVersionNumber.txt"))
							{
								writer.Write(version);
							}
						}
						else
						{
							Environment.Exit(1);
						}
					}
					else if (requestedAction == "Certify")
					{
						var repository = ObjectFactory.GetInstance<IDeploymentRepository>();
						var uncertifiedDeployments = repository.FindSuccessfulUncertified(selectedApplication.Name, selectedEnvironment.Name);

						var deployments = uncertifiedDeployments.Where(d => d.Version == requestedVersion).OrderByDescending(d => d.DeployedOn);

						if (deployments.Count() > 0)
						{
							var deployment = deployments.ElementAt(0);
							var certifier = ObjectFactory.GetInstance<IVersionCertifier>();
							certifier.Certify(deployment);
						}
						else
						{
							OutputUsageAndClose("When certifying a deployment, you must specify a valid deployment that has not already been certified");
						}
					}
					else
					{
						OutputUsageAndClose("Specify either 'Deploy' or 'Certify' for the <Action> argument");
					}
				}
			}
		}
Example #2
0
        public static void Main(string[] args)
        {
            DeployerInfrastructureDependencyRegistrar.RegisterInfrastructure();

            if (args.Length != 4)
            {
                OutputUsageAndClose("Supply the correct number of command line arguments");
            }

            var requestedAction          = args[0];
            var requestedApplicationName = args[1];
            var requestedEnvironment     = args[2];
            var requestedVersion         = args[3];

            var applicationRepository = ObjectFactory.GetInstance <IApplicationRepository>();

            var selectedApplication = applicationRepository.GetByName(requestedApplicationName);

            if (selectedApplication == null)
            {
                OutputUsageAndClose("Specify an application name included in the configuration file 'Tarantino.Deployer.Console.exe.config'");
            }

            if (selectedApplication != null)
            {
                var selectedEnvironment = selectedApplication.GetEnvironmentByName(requestedEnvironment);

                if (selectedEnvironment == null)
                {
                    OutputUsageAndClose(
                        string.Format(
                            "Specify an environment included in the configuration file 'Tarantino.Deployer.Console.exe.config' for application '{0}'",
                            selectedApplication.Name));
                }

                if (selectedEnvironment != null)
                {
                    if (requestedAction == "Deploy")
                    {
                        string versionNumber = requestedVersion;

                        if (requestedVersion == "CurrentCertified")
                        {
                            var repository           = ObjectFactory.GetInstance <IDeploymentRepository>();
                            var certifiedDeployments = repository.FindCertified(selectedApplication.Name, selectedEnvironment.Predecessor);
                            if (certifiedDeployments.Count() > 0)
                            {
                                var lastCertified = certifiedDeployments.OrderByDescending(d => d.CertifiedOn).ElementAt(0);
                                versionNumber = lastCertified.Version;
                            }
                        }
                        else if (requestedVersion == "Current")
                        {
                            versionNumber = null;
                        }

                        var result = PackageDownloader.DownloadAndExtract(selectedApplication.Name, selectedEnvironment.Name, versionNumber,
                                                                          selectedApplication.Url, selectedApplication.ZipFile,
                                                                          selectedApplication.Username, selectedApplication.Password);

                        var caller = new SimpleProcessCaller(result.Executable, string.Empty, result.WorkingDirectory)
                        {
                            StdOutReceived   = Caller_OnStdOutReceived,
                            StdErrorReceived = Caller_OnStdErrorReceived
                        };

                        caller.ExecuteProcess();
                        var exitCode = caller.ExitCode;

                        var recorder = ObjectFactory.GetInstance <IDeploymentRecorder>();
                        var version  = recorder.RecordDeployment(selectedApplication.Name, selectedEnvironment.Name, _buildOutput.ToString(), result.Version, _buildFailed);

                        if (exitCode == 0)
                        {
                            using (var writer = new StreamWriter("TarantinoDeploymentVersionNumber.txt"))
                            {
                                writer.Write(version);
                            }
                        }
                        else
                        {
                            Environment.Exit(1);
                        }
                    }
                    else if (requestedAction == "Certify")
                    {
                        var repository             = ObjectFactory.GetInstance <IDeploymentRepository>();
                        var uncertifiedDeployments = repository.FindSuccessfulUncertified(selectedApplication.Name, selectedEnvironment.Name);

                        var deployments = uncertifiedDeployments.Where(d => d.Version == requestedVersion).OrderByDescending(d => d.DeployedOn);

                        if (deployments.Count() > 0)
                        {
                            var deployment = deployments.ElementAt(0);
                            var certifier  = ObjectFactory.GetInstance <IVersionCertifier>();
                            certifier.Certify(deployment);
                        }
                        else
                        {
                            OutputUsageAndClose("When certifying a deployment, you must specify a valid deployment that has not already been certified");
                        }
                    }
                    else
                    {
                        OutputUsageAndClose("Specify either 'Deploy' or 'Certify' for the <Action> argument");
                    }
                }
            }
        }