Esempio n. 1
0
        public override int Execute(string[] commandLineArguments)
        {
            var packageFile = variables.GetPathToPrimaryPackage(fileSystem, true);

            var journal = new DeploymentJournal(fileSystem, SemaphoreFactory.Get(), variables);

            var conventions = new List <IConvention>
            {
                new AlreadyInstalledConvention(log, journal),
                new TransferPackageConvention(log, fileSystem),
            };

            var deployment       = new RunningDeployment(packageFile, variables);
            var conventionRunner = new ConventionProcessor(deployment, conventions);

            try
            {
                conventionRunner.RunConventions();
                deploymentJournalWriter.AddJournalEntry(deployment, true);
            }
            catch (Exception)
            {
                deploymentJournalWriter.AddJournalEntry(deployment, false);
                throw;
            }

            return(0);
        }
Esempio n. 2
0
        public override int Execute(string[] commandLineArguments)
        {
            Options.Parse(commandLineArguments);

            Guard.NotNullOrWhiteSpace(retentionPolicySet, "No retention-policy-set was specified. Please pass --retentionPolicySet \"Environments-2/projects-161/Step-Package B/machines-65/<default>\"");

            if (days <= 0 && releases <= 0)
            {
                throw new CommandException("A value must be provided for either --days or --releases");
            }

            var variables = new CalamariVariableDictionary();

            variables.EnrichWithEnvironmentVariables();

            var fileSystem        = CalamariPhysicalFileSystem.GetPhysicalFileSystem();
            var deploymentJournal = new DeploymentJournal(fileSystem, SemaphoreFactory.Get(), variables);
            var clock             = new SystemClock();

            var retentionPolicy = new RetentionPolicy(fileSystem, deploymentJournal, clock);

            retentionPolicy.ApplyRetentionPolicy(retentionPolicySet, days, releases);

            return(0);
        }
        public override int Execute(string[] commandLineArguments)
        {
            var packageFile = variables.GetPathToPrimaryPackage(fileSystem, true);

            if (packageFile == null) // required: true in the above call means it will throw rather than return null, but there's no way to tell the compiler that. And ! doesn't work in older frameworks
            {
                throw new CommandException("Package File path could not be determined");
            }

            var journal = new DeploymentJournal(fileSystem, SemaphoreFactory.Get(), variables);

            var conventions = new List <IConvention>
            {
                new AlreadyInstalledConvention(log, journal),
                new TransferPackageConvention(log, fileSystem),
            };

            var deployment       = new RunningDeployment(packageFile, variables);
            var conventionRunner = new ConventionProcessor(deployment, conventions, log);

            try
            {
                conventionRunner.RunConventions();
                deploymentJournalWriter.AddJournalEntry(deployment, true);
            }
            catch (Exception)
            {
                deploymentJournalWriter.AddJournalEntry(deployment, false);
                throw;
            }

            return(0);
        }
Esempio n. 4
0
        public override int Execute(string[] commandLineArguments)
        {
            Options.Parse(commandLineArguments);

            variables.EnrichWithEnvironmentVariables();
            variables.LogVariables();

            var filesystem = CalamariPhysicalFileSystem.GetPhysicalFileSystem();
            var semaphore  = SemaphoreFactory.Get();

            journal    = new DeploymentJournal(filesystem, semaphore, variables);
            deployment = new RunningDeployment(packageFile, (CalamariVariableDictionary)variables);

            ValidateArguments();

            var result = ExecuteScriptFromPackage() ??
                         ExecuteScriptFromVariables() ??
                         ExecuteScriptFromParameters();

            if (result.HasValue)
            {
                return(result.Value);
            }

            throw new CommandException("No script details provided.\r\n" +
                                       $"Pleave provide the script either via the `{SpecialVariables.Action.Script.ScriptBody}` variable, " +
                                       "through a package provided via the `--package` argument or directly via the `--script` argument.");
        }
        public override int Execute(string[] commandLineArguments)
        {
            Options.Parse(commandLineArguments);

            var fileSystem = CalamariPhysicalFileSystem.GetPhysicalFileSystem();

            var variables   = new CalamariVariableDictionary(variablesFile, sensitiveVariablesFile, sensitiveVariablesPassword);
            var packageFile = variables.GetEnvironmentExpandedPath(SpecialVariables.Tentacle.CurrentDeployment.PackageFilePath);

            if (string.IsNullOrEmpty(packageFile))
            {
                throw new CommandException($"No package file was specified. Please provide `{SpecialVariables.Tentacle.CurrentDeployment.PackageFilePath}` variable");
            }

            if (!fileSystem.FileExists(packageFile))
            {
                throw new CommandException("Could not find package file: " + packageFile);
            }

            fileSystem.FreeDiskSpaceOverrideInMegaBytes = variables.GetInt32(SpecialVariables.FreeDiskSpaceOverrideInMegaBytes);
            fileSystem.SkipFreeDiskSpaceCheck           = variables.GetFlag(SpecialVariables.SkipFreeDiskSpaceCheck);

            var commandLineRunner = new CommandLineRunner(new SplitCommandOutput(new ConsoleCommandOutput(), new ServiceMessageCommandOutput(variables)));
            var journal           = new DeploymentJournal(fileSystem, SemaphoreFactory.Get(), variables);

            var conventions = new List <IConvention>
            {
                new ContributeEnvironmentVariablesConvention(),
                new ContributePreviousInstallationConvention(journal),
                new ContributePreviousSuccessfulInstallationConvention(journal),
                new LogVariablesConvention(),
                new AlreadyInstalledConvention(journal),
                new TransferPackageConvention(fileSystem),
                new RollbackScriptConvention(DeploymentStages.DeployFailed, fileSystem, new CombinedScriptEngine(), commandLineRunner),
            };

            var deployment       = new RunningDeployment(packageFile, variables);
            var conventionRunner = new ConventionProcessor(deployment, conventions);

            try
            {
                conventionRunner.RunConventions();
                if (!deployment.SkipJournal)
                {
                    journal.AddJournalEntry(new JournalEntry(deployment, true));
                }
            }
            catch (Exception)
            {
                if (!deployment.SkipJournal)
                {
                    journal.AddJournalEntry(new JournalEntry(deployment, false));
                }
                throw;
            }

            return(0);
        }
