public static ConfigurationTransformer FromVariables(CalamariVariableDictionary variables, ILog log = null) { var treatConfigTransformationWarningsAsErrors = variables.GetFlag(SpecialVariables.Package.TreatConfigTransformationWarningsAsErrors, true); var ignoreConfigTransformErrors = variables.GetFlag(SpecialVariables.Package.IgnoreConfigTransformationErrors); var suppressConfigTransformLogging = variables.GetFlag(SpecialVariables.Package.SuppressConfigTransformationLogging); var transformLoggingOptions = TransformLoggingOptions.None; if (treatConfigTransformationWarningsAsErrors) { transformLoggingOptions |= TransformLoggingOptions.LogWarningsAsErrors; } if (ignoreConfigTransformErrors) { transformLoggingOptions |= TransformLoggingOptions.LogExceptionsAsWarnings; transformLoggingOptions |= TransformLoggingOptions.LogWarningsAsInfo; transformLoggingOptions &= ~TransformLoggingOptions.LogWarningsAsErrors; } if (suppressConfigTransformLogging) { transformLoggingOptions |= TransformLoggingOptions.DoNotLogVerbose; } return(new ConfigurationTransformer(transformLoggingOptions, log)); }
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 replacer = new ConfigurationVariablesReplacer(variables.GetFlag(SpecialVariables.Package.IgnoreVariableReplacementErrors)); var jsonReplacer = new JsonConfigurationVariableReplacer(); var scriptEngine = new CombinedScriptEngine(); var substituter = new FileSubstituter(fileSystem); var commandLineRunner = new CommandLineRunner(new SplitCommandOutput(new ConsoleCommandOutput(), new ServiceMessageCommandOutput(variables))); var configurationTransformer = new ConfigurationTransformer( variables.GetFlag(SpecialVariables.Package.IgnoreConfigTransformationErrors), variables.GetFlag(SpecialVariables.Package.SuppressConfigTransformationLogging)); var transformFileLocator = new TransformFileLocator(fileSystem); var conventions = new List <IConvention> { new ContributeEnvironmentVariablesConvention(), new LogVariablesConvention(), new ExtractPackageToStagingDirectoryConvention(new GenericPackageExtractor(), fileSystem), new ConfiguredScriptConvention(DeploymentStages.PreDeploy, scriptEngine, fileSystem, commandLineRunner), new PackagedScriptConvention(DeploymentStages.PreDeploy, fileSystem, scriptEngine, commandLineRunner), new SubstituteInFilesConvention(fileSystem, substituter), new ConfigurationTransformsConvention(fileSystem, configurationTransformer, transformFileLocator), new ConfigurationVariablesConvention(fileSystem, replacer), new JsonConfigurationVariablesConvention(jsonReplacer, fileSystem), new PackagedScriptConvention(DeploymentStages.Deploy, fileSystem, scriptEngine, commandLineRunner), new ConfiguredScriptConvention(DeploymentStages.Deploy, scriptEngine, fileSystem, commandLineRunner), new AzureWebAppConvention(), new PackagedScriptConvention(DeploymentStages.PostDeploy, fileSystem, scriptEngine, commandLineRunner), new ConfiguredScriptConvention(DeploymentStages.PostDeploy, scriptEngine, fileSystem, commandLineRunner), }; var deployment = new RunningDeployment(packageFile, variables); var conventionRunner = new ConventionProcessor(deployment, conventions); conventionRunner.RunConventions(); return(0); }
private int InvokeScript(CalamariVariableDictionary variables) { var validatedScriptFilePath = AssertScriptFileExists(); var scriptEngine = new CombinedScriptEngine(); var runner = new CommandLineRunner( new SplitCommandOutput(new ConsoleCommandOutput(), new ServiceMessageCommandOutput(variables))); Log.VerboseFormat("Executing '{0}'", validatedScriptFilePath); var result = scriptEngine.Execute(new Script(validatedScriptFilePath, scriptParameters), variables, runner); var shouldWriteJournal = CanWriteJournal(variables) && deployment != null && !deployment.SkipJournal; if (result.ExitCode == 0 && result.HasErrors && variables.GetFlag(SpecialVariables.Action.FailScriptOnErrorOutput, false)) { if (shouldWriteJournal) { journal.AddJournalEntry(new JournalEntry(deployment, false)); } return(-1); } if (shouldWriteJournal) { journal.AddJournalEntry(new JournalEntry(deployment, true)); } return(result.ExitCode); }
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); }
void ImportCertificate(CalamariVariableDictionary variables) { var certificateVariable = GetMandatoryVariable(variables, SpecialVariables.Action.Certificate.CertificateVariable); var pfxBytes = Convert.FromBase64String(GetMandatoryVariable(variables, $"{certificateVariable}.{SpecialVariables.Certificate.Properties.Pfx}")); var password = variables.Get($"{certificateVariable}.{SpecialVariables.Certificate.Properties.Password}"); var thumbprint = variables.Get($"{certificateVariable}.{SpecialVariables.Certificate.Properties.Thumbprint}"); var storeName = GetMandatoryVariable(variables, SpecialVariables.Action.Certificate.StoreName); var privateKeyExportable = variables.GetFlag(SpecialVariables.Action.Certificate.PrivateKeyExportable, false); // Either a store-location (LocalMachine or CurrentUser) or a user can be supplied StoreLocation storeLocation; var locationSpecified = Enum.TryParse(variables.Get(SpecialVariables.Action.Certificate.StoreLocation), out storeLocation); ValidateStore(locationSpecified ? (StoreLocation?)storeLocation : null, storeName); try { if (locationSpecified) { Log.Info( $"Importing certificate '{variables.Get($"{certificateVariable}.{SpecialVariables.Certificate.Properties.Subject}")}' with thumbprint '{thumbprint}' into store '{storeLocation}\\{storeName}'"); WindowsX509CertificateStore.ImportCertificateToStore(pfxBytes, password, storeLocation, storeName, privateKeyExportable); if (storeLocation == StoreLocation.LocalMachine) { // Set private-key access var privateKeyAccessRules = GetPrivateKeyAccessRules(variables); if (privateKeyAccessRules.Any()) { WindowsX509CertificateStore.AddPrivateKeyAccessRules(thumbprint, storeLocation, storeName, privateKeyAccessRules); } } } else // Import into a specific user's store { var storeUser = variables.Get(SpecialVariables.Action.Certificate.StoreUser); if (string.IsNullOrWhiteSpace(storeUser)) { throw new CommandException( $"Either '{SpecialVariables.Action.Certificate.StoreLocation}' or '{SpecialVariables.Action.Certificate.StoreUser}' must be supplied"); } Log.Info( $"Importing certificate '{variables.Get($"{certificateVariable}.{SpecialVariables.Certificate.Properties.Subject}")}' with thumbprint '{thumbprint}' into store '{storeName}' for user '{storeUser}'"); WindowsX509CertificateStore.ImportCertificateToStore(pfxBytes, password, storeUser, storeName, privateKeyExportable); } } catch (Exception) { Log.Error("There was an error importing the certificate into the store"); throw; } }
public override int Execute(string[] commandLineArguments) { Options.Parse(commandLineArguments); var fileSystem = CalamariPhysicalFileSystem.GetPhysicalFileSystem(); var variables = new CalamariVariableDictionary(variablesFile, sensitiveVariablesFile, sensitiveVariablesPassword); if (!string.IsNullOrEmpty(packageFile)) { 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 substituter = new FileSubstituter(fileSystem); var packageExtractor = new GenericPackageExtractorFactory().createStandardGenericPackageExtractor(); var additionalFileSubstitution = variables.Get(TerraformSpecialVariables.Action.Terraform.FileSubstitution); var runAutomaticFileSubstitution = variables.GetFlag(TerraformSpecialVariables.Action.Terraform.RunAutomaticFileSubstitution, true); var enableNoMatchWarning = variables.Get(SpecialVariables.Package.EnableNoMatchWarning); variables.Add(SpecialVariables.Package.EnableNoMatchWarning, !String.IsNullOrEmpty(enableNoMatchWarning) ? enableNoMatchWarning : (!String.IsNullOrEmpty(additionalFileSubstitution)).ToString()); var conventions = new List <IConvention> { new ContributeEnvironmentVariablesConvention(), new LogVariablesConvention(), new ExtractPackageToStagingDirectoryConvention(packageExtractor, fileSystem).When(_ => packageFile != null), new SubstituteInFilesConvention(fileSystem, substituter, _ => true, _ => FileTargetFactory(runAutomaticFileSubstitution ? DefaultTerraformFileSubstitution : string.Empty, additionalFileSubstitution)), step(fileSystem) }; 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); var fileSystem = CalamariPhysicalFileSystem.GetPhysicalFileSystem(); var variables = new CalamariVariableDictionary(variablesFile, sensitiveVariablesFile, sensitiveVariablesPassword); 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 environment = AwsEnvironmentGeneration.Create(variables).GetAwaiter().GetResult(); var substituter = new FileSubstituter(fileSystem); var targetType = GetTargetMode(targetMode); var packageExtractor = new GenericPackageExtractorFactory().createStandardGenericPackageExtractor(); var conventions = new List <IConvention> { new ContributeEnvironmentVariablesConvention(), new LogVariablesConvention(), new ExtractPackageToStagingDirectoryConvention(packageExtractor, fileSystem).When(_ => targetType == S3TargetMode.FileSelections), new LogAwsUserInfoConvention(environment), new CreateS3BucketConvention(environment, _ => bucket), new UploadAwsS3Convention( fileSystem, environment, bucket, targetType, new VariableS3TargetOptionsProvider(variables), substituter ) }; var deployment = new RunningDeployment(packageFile, variables); var conventionRunner = new ConventionProcessor(deployment, conventions); conventionRunner.RunConventions(); return(0); }
private int InvokeScript(CalamariVariableDictionary variables) { var validatedScriptFilePath = AssertScriptFileExists(); var scriptEngine = new CombinedScriptEngine(); var runner = new CommandLineRunner( new SplitCommandOutput(new ConsoleCommandOutput(), new ServiceMessageCommandOutput(variables))); Log.VerboseFormat("Executing '{0}'", validatedScriptFilePath); var result = scriptEngine.Execute(new Script(validatedScriptFilePath, scriptParameters), variables, runner); if (result.ExitCode == 0 && result.HasErrors && variables.GetFlag(SpecialVariables.Action.FailScriptOnErrorOutput, false)) { return(-1); } return(result.ExitCode); }
public override int Execute(string[] commandLineArguments) { Options.Parse(commandLineArguments); variables.EnrichWithEnvironmentVariables(); variables.LogVariables(); var runner = new CommandLineRunner(new ConsoleCommandOutput()); Log.VerboseFormat("Executing '{0}'", scriptFile); var result = scriptEngine.Execute(new Script(scriptFile, ""), variables, runner); if (result.ExitCode == 0 && result.HasErrors && variables.GetFlag(SpecialVariables.Action.FailScriptOnErrorOutput, false)) { return(-1); } return(result.ExitCode); }
public override int Execute(string[] commandLineArguments) { Options.Parse(commandLineArguments); var fileSystem = CalamariPhysicalFileSystem.GetPhysicalFileSystem(); var commandLineRunner = new CommandLineRunner(new SplitCommandOutput(new ConsoleCommandOutput(), new ServiceMessageCommandOutput(variables))); fileSubstituter = new FileSubstituter(fileSystem); var configurationTransformer = ConfigurationTransformer.FromVariables(variables); var transformFileLocator = new TransformFileLocator(fileSystem); var replacer = new ConfigurationVariablesReplacer(variables.GetFlag(SpecialVariables.Package.IgnoreVariableReplacementErrors)); var jsonVariableReplacer = new JsonConfigurationVariableReplacer(); var extractor = new GenericPackageExtractorFactory().createStandardGenericPackageExtractor(); ValidateArguments(); WriteVariableScriptToFile(); var conventions = new List <IConvention> { new ContributeEnvironmentVariablesConvention(), new ContributeVariablesFromJsonFileConvention(), new LogVariablesConvention(), new StageScriptPackagesConvention(packageFile, fileSystem, extractor), // Substitute the script source file new SubstituteInFilesConvention(fileSystem, fileSubstituter, _ => true, ScriptFileTargetFactory), // Substitute any user-specified files new SubstituteInFilesConvention(fileSystem, fileSubstituter), new ConfigurationTransformsConvention(fileSystem, configurationTransformer, transformFileLocator), new ConfigurationVariablesConvention(fileSystem, replacer), new JsonConfigurationVariablesConvention(jsonVariableReplacer, fileSystem), new ExecuteScriptConvention(scriptEngine, commandLineRunner) }; var deployment = new RunningDeployment(packageFile, variables); var conventionRunner = new ConventionProcessor(deployment, conventions); conventionRunner.RunConventions(); var exitCode = variables.GetInt32(SpecialVariables.Action.Script.ExitCode); deploymentJournalWriter.AddJournalEntry(deployment, exitCode == 0, packageFile); return(exitCode.Value); }
private int InvokeScript(string scriptFileName, CalamariVariableDictionary variables) { // Any additional files extracted from the packages or sent by the action handler are processed here SubstituteVariablesInAdditionalFiles(); var scriptParameters = variables.Get(SpecialVariables.Action.Script.ScriptParameters); if (WasProvided(scriptParametersArg) && WasProvided(scriptParameters)) { Log.Warn($"The `--scriptParameters` parameter and `{SpecialVariables.Action.Script.ScriptParameters}` variable are both set.\r\n" + $"Please provide just the `{SpecialVariables.Action.Script.ScriptParameters}` variable instead."); } var runner = new CommandLineRunner(new SplitCommandOutput(new ConsoleCommandOutput(), new ServiceMessageCommandOutput(variables))); Log.VerboseFormat("Executing '{0}'", scriptFileName); var result = scriptEngine.Execute(new Script(scriptFileName, scriptParametersArg ?? scriptParameters), variables, runner); var shouldWriteJournal = CanWriteJournal(variables) && deployment != null && !deployment.SkipJournal; if (result.ExitCode == 0 && result.HasErrors && variables.GetFlag(SpecialVariables.Action.FailScriptOnErrorOutput, false)) { if (shouldWriteJournal) { journal.AddJournalEntry(new JournalEntry(deployment, false)); } return(-1); } if (shouldWriteJournal) { journal.AddJournalEntry(new JournalEntry(deployment, true)); } return(result.ExitCode); }
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); var scriptCapability = new CombinedScriptEngine(); var replacer = new ConfigurationVariablesReplacer(variables.GetFlag(SpecialVariables.Package.IgnoreVariableReplacementErrors)); var generator = new AppSettingsJsonGenerator(); var substituter = new FileSubstituter(fileSystem); var configurationTransformer = new ConfigurationTransformer(variables.GetFlag(SpecialVariables.Package.IgnoreConfigTransformationErrors), variables.GetFlag(SpecialVariables.Package.SuppressConfigTransformationLogging)); var embeddedResources = new CallingAssemblyEmbeddedResources(); var iis = new InternetInformationServer(); var commandLineRunner = new CommandLineRunner(new SplitCommandOutput(new ConsoleCommandOutput(), new ServiceMessageCommandOutput(variables))); var semaphore = new SystemSemaphore(); var journal = new DeploymentJournal(fileSystem, semaphore, variables); var conventions = new List <IConvention> { new ContributeEnvironmentVariablesConvention(), new ContributePreviousInstallationConvention(journal), new LogVariablesConvention(), new AlreadyInstalledConvention(journal), new ExtractPackageToApplicationDirectoryConvention(new LightweightPackageExtractor(), fileSystem, semaphore), new FeatureScriptConvention(DeploymentStages.BeforePreDeploy, fileSystem, embeddedResources, scriptCapability, commandLineRunner), new ConfiguredScriptConvention(DeploymentStages.PreDeploy, scriptCapability, fileSystem, commandLineRunner), new PackagedScriptConvention(DeploymentStages.PreDeploy, fileSystem, scriptCapability, commandLineRunner), new FeatureScriptConvention(DeploymentStages.AfterPreDeploy, fileSystem, embeddedResources, scriptCapability, commandLineRunner), new SubstituteInFilesConvention(fileSystem, substituter), new ConfigurationTransformsConvention(fileSystem, configurationTransformer), new ConfigurationVariablesConvention(fileSystem, replacer), new AppSettingsJsonConvention(generator), new CopyPackageToCustomInstallationDirectoryConvention(fileSystem), new FeatureScriptConvention(DeploymentStages.BeforeDeploy, fileSystem, embeddedResources, scriptCapability, commandLineRunner), new PackagedScriptConvention(DeploymentStages.Deploy, fileSystem, scriptCapability, commandLineRunner), new ConfiguredScriptConvention(DeploymentStages.Deploy, scriptCapability, fileSystem, commandLineRunner), new FeatureScriptConvention(DeploymentStages.AfterDeploy, fileSystem, embeddedResources, scriptCapability, commandLineRunner), new LegacyIisWebSiteConvention(fileSystem, iis), new FeatureScriptConvention(DeploymentStages.BeforePostDeploy, fileSystem, embeddedResources, scriptCapability, commandLineRunner), new PackagedScriptConvention(DeploymentStages.PostDeploy, fileSystem, scriptCapability, commandLineRunner), new ConfiguredScriptConvention(DeploymentStages.PostDeploy, scriptCapability, fileSystem, commandLineRunner), new FeatureScriptConvention(DeploymentStages.AfterPostDeploy, fileSystem, embeddedResources, scriptCapability, commandLineRunner), new RollbackScriptConvention(DeploymentStages.DeployFailed, fileSystem, scriptCapability, 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); }
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); }
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); if (!ServiceFabricHelper.IsServiceFabricSdkKeyInRegistry()) { throw new CommandException("Could not find the Azure Service Fabric SDK on this server. This SDK is required before running Service Fabric commands."); } 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 replacer = new ConfigurationVariablesReplacer(variables.GetFlag(SpecialVariables.Package.IgnoreVariableReplacementErrors)); var jsonReplacer = new JsonConfigurationVariableReplacer(); var substituter = new FileSubstituter(fileSystem); var commandLineRunner = new CommandLineRunner(new SplitCommandOutput(new ConsoleCommandOutput(), new ServiceMessageCommandOutput(variables))); var configurationTransformer = ConfigurationTransformer.FromVariables(variables); var transformFileLocator = new TransformFileLocator(fileSystem); var conventions = new List <IConvention> { new ContributeEnvironmentVariablesConvention(), new LogVariablesConvention(), new ExtractPackageToStagingDirectoryConvention(new GenericPackageExtractorFactory().createStandardGenericPackageExtractor(), fileSystem), // PreDeploy stage new ConfiguredScriptConvention(DeploymentStages.PreDeploy, fileSystem, scriptEngine, commandLineRunner), new PackagedScriptConvention(DeploymentStages.PreDeploy, fileSystem, scriptEngine, commandLineRunner), // Standard variable and transform replacements new SubstituteInFilesConvention(fileSystem, substituter), new ConfigurationTransformsConvention(fileSystem, configurationTransformer, transformFileLocator), new ConfigurationVariablesConvention(fileSystem, replacer), new JsonConfigurationVariablesConvention(jsonReplacer, fileSystem), // Deploy stage new PackagedScriptConvention(DeploymentStages.Deploy, fileSystem, scriptEngine, commandLineRunner), new ConfiguredScriptConvention(DeploymentStages.Deploy, fileSystem, scriptEngine, commandLineRunner), // Variable replacement new SubstituteVariablesInAzureServiceFabricPackageConvention(fileSystem, substituter), // Main Service Fabric deployment script execution new EnsureCertificateInstalledInStoreConvention(certificateStore, SpecialVariables.Action.ServiceFabric.ClientCertVariable, SpecialVariables.Action.ServiceFabric.CertificateStoreLocation, SpecialVariables.Action.ServiceFabric.CertificateStoreName), new DeployAzureServiceFabricAppConvention(fileSystem, embeddedResources, scriptEngine, commandLineRunner), // PostDeploy stage 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); }