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); if (variablesFile != null) Log.Info("Using variables from: " + variablesFile); var variables = new VariableDictionary(variablesFile); var fileSystem = new WindowsPhysicalFileSystem(); var embeddedResources = new ExecutingAssemblyEmbeddedResources(); 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(); var configurationTransformer = new ConfigurationTransformer(variables.GetFlag(SpecialVariables.Package.IgnoreConfigTransformationErrors), variables.GetFlag(SpecialVariables.Package.SuppressConfigTransformationLogging)); var replacer = new ConfigurationVariablesReplacer(); var conventions = new List<IConvention> { new ContributeEnvironmentVariablesConvention(), new LogVariablesConvention(), new ExtractPackageToStagingDirectoryConvention(new LightweightPackageExtractor(), fileSystem), new FindCloudServicePackageConvention(fileSystem), new EnsureCloudServicePackageIsCtpFormatConvention(fileSystem), new ExtractAzureCloudServicePackageConvention(fileSystem), new ChooseCloudServiceConfigurationFileConvention(fileSystem), new ConfiguredScriptConvention(DeploymentStages.PreDeploy, scriptEngine, fileSystem, commandLineRunner), new PackagedScriptConvention(DeploymentStages.PreDeploy, fileSystem, scriptEngine, commandLineRunner), new ConfigureAzureCloudServiceConvention(fileSystem, cloudCredentialsFactory, cloudServiceConfigurationRetriever), new SubstituteInFilesConvention(fileSystem, substituter), new ConfigurationTransformsConvention(fileSystem, configurationTransformer), new ConfigurationVariablesConvention(fileSystem, replacer), new PackagedScriptConvention(DeploymentStages.Deploy, fileSystem, scriptEngine, commandLineRunner), new ConfiguredScriptConvention(DeploymentStages.Deploy, scriptEngine, fileSystem, commandLineRunner), new RePackageCloudServiceConvention(fileSystem), new UploadAzureCloudServicePackageConvention(fileSystem, azurePackageUploader, cloudCredentialsFactory), new DeployAzureCloudServicePackageConvention(fileSystem, embeddedResources, scriptEngine, commandLineRunner), 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; }
public CommandResult Execute() { var runner = new CommandLineRunner(new SplitCommandOutput(new ConsoleCommandOutput(), new ServiceMessageCommandOutput(new CalamariVariableDictionary()))); var result = runner.Execute(OctoDiff.Build()); return(result); }
private CalamariResult ExecuteScript(IScriptEngine psse, string scriptName, CalamariVariableDictionary variables) { var capture = new CaptureCommandOutput(); var runner = new CommandLineRunner(capture); var result = psse.Execute(scriptName, variables, runner); return new CalamariResult(result.ExitCode, capture); }
protected CalamariResult Invoke(CommandLine command, VariableDictionary variables) { var capture = new CaptureCommandOutput(); var runner = new CommandLineRunner(new SplitCommandOutput(new ConsoleCommandOutput(), new ServiceMessageCommandOutput(variables), capture)); var result = runner.Execute(command.Build()); return new CalamariResult(result.ExitCode, capture); }
private int InvokeScript(VariableDictionary variables) { if (!File.Exists(scriptFile)) throw new CommandException("Could not find script file: " + scriptFile); var scriptEngine = new CombinedScriptEngine(); var runner = new CommandLineRunner( new SplitCommandOutput(new ConsoleCommandOutput(), new ServiceMessageCommandOutput(variables))); var result = scriptEngine.Execute(scriptFile, variables, runner); return result.ExitCode; }
public override int Execute(string[] commandLineArguments) { Options.Parse(commandLineArguments); string deltaFilePath; string newFilePath; string basisFilePath; ValidateParameters(out basisFilePath, out deltaFilePath, out newFilePath); fileSystem.EnsureDiskHasEnoughFreeSpace(packageStore.GetPackagesDirectory()); var commandLineRunner = new CommandLineRunner(new SplitCommandOutput(new ConsoleCommandOutput(), new ServiceMessageCommandOutput(new CalamariVariableDictionary()))); var tempNewFilePath = newFilePath + ".partial"; var executable = FindOctoDiffExecutable(); var octoDiff = CommandLine.Execute(executable) .Action("patch") .PositionalArgument(basisFilePath) .PositionalArgument(deltaFilePath) .PositionalArgument(tempNewFilePath); if(skipVerification) octoDiff.Flag("skip-verification"); if(showProgress) octoDiff.Flag("progress"); Log.Info("Applying delta to {0} with hash {1} and storing as {2}", basisFilePath, fileHash, newFilePath); var result = commandLineRunner.Execute(octoDiff.Build()); if (result.ExitCode != 0) { fileSystem.DeleteFile(tempNewFilePath, FailureOptions.ThrowOnFailure); throw new CommandLineException(executable, result.ExitCode, result.Errors); } File.Move(tempNewFilePath, newFilePath); if (!File.Exists(newFilePath)) throw new CommandException("Failed to apply delta file " + deltaFilePath + " to " + basisFilePath); var package = packageStore.GetPackage(newFilePath); if (package == null) return 0; using (var file = new FileStream(package.FullPath, FileMode.Open, FileAccess.Read, FileShare.Read)) { var size = file.Length; Log.ServiceMessages.DeltaVerification(package.FullPath, package.Metadata.Hash, size); } 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 replacer = new ConfigurationVariablesReplacer(variables.GetFlag(SpecialVariables.Package.IgnoreVariableReplacementErrors)); var generator = new AppSettingsJsonGenerator(); 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 conventions = new List<IConvention> { new ContributeEnvironmentVariablesConvention(), new LogVariablesConvention(), new ExtractPackageToStagingDirectoryConvention(new LightweightPackageExtractor(), fileSystem), new ConfiguredScriptConvention(DeploymentStages.PreDeploy, scriptEngine, fileSystem, commandLineRunner), new PackagedScriptConvention(DeploymentStages.PreDeploy, fileSystem, scriptEngine, commandLineRunner), new SubstituteInFilesConvention(fileSystem, substituter), new ConfigurationTransformsConvention(fileSystem, configurationTransformer), new ConfigurationVariablesConvention(fileSystem, replacer), new AppSettingsJsonConvention(generator), new PackagedScriptConvention(DeploymentStages.Deploy, fileSystem, scriptEngine, commandLineRunner), new ConfiguredScriptConvention(DeploymentStages.Deploy, scriptEngine, fileSystem, commandLineRunner), new AzureWebAppConvention(variables), 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; }
public static string BuildSamplePackage(string name, string version, bool modifyPackage = false) { var nugetCommandLine = TestEnvironment.GetTestPath("NuGet", "NuGet.exe"); Assert.That(File.Exists(nugetCommandLine), string.Format("NuGet.exe is not available (expected at {0}).", nugetCommandLine)); var packageDirectory = TestEnvironment.GetTestPath("Fixtures", "Deployment", "Packages", name); Assert.That(Directory.Exists(packageDirectory), string.Format("Package {0} is not available (expected at {1}).", name, packageDirectory)); var nuspec = Path.Combine(packageDirectory, name + ".nuspec"); Assert.That(File.Exists(nuspec), string.Format("Nuspec for {0} is not available (expected at {1}.", name, nuspec)); var output = Path.GetTempPath(); var path = Path.Combine(output, name + "." + version + ".nupkg"); if (File.Exists(path)) File.Delete(path); string indexFilePath = null; if (modifyPackage) { indexFilePath = AddFileToPackage(packageDirectory); } var runner = new CommandLineRunner(new ConsoleCommandOutput()); var result = runner.Execute(CommandLine.Execute(nugetCommandLine) .Action("pack") .Argument(nuspec) .Flag("NoPackageAnalysis") .Argument("Version", version) .Argument("OutputDirectory", output) .Build()); result.VerifySuccess(); if (modifyPackage && !String.IsNullOrWhiteSpace(indexFilePath) && File.Exists(indexFilePath)) File.Delete(indexFilePath); Assert.That(File.Exists(path), string.Format("The generated nupkg was unable to be found (expected at {0}).", path)); return path; }
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 outputVariables = new VariableDictionary(outputVariablesFile); variables.MergeWith(outputVariables); var scriptCapability = new CombinedScriptEngine(); var replacer = new ConfigurationVariablesReplacer(variables.GetFlag(SpecialVariables.Package.IgnoreVariableReplacementErrors)); 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), new ServiceMessageCommandOutput(outputVariables))); 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 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), }; var deployment = new RunningDeployment(packageFile, variables); var conventionRunner = new ConventionProcessor(deployment, conventions); try { conventionRunner.RunConventions(); outputVariables.Save(); if (!deployment.SkipJournal) journal.AddJournalEntry(new JournalEntry(deployment, true)); } catch (Exception) { if (!deployment.SkipJournal) journal.AddJournalEntry(new JournalEntry(deployment, false)); throw; } return 0; }