Esempio n. 6
0
        public CommandResult Execute(Script script,
                                     IVariables variables,
                                     ICommandLineRunner commandLineRunner,
                                     Dictionary <string, string>?environmentVars = null)
        {
            var environmentVariablesIncludingProxy = environmentVars ?? new Dictionary <string, string>();

            foreach (var proxyVariable in ProxyEnvironmentVariablesGenerator.GenerateProxyEnvironmentVariables())
            {
                environmentVariablesIncludingProxy[proxyVariable.Key] = proxyVariable.Value;
            }

            var prepared = PrepareExecution(script, variables, environmentVariablesIncludingProxy);

            CommandResult?result = null;

            foreach (var execution in prepared)
            {
                if (variables.IsSet(CopyWorkingDirectoryVariable))
                {
                    CopyWorkingDirectory(variables,
                                         execution.CommandLineInvocation.WorkingDirectory,
                                         execution.CommandLineInvocation.Arguments);
                }

                try
                {
                    if (execution.CommandLineInvocation.Isolate)
                    {
                        using (SemaphoreFactory.Get()
                               .Acquire("CalamariSynchronizeProcess",
                                        "Waiting for other process to finish executing script"))
                        {
                            result = commandLineRunner.Execute(execution.CommandLineInvocation);
                        }
                    }
                    else
                    {
                        result = commandLineRunner.Execute(execution.CommandLineInvocation);
                    }

                    if (result.ExitCode != 0)
                    {
                        return(result);
                    }
                }
                finally
                {
                    foreach (var temporaryFile in execution.TemporaryFiles)
                    {
                        var fileSystem = CalamariPhysicalFileSystem.GetPhysicalFileSystem();
                        fileSystem.DeleteFile(temporaryFile, FailureOptions.IgnoreFailure);
                    }
                }
            }

            return(result !);
        }
Esempio n. 7
0
        public void ReturnsFileBasedSemaphoreManagerForMono()
        {
            if (!CalamariEnvironment.IsRunningOnMono)
            {
                Assert.Ignore("This test is designed to run on mono");
            }
            var result = SemaphoreFactory.Get();

            Assert.That(result, Is.InstanceOf <FileBasedSempahoreManager>());
        }
Esempio n. 8
0
        public void ReturnsSystemSemaphoreManagerForWindows()
        {
            if (!CalamariEnvironment.IsRunningOnWindows)
            {
                Assert.Ignore("This test is designed to run on windows");
            }
            var result = SemaphoreFactory.Get();

            Assert.That(result, Is.InstanceOf <SystemSemaphoreManager>());
        }
Esempio n. 9
0
        public static void Contribute(ICalamariFileSystem fileSystem, IVariables variables)
        {
            var policySet = variables.Get(KnownVariables.RetentionPolicySet);

            if (string.IsNullOrWhiteSpace(policySet))
            {
                return;
            }

            var journal = new DeploymentJournal(fileSystem, SemaphoreFactory.Get(), variables);

            Previous(variables, journal, policySet);
            PreviousSuccessful(variables, journal, policySet);
        }
Esempio n. 10
0
        /// <summary>
        /// Conditionally Write To Journal if there were packages that may need to be cleaned up during retention
        /// </summary>
        /// <param name="deployment"></param>
        /// <param name="wasSuccessful">Was the command successful. Usually ExitCode == 0</param>
        /// <param name="packageFile">Since package references can still be passed by the command line this needs to be provided here.
        /// Can remove once we obtain all references through variables</param>
        public void AddJournalEntry(RunningDeployment deployment, bool wasSuccessful, string?packageFile = null)
        {
            var semaphore = SemaphoreFactory.Get();
            var journal   = new DeploymentJournal(fileSystem, semaphore, deployment.Variables);

            var hasPackages = !string.IsNullOrWhiteSpace(packageFile) ||
                              deployment.Variables.GetIndexes(PackageVariables.PackageCollection).Any();

            var canWrite = deployment.Variables.Get(TentacleVariables.Agent.JournalPath) != null;

            if (canWrite && hasPackages && !deployment.SkipJournal)
            {
                journal.AddJournalEntry(new JournalEntry(deployment, wasSuccessful));
            }
        }
Esempio n. 11
0
        protected override void ConfigureContainer(ContainerBuilder builder, CommonOptions options)
        {
            // Setting extensions here as in the new Modularity world we don't register extensions
            // and GetAllAssembliesToRegister doesn't get passed CommonOptions
            extensions = options.Extensions;

            base.ConfigureContainer(builder, options);

            builder.RegisterType <CalamariCertificateStore>().As <ICertificateStore>().SingleInstance();
            builder.RegisterType <DeploymentJournalWriter>().As <IDeploymentJournalWriter>().SingleInstance();
            builder.RegisterType <PackageStore>().As <IPackageStore>().SingleInstance();

            builder.RegisterType <KubernetesDiscovererFactory>()
            .As <IKubernetesDiscovererFactory>()
            .SingleInstance();

            builder.RegisterInstance(SemaphoreFactory.Get()).As <ISemaphoreFactory>();

            builder.RegisterModule <PackageRetentionModule>();

            TypeDescriptor.AddAttributes(typeof(ServerTaskId), new TypeConverterAttribute(typeof(TinyTypeTypeConverter <ServerTaskId>)));

            //Add decorator to commands with the RetentionLockingCommand attribute. Also need to include commands defined in external assemblies.
            var assembliesToRegister = GetAllAssembliesToRegister().ToArray();

            builder.RegisterAssemblyTypes(assembliesToRegister)
            .AssignableTo <IKubernetesDiscoverer>()
            .As <IKubernetesDiscoverer>();

            //Register the non-decorated commands
            builder.RegisterAssemblyTypes(assembliesToRegister)
            .AssignableTo <ICommandWithArgs>()
            .WithMetadataFrom <CommandAttribute>()
            .As <ICommandWithArgs>();

            builder.RegisterAssemblyTypes(assembliesToRegister)
            .AssignableTo <ICommandWithInputs>()
            .WithMetadataFrom <CommandAttribute>()
            .As <ICommandWithInputs>();

            builder.RegisterAssemblyTypes(GetProgramAssemblyToRegister())
            .Where(x => typeof(ILaunchTool).IsAssignableFrom(x) && !x.IsAbstract && !x.IsInterface)
            .WithMetadataFrom <LaunchToolAttribute>()
            .As <ILaunchTool>();
        }
        public override int Execute(string[] commandLineArguments)
        {
            Options.Parse(commandLineArguments);

            var variables = new CalamariVariableDictionary(variablesFile, sensitiveVariablesFile, sensitiveVariablesPassword);

            variables.EnrichWithEnvironmentVariables();
            variables.LogVariables();

            var filesystem = CalamariPhysicalFileSystem.GetPhysicalFileSystem();
            var semaphore  = SemaphoreFactory.Get();

            journal = new DeploymentJournal(filesystem, semaphore, variables);

            ExtractPackage(variables);
            SubstituteVariablesInScript(variables);
            return(InvokeScript(variables));
        }
Esempio n. 13
0
        public void SetUp()
        {
            fileSystem = CalamariPhysicalFileSystem.GetPhysicalFileSystem();

            // Ensure tenticle directory exists
            tentacleDirectory = Path.Combine(Path.GetTempPath(), "CalamariTestTentacle");
            var tentacleHiddenDirectory = Path.Combine(tentacleDirectory, ".tentacle");

            fileSystem.EnsureDirectoryExists(tentacleDirectory);
            fileSystem.EnsureDirectoryExists(tentacleHiddenDirectory);
            fileSystem.PurgeDirectory(tentacleHiddenDirectory, FailureOptions.ThrowOnFailure);

            Environment.SetEnvironmentVariable("TentacleJournal", Path.Combine(tentacleHiddenDirectory, "DeploymentJournal.xml"));
            Environment.SetEnvironmentVariable("TentacleHome", tentacleHiddenDirectory);

            variables = new VariableDictionary();
            variables.EnrichWithEnvironmentVariables();

            deploymentJournal = new DeploymentJournal(fileSystem, SemaphoreFactory.Get(), variables);

            packagesDirectory = Path.Combine(Path.GetTempPath(), "CalamariTestPackages");
            fileSystem.EnsureDirectoryExists(packagesDirectory);
            stagingDirectory = Path.Combine(Path.GetTempPath(), "CalamariTestStaging");
            fileSystem.EnsureDirectoryExists(stagingDirectory);

            // Create some artificats
            const string retentionPolicySet1 = "retentionPolicySet1";

            CreateDeployment(Path.Combine(packagesDirectory, "Acme.1.0.0.nupkg"), Path.Combine(stagingDirectory, "Acme.1.0.0"),
                             new DateTimeOffset(new DateTime(2015, 01, 26), new TimeSpan(10, 0, 0)), retentionPolicySet1);

            CreateDeployment(Path.Combine(packagesDirectory, "Acme.1.1.0.nupkg"), Path.Combine(stagingDirectory, "Acme.1.1.0"),
                             new DateTimeOffset(new DateTime(2015, 02, 01), new TimeSpan(10, 0, 0)), retentionPolicySet1);

            CreateDeployment(Path.Combine(packagesDirectory, "Acme.1.2.0.nupkg"), Path.Combine(stagingDirectory, "Acme.1.2.0"),
                             new DateTimeOffset(new DateTime(2015, 02, 10), new TimeSpan(10, 0, 0)), retentionPolicySet1);
        }
        public override int Execute(string[] commandLineArguments)
        {
            Options.Parse(commandLineArguments);

            Guard.NotNullOrWhiteSpace(packageFile, "No package file was specified. Please pass --package YourPackage.nupkg");

            if (!File.Exists(packageFile))
            {
                throw new CommandException("Could not find package file: " + packageFile);
            }

            Log.Info("Deploying package:    " + packageFile);

            var fileSystem = CalamariPhysicalFileSystem.GetPhysicalFileSystem();

            var variables = new CalamariVariableDictionary(variablesFile, sensitiveVariablesFile, sensitiveVariablesPassword);

            fileSystem.FreeDiskSpaceOverrideInMegaBytes = variables.GetInt32(SpecialVariables.FreeDiskSpaceOverrideInMegaBytes);
            fileSystem.SkipFreeDiskSpaceCheck           = variables.GetFlag(SpecialVariables.SkipFreeDiskSpaceCheck);

            var featureClasses = new List <IFeature>();

            var replacer    = new ConfigurationVariablesReplacer(variables.GetFlag(SpecialVariables.Package.IgnoreVariableReplacementErrors));
            var generator   = new JsonConfigurationVariableReplacer();
            var substituter = new FileSubstituter(fileSystem);
            var configurationTransformer = ConfigurationTransformer.FromVariables(variables);
            var transformFileLocator     = new TransformFileLocator(fileSystem);
            var embeddedResources        = new AssemblyEmbeddedResources();

#if IIS_SUPPORT
            var iis = new InternetInformationServer();
            featureClasses.AddRange(new IFeature[] { new IisWebSiteBeforeDeployFeature(), new IisWebSiteAfterPostDeployFeature() });
#endif
            var commandLineRunner = new CommandLineRunner(new SplitCommandOutput(new ConsoleCommandOutput(), new ServiceMessageCommandOutput(variables)));
            var semaphore         = SemaphoreFactory.Get();
            var journal           = new DeploymentJournal(fileSystem, semaphore, variables);

            var conventions = new List <IConvention>
            {
                new ContributeEnvironmentVariablesConvention(),
                new ContributePreviousInstallationConvention(journal),
                new ContributePreviousSuccessfulInstallationConvention(journal),
                new LogVariablesConvention(),
                new AlreadyInstalledConvention(journal),
                new ExtractPackageToApplicationDirectoryConvention(new GenericPackageExtractorFactory().createStandardGenericPackageExtractor(), fileSystem),
                new FeatureConvention(DeploymentStages.BeforePreDeploy, featureClasses, fileSystem, scriptEngine, commandLineRunner, embeddedResources),
                new ConfiguredScriptConvention(DeploymentStages.PreDeploy, fileSystem, scriptEngine, commandLineRunner),
                new PackagedScriptConvention(DeploymentStages.PreDeploy, fileSystem, scriptEngine, commandLineRunner),
                new FeatureConvention(DeploymentStages.AfterPreDeploy, featureClasses, fileSystem, scriptEngine, commandLineRunner, embeddedResources),
                new SubstituteInFilesConvention(fileSystem, substituter),
                new ConfigurationTransformsConvention(fileSystem, configurationTransformer, transformFileLocator),
                new ConfigurationVariablesConvention(fileSystem, replacer),
                new JsonConfigurationVariablesConvention(generator, fileSystem),
                new CopyPackageToCustomInstallationDirectoryConvention(fileSystem),
                new FeatureConvention(DeploymentStages.BeforeDeploy, featureClasses, fileSystem, scriptEngine, commandLineRunner, embeddedResources),
                new PackagedScriptConvention(DeploymentStages.Deploy, fileSystem, scriptEngine, commandLineRunner),
                new ConfiguredScriptConvention(DeploymentStages.Deploy, fileSystem, scriptEngine, commandLineRunner),
                new FeatureConvention(DeploymentStages.AfterDeploy, featureClasses, fileSystem, scriptEngine, commandLineRunner, embeddedResources),
#if IIS_SUPPORT
                new LegacyIisWebSiteConvention(fileSystem, iis),
#endif
                new FeatureConvention(DeploymentStages.BeforePostDeploy, featureClasses, fileSystem, scriptEngine, commandLineRunner, embeddedResources),
                new PackagedScriptConvention(DeploymentStages.PostDeploy, fileSystem, scriptEngine, commandLineRunner),
                new ConfiguredScriptConvention(DeploymentStages.PostDeploy, fileSystem, scriptEngine, commandLineRunner),
                new FeatureConvention(DeploymentStages.AfterPostDeploy, featureClasses, fileSystem, scriptEngine, commandLineRunner, embeddedResources),
                new RollbackScriptConvention(DeploymentStages.DeployFailed, fileSystem, scriptEngine, commandLineRunner),
                new FeatureRollbackConvention(DeploymentStages.DeployFailed, fileSystem, scriptEngine, commandLineRunner, embeddedResources)
            };

            var deployment       = new RunningDeployment(packageFile, variables);
            var conventionRunner = new ConventionProcessor(deployment, conventions);

            try
            {
                conventionRunner.RunConventions();
                if (!deployment.SkipJournal)
                {
                    journal.AddJournalEntry(new JournalEntry(deployment, true));
                }
            }
            catch (Exception)
            {
                if (!deployment.SkipJournal)
                {
                    journal.AddJournalEntry(new JournalEntry(deployment, false));
                }
                throw;
            }

            return(0);
        }
Esempio n. 15
0
        public override int Execute(string[] commandLineArguments)
        {
            Options.Parse(commandLineArguments);

            Guard.NotNullOrWhiteSpace(archiveFile, "No archive file was specified. Please pass --archive YourPackage.jar");
            JavaRuntime.VerifyExists();

            if (!File.Exists(archiveFile))
            {
                throw new CommandException("Could not find archive file: " + archiveFile);
            }

            Log.Info("Deploying:    " + archiveFile);

            var fileSystem = CalamariPhysicalFileSystem.GetPhysicalFileSystem();

            var variables     = new CalamariVariableDictionary(variablesFile, sensitiveVariablesFile, sensitiveVariablesPassword);
            var semaphore     = SemaphoreFactory.Get();
            var journal       = new DeploymentJournal(fileSystem, semaphore, variables);
            var substituter   = new FileSubstituter(fileSystem);
            var commandOutput =
                new SplitCommandOutput(new ConsoleCommandOutput(), new ServiceMessageCommandOutput(variables));
            var commandLineRunner = new CommandLineRunner(commandOutput);
            var jsonReplacer      = new JsonConfigurationVariableReplacer();
            var jarTools          = new JarTool(commandLineRunner, commandOutput, variables);
            var packageExtractor  = new JavaPackageExtractor(jarTools);
            var embeddedResources = new AssemblyEmbeddedResources();
            var javaRunner        = new JavaRunner(commandLineRunner, variables);


            var featureClasses = new List <IFeature>
            {
                new TomcatFeature(javaRunner),
                new WildflyFeature(javaRunner)
            };

            var deployExploded = variables.GetFlag(SpecialVariables.Action.Java.DeployExploded);

            var conventions = new List <IConvention>
            {
                new ContributeEnvironmentVariablesConvention(),
                new ContributePreviousInstallationConvention(journal),
                new ContributePreviousSuccessfulInstallationConvention(journal),
                new LogVariablesConvention(),
                new AlreadyInstalledConvention(journal),
                // If we are deploying the package exploded then extract directly to the application directory.
                // Else, if we are going to re-pack, then we extract initially to a temporary directory
                deployExploded
                    ? (IInstallConvention) new ExtractPackageToApplicationDirectoryConvention(packageExtractor, fileSystem)
                    : new ExtractPackageToStagingDirectoryConvention(packageExtractor, fileSystem),
                new FeatureConvention(DeploymentStages.BeforePreDeploy, featureClasses, fileSystem, scriptEngine, commandLineRunner, embeddedResources),
                new ConfiguredScriptConvention(DeploymentStages.PreDeploy, fileSystem, scriptEngine, commandLineRunner),
                new PackagedScriptConvention(DeploymentStages.PreDeploy, fileSystem, scriptEngine, commandLineRunner),
                new FeatureConvention(DeploymentStages.AfterPreDeploy, featureClasses, fileSystem, scriptEngine, commandLineRunner, embeddedResources),
                new SubstituteInFilesConvention(fileSystem, substituter),
                new JsonConfigurationVariablesConvention(jsonReplacer, fileSystem),
                new RePackArchiveConvention(fileSystem, jarTools),
                new CopyPackageToCustomInstallationDirectoryConvention(fileSystem),
                new FeatureConvention(DeploymentStages.BeforeDeploy, featureClasses, fileSystem, scriptEngine, commandLineRunner, embeddedResources),
                new PackagedScriptConvention(DeploymentStages.Deploy, fileSystem, scriptEngine, commandLineRunner),
                new ConfiguredScriptConvention(DeploymentStages.Deploy, fileSystem, scriptEngine, commandLineRunner),
                new FeatureConvention(DeploymentStages.AfterDeploy, featureClasses, fileSystem, scriptEngine, commandLineRunner, embeddedResources),
                new FeatureConvention(DeploymentStages.BeforePostDeploy, featureClasses, fileSystem, scriptEngine, commandLineRunner, embeddedResources),
                new PackagedScriptConvention(DeploymentStages.PostDeploy, fileSystem, scriptEngine, commandLineRunner),
                new ConfiguredScriptConvention(DeploymentStages.PostDeploy, fileSystem, scriptEngine, commandLineRunner),
                new FeatureConvention(DeploymentStages.AfterPostDeploy, featureClasses, fileSystem, scriptEngine, commandLineRunner, embeddedResources),
                new RollbackScriptConvention(DeploymentStages.DeployFailed, fileSystem, scriptEngine, commandLineRunner),
                new FeatureRollbackConvention(DeploymentStages.DeployFailed, fileSystem, scriptEngine, commandLineRunner, embeddedResources)
            };

            var deployment       = new RunningDeployment(archiveFile, variables);
            var conventionRunner = new ConventionProcessor(deployment, conventions);

            try
            {
                conventionRunner.RunConventions();
                if (!deployment.SkipJournal)
                {
                    journal.AddJournalEntry(new JournalEntry(deployment, true));
                }
            }
            catch (Exception)
            {
                if (!deployment.SkipJournal)
                {
                    journal.AddJournalEntry(new JournalEntry(deployment, false));
                }
                throw;
            }

            return(0);
        }
        public override int Execute(string[] commandLineArguments)
        {
            Options.Parse(commandLineArguments);

            Guard.NotNullOrWhiteSpace(packageFile, "No package file was specified. Please pass --package YourPackage.nupkg");

            if (!File.Exists(packageFile))
            {
                throw new CommandException("Could not find package file: " + packageFile);
            }

            if (variablesFile != null && !File.Exists(variablesFile))
            {
                throw new CommandException("Could not find variables file: " + variablesFile);
            }

            Log.Info("Deploying package:    " + packageFile);
            var variables = new CalamariVariableDictionary(variablesFile, sensitiveVariablesFile, sensitiveVariablesPassword);

            var fileSystem                         = new WindowsPhysicalFileSystem();
            var embeddedResources                  = new AssemblyEmbeddedResources();
            var scriptEngine                       = new CombinedScriptEngine();
            var commandLineRunner                  = new CommandLineRunner(new SplitCommandOutput(new ConsoleCommandOutput(), new ServiceMessageCommandOutput(variables)));
            var azurePackageUploader               = new AzurePackageUploader();
            var certificateStore                   = new CalamariCertificateStore();
            var cloudCredentialsFactory            = new SubscriptionCloudCredentialsFactory(certificateStore);
            var cloudServiceConfigurationRetriever = new AzureCloudServiceConfigurationRetriever();
            var substituter                        = new FileSubstituter(fileSystem);
            var configurationTransformer           = ConfigurationTransformer.FromVariables(variables);
            var transformFileLocator               = new TransformFileLocator(fileSystem);
            var replacer = new ConfigurationVariablesReplacer(variables.GetFlag(SpecialVariables.Package.IgnoreVariableReplacementErrors));
            var jsonVariablesReplacer = new JsonConfigurationVariableReplacer();

            var conventions = new List <IConvention>
            {
                new ContributeEnvironmentVariablesConvention(),
                new LogVariablesConvention(),
                new SwapAzureDeploymentConvention(fileSystem, embeddedResources, scriptEngine, commandLineRunner),
                new ExtractPackageToStagingDirectoryConvention(new GenericPackageExtractor(), fileSystem),
                new FindCloudServicePackageConvention(fileSystem),
                new EnsureCloudServicePackageIsCtpFormatConvention(fileSystem),
                new ExtractAzureCloudServicePackageConvention(fileSystem),
                new ChooseCloudServiceConfigurationFileConvention(fileSystem),
                new ConfiguredScriptConvention(DeploymentStages.PreDeploy, fileSystem, scriptEngine, commandLineRunner),
                new PackagedScriptConvention(DeploymentStages.PreDeploy, fileSystem, scriptEngine, commandLineRunner),
                new ConfigureAzureCloudServiceConvention(fileSystem, cloudCredentialsFactory, cloudServiceConfigurationRetriever),
                new SubstituteInFilesConvention(fileSystem, substituter),
                new ConfigurationTransformsConvention(fileSystem, configurationTransformer, transformFileLocator),
                new ConfigurationVariablesConvention(fileSystem, replacer),
                new JsonConfigurationVariablesConvention(jsonVariablesReplacer, fileSystem),
                new PackagedScriptConvention(DeploymentStages.Deploy, fileSystem, scriptEngine, commandLineRunner),
                new ConfiguredScriptConvention(DeploymentStages.Deploy, fileSystem, scriptEngine, commandLineRunner),
                new RePackageCloudServiceConvention(fileSystem, SemaphoreFactory.Get()),
                new UploadAzureCloudServicePackageConvention(fileSystem, azurePackageUploader, cloudCredentialsFactory),
                new DeployAzureCloudServicePackageConvention(fileSystem, embeddedResources, scriptEngine, commandLineRunner),
                new PackagedScriptConvention(DeploymentStages.PostDeploy, fileSystem, scriptEngine, commandLineRunner),
                new ConfiguredScriptConvention(DeploymentStages.PostDeploy, fileSystem, scriptEngine, commandLineRunner),
            };

            var deployment       = new RunningDeployment(packageFile, variables);
            var conventionRunner = new ConventionProcessor(deployment, conventions);

            conventionRunner.RunConventions();

            return(0);
        }
        public override int Execute(string[] commandLineArguments)
        {
            Options.Parse(commandLineArguments);

            Guard.NotNullOrWhiteSpace(archiveFile, "No archive file was specified. Please pass --archive YourPackage.jar");
            JavaRuntime.VerifyExists();

            if (!File.Exists(archiveFile))
            {
                throw new CommandException("Could not find archive file: " + archiveFile);
            }

            Log.Info("Deploying:    " + archiveFile);

            var semaphore = SemaphoreFactory.Get();
            var journal   = new DeploymentJournal(fileSystem, semaphore, variables);
            var allFileFormatReplacers           = FileFormatVariableReplacers.BuildAllReplacers(fileSystem, log);
            var structuredConfigVariablesService = new StructuredConfigVariablesService(allFileFormatReplacers, fileSystem, log);
            var jarTools          = new JarTool(commandLineRunner, log, variables);
            var packageExtractor  = new JarPackageExtractor(jarTools);
            var embeddedResources = new AssemblyEmbeddedResources();
            var javaRunner        = new JavaRunner(commandLineRunner, variables);


            var featureClasses = new List <IFeature>
            {
                new TomcatFeature(javaRunner),
                new WildflyFeature(javaRunner)
            };

            var deployExploded = variables.GetFlag(SpecialVariables.Action.Java.DeployExploded);

            var conventions = new List <IConvention>
            {
                new AlreadyInstalledConvention(log, journal),
                // If we are deploying the package exploded then extract directly to the application directory.
                // Else, if we are going to re-pack, then we extract initially to a temporary directory
                deployExploded
                    ? (IInstallConvention) new DelegateInstallConvention(d => extractPackage.ExtractToApplicationDirectory(archiveFile, packageExtractor))
                    : new DelegateInstallConvention(d => extractPackage.ExtractToStagingDirectory(archiveFile, packageExtractor)),
                new FeatureConvention(DeploymentStages.BeforePreDeploy, featureClasses, fileSystem, scriptEngine, commandLineRunner, embeddedResources),
                new ConfiguredScriptConvention(new PreDeployConfiguredScriptBehaviour(log, fileSystem, scriptEngine, commandLineRunner)),
                new PackagedScriptConvention(new PreDeployPackagedScriptBehaviour(log, fileSystem, scriptEngine, commandLineRunner)),
                new FeatureConvention(DeploymentStages.AfterPreDeploy, featureClasses, fileSystem, scriptEngine, commandLineRunner, embeddedResources),
                new SubstituteInFilesConvention(new SubstituteInFilesBehaviour(substituteInFiles)),
                new StructuredConfigurationVariablesConvention(new StructuredConfigurationVariablesBehaviour(structuredConfigVariablesService)),
                new RePackArchiveConvention(log, fileSystem, jarTools),
                new CopyPackageToCustomInstallationDirectoryConvention(fileSystem),
                new FeatureConvention(DeploymentStages.BeforeDeploy, featureClasses, fileSystem, scriptEngine, commandLineRunner, embeddedResources),
                new PackagedScriptConvention(new DeployPackagedScriptBehaviour(log, fileSystem, scriptEngine, commandLineRunner)),
                new ConfiguredScriptConvention(new DeployConfiguredScriptBehaviour(log, fileSystem, scriptEngine, commandLineRunner)),
                new FeatureConvention(DeploymentStages.AfterDeploy, featureClasses, fileSystem, scriptEngine, commandLineRunner, embeddedResources),
                new FeatureConvention(DeploymentStages.BeforePostDeploy, featureClasses, fileSystem, scriptEngine, commandLineRunner, embeddedResources),
                new PackagedScriptConvention(new PostDeployPackagedScriptBehaviour(log, fileSystem, scriptEngine, commandLineRunner)),
                new ConfiguredScriptConvention(new PostDeployConfiguredScriptBehaviour(log, fileSystem, scriptEngine, commandLineRunner)),
                new FeatureConvention(DeploymentStages.AfterPostDeploy, featureClasses, fileSystem, scriptEngine, commandLineRunner, embeddedResources),
                new RollbackScriptConvention(log, DeploymentStages.DeployFailed, fileSystem, scriptEngine, commandLineRunner),
                new FeatureRollbackConvention(DeploymentStages.DeployFailed, fileSystem, scriptEngine, commandLineRunner, embeddedResources)
            };

            var deployment       = new RunningDeployment(archiveFile, variables);
            var conventionRunner = new ConventionProcessor(deployment, conventions, log);

            try
            {
                conventionRunner.RunConventions();
                if (!deployment.SkipJournal)
                {
                    journal.AddJournalEntry(new JournalEntry(deployment, true));
                }
            }
            catch (Exception)
            {
                if (!deployment.SkipJournal)
                {
                    journal.AddJournalEntry(new JournalEntry(deployment, false));
                }
                throw;
            }

            return(0);
        }
Esempio n. 18
0
        public void ReturnsSystemSemaphoreManagerForAllPlatformsUnderNetCore()
        {
            var result = SemaphoreFactory.Get();

            Assert.That(result, Is.InstanceOf <SystemSemaphoreManager>());
        }
Esempio n. 19
0
        public void SetUp()
        {
            extractor = Substitute.For <IPackageExtractor>();
            extractor.GetMetadata(PackageLocation).Returns(new PackageMetadata {
                Id = "Acme.Web", Version = "1.0.0"
            });

            fileSystem = Substitute.For <ICalamariFileSystem>();
            fileSystem.RemoveInvalidFileNameChars(Arg.Any <string>()).Returns(c => c.Arg <string>().Replace("!", ""));

            variables  = new CalamariVariableDictionary();
            convention = new ExtractPackageToApplicationDirectoryConvention(extractor, fileSystem, SemaphoreFactory.Get());
        }
        public override int Execute(string[] commandLineArguments)
        {
            Options.Parse(commandLineArguments);

            Guard.NotNullOrWhiteSpace(pathToPackage, "No package file was specified. Please pass --package YourPackage.nupkg");

            if (!File.Exists(pathToPackage))
            {
                throw new CommandException("Could not find package file: " + pathToPackage);
            }

            Log.Info("Deploying package:    " + pathToPackage);

            var featureClasses = new List <IFeature>();

            var replacer = new ConfigurationVariablesReplacer(variables, log);
            var allFileFormatReplacers           = FileFormatVariableReplacers.BuildAllReplacers(fileSystem, log);
            var structuredConfigVariablesService = new StructuredConfigVariablesService(allFileFormatReplacers, fileSystem, log);
            var configurationTransformer         = ConfigurationTransformer.FromVariables(variables, log);
            var transformFileLocator             = new TransformFileLocator(fileSystem, log);
            var embeddedResources = new AssemblyEmbeddedResources();

#if IIS_SUPPORT
            var iis = new InternetInformationServer();
            featureClasses.AddRange(new IFeature[] { new IisWebSiteBeforeDeployFeature(), new IisWebSiteAfterPostDeployFeature() });
#endif
            if (!CalamariEnvironment.IsRunningOnWindows)
            {
                featureClasses.Add(new NginxFeature(NginxServer.AutoDetect(), fileSystem));
            }

            var semaphore = SemaphoreFactory.Get();
            var journal   = new DeploymentJournal(fileSystem, semaphore, variables);

            var conventions = new List <IConvention>
            {
                new AlreadyInstalledConvention(log, journal),
                new DelegateInstallConvention(d => extractPackage.ExtractToApplicationDirectory(pathToPackage)),
                new FeatureConvention(DeploymentStages.BeforePreDeploy, featureClasses, fileSystem, scriptEngine, commandLineRunner, embeddedResources),
                new ConfiguredScriptConvention(new PreDeployConfiguredScriptBehaviour(log, fileSystem, scriptEngine, commandLineRunner)),
                new PackagedScriptConvention(new PreDeployPackagedScriptBehaviour(log, fileSystem, scriptEngine, commandLineRunner)),
                new FeatureConvention(DeploymentStages.AfterPreDeploy, featureClasses, fileSystem, scriptEngine, commandLineRunner, embeddedResources),
                new SubstituteInFilesConvention(new SubstituteInFilesBehaviour(substituteInFiles)),
                new ConfigurationTransformsConvention(new ConfigurationTransformsBehaviour(fileSystem, configurationTransformer, transformFileLocator, log)),
                new ConfigurationVariablesConvention(new ConfigurationVariablesBehaviour(fileSystem, replacer, log)),
                new StructuredConfigurationVariablesConvention(new StructuredConfigurationVariablesBehaviour(structuredConfigVariablesService)),
                new CopyPackageToCustomInstallationDirectoryConvention(fileSystem),
                new FeatureConvention(DeploymentStages.BeforeDeploy, featureClasses, fileSystem, scriptEngine, commandLineRunner, embeddedResources),
                new PackagedScriptConvention(new DeployPackagedScriptBehaviour(log, fileSystem, scriptEngine, commandLineRunner)),
                new ConfiguredScriptConvention(new DeployConfiguredScriptBehaviour(log, fileSystem, scriptEngine, commandLineRunner)),
                new FeatureConvention(DeploymentStages.AfterDeploy, featureClasses, fileSystem, scriptEngine, commandLineRunner, embeddedResources),
#if IIS_SUPPORT
                new LegacyIisWebSiteConvention(fileSystem, iis),
#endif
                new FeatureConvention(DeploymentStages.BeforePostDeploy, featureClasses, fileSystem, scriptEngine, commandLineRunner, embeddedResources),
                new PackagedScriptConvention(new PostDeployPackagedScriptBehaviour(log, fileSystem, scriptEngine, commandLineRunner)),
                new ConfiguredScriptConvention(new PostDeployConfiguredScriptBehaviour(log, fileSystem, scriptEngine, commandLineRunner)),
                new FeatureConvention(DeploymentStages.AfterPostDeploy, featureClasses, fileSystem, scriptEngine, commandLineRunner, embeddedResources),
                new RollbackScriptConvention(log, DeploymentStages.DeployFailed, fileSystem, scriptEngine, commandLineRunner),
                new FeatureRollbackConvention(DeploymentStages.DeployFailed, fileSystem, scriptEngine, commandLineRunner, embeddedResources)
            };

            var deployment       = new RunningDeployment(pathToPackage, variables);
            var conventionRunner = new ConventionProcessor(deployment, conventions, log);

            try
            {
                conventionRunner.RunConventions();
                if (!deployment.SkipJournal)
                {
                    journal.AddJournalEntry(new JournalEntry(deployment, true));
                }
            }
            catch (Exception)
            {
                if (!deployment.SkipJournal)
                {
                    journal.AddJournalEntry(new JournalEntry(deployment, false));
                }
                throw;
            }

            return(0);
        }