public void Install(RunningDeployment deployment) { Log.Info("Config file: " + deployment.Variables.Get(SpecialVariables.Action.Azure.Output.ConfigurationFile)); Log.SetOutputVariable("OctopusAzureServiceName", deployment.Variables.Get(SpecialVariables.Action.Azure.CloudServiceName), deployment.Variables); Log.SetOutputVariable("OctopusAzureStorageAccountName", deployment.Variables.Get(SpecialVariables.Action.Azure.StorageAccountName), deployment.Variables); Log.SetOutputVariable("OctopusAzureSlot", deployment.Variables.Get(SpecialVariables.Action.Azure.Slot), deployment.Variables); Log.SetOutputVariable("OctopusAzurePackageUri", deployment.Variables.Get(SpecialVariables.Action.Azure.UploadedPackageUri), deployment.Variables); Log.SetOutputVariable("OctopusAzureDeploymentLabel", deployment.Variables.Get(SpecialVariables.Action.Name) + " v" + deployment.Variables.Get(SpecialVariables.Release.Number), deployment.Variables); Log.SetOutputVariable("OctopusAzureSwapIfPossible", deployment.Variables.Get(SpecialVariables.Action.Azure.SwapIfPossible, defaultValue: false.ToString()), deployment.Variables); Log.SetOutputVariable("OctopusAzureUseCurrentInstanceCount", deployment.Variables.Get(SpecialVariables.Action.Azure.UseCurrentInstanceCount), deployment.Variables); // The script name 'DeployToAzure.ps1' is used for backwards-compatibility var scriptFile = Path.Combine(deployment.CurrentDirectory, "DeployToAzure.ps1"); // The user may supply the script, to override behaviour if (!fileSystem.FileExists(scriptFile)) { fileSystem.OverwriteFile(scriptFile, embeddedResources.GetEmbeddedResourceText("Calamari.Azure.Scripts.DeployAzureCloudService.ps1")); } var result = scriptEngine.Execute(scriptFile, deployment.Variables, commandLineRunner); fileSystem.DeleteFile(scriptFile, FailureOptions.IgnoreFailure); if (result.ExitCode != 0) { throw new CommandException(string.Format("Script '{0}' returned non-zero exit code: {1}", scriptFile, result.ExitCode)); } }
public void Install(RunningDeployment deployment) { var subscriptionId = variables.Get(SpecialVariables.Action.Azure.SubscriptionId); var certificate = Convert.FromBase64String(variables.Get(SpecialVariables.Action.Azure.CertificateBytes)); var webAppName = variables.Get(SpecialVariables.Action.Azure.WebAppName); Log.Info("Deploying to Azure WebApp '{0}' using subscription-id '{1}'", webAppName, subscriptionId); var cloudClient = CloudContext.Clients.CreateWebSiteManagementClient( new CertificateCloudCredentials(subscriptionId, new X509Certificate2(certificate))); var webApp = cloudClient.WebSpaces.List() .SelectMany(webSpace => cloudClient.WebSpaces.ListWebSites(webSpace.Name, new WebSiteListParameters {})) .FirstOrDefault(webSite => webSite.Name.Equals(webAppName, StringComparison.OrdinalIgnoreCase)); if (webApp == null) { throw new CommandException(string.Format("Could not find Azure Web App '{0}' in subscription '{1}'", webAppName, subscriptionId)); } var publishProfile = cloudClient.WebSites.GetPublishProfile(webApp.WebSpace, webAppName) .PublishProfiles.First(x => x.PublishMethod.StartsWith("MSDeploy")); var changeSummary = DeploymentManager .CreateObject("contentPath", deployment.CurrentDirectory) .SyncTo("contentPath", BuildPath(publishProfile.MSDeploySite, variables), DeploymentOptions(publishProfile), DeploymentSyncOptions(variables) ); Log.Info("Successfully deployed to Azure. {0} objects added. {1} objects updated. {2} objects deleted.", changeSummary.ObjectsAdded, changeSummary.ObjectsUpdated, changeSummary.ObjectsDeleted); }
public override int Execute(string[] commandLineArguments) { Options.Parse(commandLineArguments); Guard.NotNullOrWhiteSpace(packageFile, "No package file was specified. Please pass -cspkg YourPackage.cspkg"); if (!File.Exists(packageFile)) throw new CommandException("Could not find package file: " + packageFile); var variables = new VariableDictionary(); variables.Set(SpecialVariables.Action.Azure.CloudServicePackagePath, packageFile); variables.Set(SpecialVariables.OriginalPackageDirectoryPath, !string.IsNullOrWhiteSpace(destinationDirectory) ? destinationDirectory : Path.GetDirectoryName(packageFile)); var fileSystem = new WindowsPhysicalFileSystem(); var conventions = new List<IConvention> { new EnsureCloudServicePackageIsCtpFormatConvention(fileSystem), new ExtractAzureCloudServicePackageConvention(fileSystem), }; var deployment = new RunningDeployment(packageFile, variables); var conventionRunner = new ConventionProcessor(deployment, conventions); conventionRunner.RunConventions(); return 0; }
public void Install(RunningDeployment deployment) { Log.SetOutputVariable("OctopusAzureServiceName", deployment.Variables.Get(SpecialVariables.Action.Azure.CloudServiceName), deployment.Variables); Log.SetOutputVariable("OctopusAzureStorageAccountName", deployment.Variables.Get(SpecialVariables.Action.Azure.StorageAccountName), deployment.Variables); Log.SetOutputVariable("OctopusAzureSlot", deployment.Variables.Get(SpecialVariables.Action.Azure.Slot), deployment.Variables); Log.SetOutputVariable("OctopusAzureDeploymentLabel", deployment.Variables.Get(SpecialVariables.Action.Name) + " v" + deployment.Variables.Get(SpecialVariables.Release.Number), deployment.Variables); Log.SetOutputVariable("OctopusAzureSwapIfPossible", deployment.Variables.Get(SpecialVariables.Action.Azure.SwapIfPossible, defaultValue: false.ToString()), deployment.Variables); var tempDirectory = fileSystem.CreateTemporaryDirectory(); var scriptFile = Path.Combine(tempDirectory, "SwapAzureCloudServiceDeployment.ps1"); // The user may supply the script, to override behaviour if (!fileSystem.FileExists(scriptFile)) { fileSystem.OverwriteFile(scriptFile, embeddedResources.GetEmbeddedResourceText("Calamari.Azure.Scripts.SwapAzureCloudServiceDeployment.ps1")); } var result = scriptEngine.Execute(scriptFile, deployment.Variables, commandLineRunner); fileSystem.DeleteDirectory(tempDirectory, FailureOptions.IgnoreFailure); if (result.ExitCode != 0) { throw new CommandException($"Script '{scriptFile}' returned non-zero exit code: {result.ExitCode}"); } var swapped = deployment.Variables.GetFlag(SpecialVariables.Action.Azure.Output.CloudServiceDeploymentSwapped); if (swapped) { deployment.Variables.Set(SpecialVariables.Action.SkipRemainingConventions, "true"); } }
public void Install(RunningDeployment deployment) { if (deployment.Variables.GetFlag(SpecialVariables.Action.Azure.CloudServicePackageExtractionDisabled, false)) return; Log.Verbose("Re-packaging cspkg."); var workingDirectory = deployment.CurrentDirectory; var originalPackagePath = deployment.Variables.Get(SpecialVariables.Action.Azure.CloudServicePackagePath); var newPackagePath = Path.Combine(Path.GetDirectoryName(originalPackagePath), Path.GetFileNameWithoutExtension(originalPackagePath) + "_repacked.cspkg"); using (var originalPackage = Package.Open(originalPackagePath, FileMode.Open)) using (var newPackage = Package.Open(newPackagePath, FileMode.CreateNew)) { var originalManifest = AzureCloudServiceConventions.ReadPackageManifest(originalPackage); var newManifest = new PackageDefinition { MetaData = {AzureVersion = originalManifest.MetaData.AzureVersion} }; AddParts(newPackage, newManifest, Path.Combine(workingDirectory, AzureCloudServiceConventions.PackageFolders.ServiceDefinition), AzureCloudServiceConventions.PackageFolders.ServiceDefinition); AddParts(newPackage, newManifest, Path.Combine(workingDirectory, AzureCloudServiceConventions.PackageFolders.NamedStreams), AzureCloudServiceConventions.PackageFolders.NamedStreams); AddLocalContent(newPackage, newManifest, workingDirectory); AddPackageManifest(newPackage, newManifest); newPackage.Flush(); } fileSystem.OverwriteAndDelete(originalPackagePath, newPackagePath); }
public void SetUp() { variables = new CalamariVariableDictionary(); variables.Set(SpecialVariables.OriginalPackageDirectoryPath, stagingDirectory); fileSystem = Substitute.For<ICalamariFileSystem>(); deployment = new RunningDeployment(packageFilePath, variables); }
protected void DeleteScripts(RunningDeployment deployment) { var scripts = FindScripts(deployment); foreach (var script in scripts) { fileSystem.DeleteFile(script, FailureOptions.IgnoreFailure); } }
public void SetUp() { fileSystem = Substitute.For<ICalamariFileSystem>(); variables = new VariableDictionary(); variables.Set(SpecialVariables.OriginalPackageDirectoryPath, StagingDirectory); deployment = new RunningDeployment(StagingDirectory, variables); convention = new ChooseCloudServiceConfigurationFileConvention(fileSystem); }
string ChooseWhichConfigurationFileToUse(RunningDeployment deployment) { var configurationFilePath = GetFirstExistingFile(deployment, deployment.Variables.Get(SpecialVariables.Action.Azure.CloudServiceConfigurationFileRelativePath), BuildEnvironmentSpecificFallbackFileName(deployment), FallbackFileName); return configurationFilePath; }
IEnumerable<string> FindScripts(RunningDeployment deployment) { var supportedScriptExtensions = scriptEngine.GetSupportedExtensions(); var searchPatterns = supportedScriptExtensions.Select(e => "*." + e).ToArray(); return from file in fileSystem.EnumerateFiles(deployment.CurrentDirectory, searchPatterns) let nameWithoutExtension = Path.GetFileNameWithoutExtension(file) where nameWithoutExtension.Equals(scriptFilePrefix, StringComparison.OrdinalIgnoreCase) select file; }
public void SetUp() { variables = new VariableDictionary(); fileSystem = Substitute.For<ICalamariFileSystem>(); iis = Substitute.For<IInternetInformationServer>(); deployment = new RunningDeployment("C:\\packages", variables) { StagingDirectory = stagingDirectory }; }
public void SetUp() { fileSystem = Substitute.For<ICalamariFileSystem>(); configurationTransformer = Substitute.For<IConfigurationTransformer>(); variables = new CalamariVariableDictionary(); variables.Set(SpecialVariables.OriginalPackageDirectoryPath, stagingDirectory); deployment = new RunningDeployment("C:\\packages", variables); }
public void SetUp() { fileSystem = Substitute.For<ICalamariFileSystem>(); substituter = Substitute.For<IFileSubstituter>(); variables = new VariableDictionary(); deployment = new RunningDeployment(TestEnvironment.ConstructRootedPath("packages"), variables) { StagingDirectory = StagingDirectory }; }
public void SetUp() { fileSystem = new WindowsPhysicalFileSystem(); configurationTransformer = Substitute.For<IConfigurationTransformer>(); var deployDirectory = BuildConfigPath(null); variables = new CalamariVariableDictionary(); variables.Set(SpecialVariables.OriginalPackageDirectoryPath, deployDirectory); deployment = new RunningDeployment(deployDirectory, variables); }
public void Install(RunningDeployment deployment) { // Validate we actually have a real path to the real config file since this value is potentially passed via variable or a previous convention var configurationFilePath = deployment.Variables.Get(SpecialVariables.Action.Azure.Output.ConfigurationFile); if (!fileSystem.FileExists(configurationFilePath)) throw new CommandException("Could not find the Azure Cloud Service Configuration file: " + configurationFilePath); var configuration = XDocument.Parse(fileSystem.ReadFile(configurationFilePath)); UpdateConfigurationWithCurrentInstanceCount(configuration, configurationFilePath, deployment.Variables); UpdateConfigurationSettings(configuration, deployment.Variables); SaveConfigurationFile(configuration, configurationFilePath); }
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(), 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 void SetUp() { fileSystem = Substitute.For<ICalamariFileSystem>(); fileSystem.EnumerateFilesRecursively(Arg.Any<string>(), Arg.Any<string[]>()).Returns(new[] { "C:\\App\\MyApp\\Web.config", "C:\\App\\MyApp\\Web.Release.config", "C:\\App\\MyApp\\Views\\Web.config" }); deployment = new RunningDeployment("C:\\Packages", new CalamariVariableDictionary()); replacer = Substitute.For<IConfigurationVariablesReplacer>(); }
protected void RunScripts(RunningDeployment deployment) { var scripts = FindScripts(deployment); foreach (var script in scripts) { var result = scriptEngine.Execute(script, deployment.Variables, commandLineRunner); if (result.ExitCode != 0) { throw new CommandException(string.Format("Script '{0}' returned non-zero exit code: {1}. Deployment terminated.", script, result.ExitCode)); } } }
public void SetUp() { fileSystem = Substitute.For<ICalamariFileSystem>(); scriptEngine = Substitute.For<IScriptEngine>(); commandLineRunner = Substitute.For<ICommandLineRunner>(); scriptEngine.GetSupportedExtensions().Returns(new string[] { "ps1" }); variables = new VariableDictionary(); variables.Set(SpecialVariables.Package.EnabledFeatures, SpecialVariables.Features.CustomScripts); deployment = new RunningDeployment("C:\\packages", variables) { StagingDirectory = stagingDirectory }; }
public void SetUp() { fileSystem = Substitute.For<ICalamariFileSystem>(); fileSystem.EnumerateFiles(Arg.Any<string>(), Arg.Any<string[]>()).Returns(new[] { TestEnvironment.ConstructRootedPath("App", "MyApp", "Hello.ps1"), TestEnvironment.ConstructRootedPath("App", "MyApp", "Deploy.ps1"), TestEnvironment.ConstructRootedPath("App", "MyApp", "Deploy.csx"), TestEnvironment.ConstructRootedPath("App", "MyApp", "PreDeploy.ps1") }); commandResult = new CommandResult("PowerShell.exe foo bar", 0, null); scriptEngine = Substitute.For<IScriptEngine>(); scriptEngine.Execute(Arg.Any<string>(), Arg.Any<CalamariVariableDictionary>(), Arg.Any<ICommandLineRunner>()).Returns(c => commandResult); scriptEngine.GetSupportedExtensions().Returns(new[] {"csx", "ps1"}); runner = Substitute.For<ICommandLineRunner>(); deployment = new RunningDeployment(TestEnvironment.ConstructRootedPath("Packages"), new CalamariVariableDictionary()); }
public void SetUp() { fileSystem = Substitute.For<ICalamariFileSystem>(); packageUploader = Substitute.For<IAzurePackageUploader>(); credentialsFactory = Substitute.For<ISubscriptionCloudCredentialsFactory>(); credentialsFactory.GetCredentials(azureSubscriptionId, certificateThumbprint, certificateBytes) .Returns(new FakeSubscriptionCloudCredentials(azureSubscriptionId)); variables = new VariableDictionary(); variables.Set(SpecialVariables.OriginalPackageDirectoryPath, stagingDirectory); variables.Set(SpecialVariables.Action.Azure.SubscriptionId, azureSubscriptionId); variables.Set(SpecialVariables.Action.Azure.CertificateThumbprint, certificateThumbprint); variables.Set(SpecialVariables.Action.Azure.CertificateBytes, certificateBytes); variables.Set(SpecialVariables.Action.Azure.StorageAccountName, storageAccountName); deployment = new RunningDeployment(stagingDirectory, variables); convention = new UploadAzureCloudServicePackageConvention(fileSystem, packageUploader, credentialsFactory); }
string GetFirstExistingFile(RunningDeployment deployment, params string[] fileNames) { foreach (var name in fileNames) { if (string.IsNullOrWhiteSpace(name)) continue; var path = Path.Combine(deployment.CurrentDirectory, name); if (fileSystem.FileExists(path)) { Log.Verbose("Found Azure Cloud Service Configuration file: " + path); return path; } Log.Verbose("Azure Cloud Service Configuration file (*.cscfg) not found: " + path); } throw new CommandException( "Could not find an Azure Cloud Service Configuration file (*.cscfg) in the package."); }
public void Install(RunningDeployment deployment) { if (deployment.Variables.GetFlag(SpecialVariables.Action.Azure.CloudServicePackageExtractionDisabled, false)) return; var packagePath = deployment.Variables.Get(SpecialVariables.Action.Azure.CloudServicePackagePath); Log.VerboseFormat("Extracting Cloud Service package: '{0}'", packagePath); using (var package = Package.Open(packagePath, FileMode.Open)) { var manifest = AzureCloudServiceConventions.ReadPackageManifest(package); var workingDirectory = deployment.CurrentDirectory; ExtractContents(package, manifest, AzureCloudServiceConventions.PackageFolders.ServiceDefinition, workingDirectory); ExtractContents(package, manifest, AzureCloudServiceConventions.PackageFolders.NamedStreams, workingDirectory); ExtractLayouts(package, manifest, workingDirectory); } if (deployment.Variables.GetFlag(SpecialVariables.Action.Azure.LogExtractedCspkg)) LogExtractedPackage(deployment.CurrentDirectory); }
public void Install(RunningDeployment deployment) { var package = deployment.Variables.Get(SpecialVariables.Action.Azure.CloudServicePackagePath); Log.Info("Uploading package to Azure blob storage: '{0}'", package); var packageHash = Hash(package); var nugetPackageVersion = deployment.Variables.Get(SpecialVariables.Package.NuGetPackageVersion); var uploadedFileName = Path.ChangeExtension(Path.GetFileName(package), "." + nugetPackageVersion + "_" + packageHash + ".cspkg"); var credentials = credentialsFactory.GetCredentials( deployment.Variables.Get(SpecialVariables.Action.Azure.SubscriptionId), deployment.Variables.Get(SpecialVariables.Action.Azure.CertificateThumbprint), deployment.Variables.Get(SpecialVariables.Action.Azure.CertificateBytes) ); var storageAccountName = deployment.Variables.Get(SpecialVariables.Action.Azure.StorageAccountName); var uploadedUri = azurePackageUploader.Upload(credentials, storageAccountName, package, uploadedFileName); Log.SetOutputVariable(SpecialVariables.Action.Azure.UploadedPackageUri, uploadedUri.ToString(), deployment.Variables); Log.Info("Package uploaded to " + uploadedUri.ToString()); }
public void ShouldReturnCorrectDirectories() { var deployment = new RunningDeployment("C:\\Package.nupkg", new CalamariVariableDictionary()); // When no custom installation directory is chosen, custom points to staging deployment.Variables.Set(SpecialVariables.OriginalPackageDirectoryPath, "C:\\Apps\\MyPackage\\1.0.0_1"); Assert.That(deployment.StagingDirectory, Is.EqualTo("C:\\Apps\\MyPackage\\1.0.0_1")); Assert.That(deployment.CustomDirectory, Is.EqualTo("C:\\Apps\\MyPackage\\1.0.0_1")); Assert.That(deployment.CurrentDirectory, Is.EqualTo("C:\\Apps\\MyPackage\\1.0.0_1")); // Custom installation directory is always available, but the staging directory points to current deployment.Variables.Set(SpecialVariables.Package.CustomInstallationDirectory, "C:\\MyWebsite"); Assert.That(deployment.StagingDirectory, Is.EqualTo("C:\\Apps\\MyPackage\\1.0.0_1")); Assert.That(deployment.CustomDirectory, Is.EqualTo("C:\\MyWebsite")); Assert.That(deployment.CurrentDirectory, Is.EqualTo("C:\\Apps\\MyPackage\\1.0.0_1")); // After the package contents is copied to the custom installation directory, the current directory changes deployment.CurrentDirectoryProvider = DeploymentWorkingDirectory.CustomDirectory; Assert.That(deployment.StagingDirectory, Is.EqualTo("C:\\Apps\\MyPackage\\1.0.0_1")); Assert.That(deployment.CustomDirectory, Is.EqualTo("C:\\MyWebsite")); Assert.That(deployment.CurrentDirectory, Is.EqualTo("C:\\MyWebsite")); }
public void SetUp() { result = null; fileSystem = Substitute.For<ICalamariFileSystem>(); credentialsFactory = Substitute.For<ISubscriptionCloudCredentialsFactory>(); configurationRetriever = Substitute.For<IAzureCloudServiceConfigurationRetriever>(); variables = new CalamariVariableDictionary(); variables.Set(SpecialVariables.OriginalPackageDirectoryPath, StagingDirectory); deployment = new RunningDeployment(StagingDirectory, variables); variables.Set(SpecialVariables.Action.Azure.SubscriptionId, AzureSubscriptionId); variables.Set(SpecialVariables.Action.Azure.CertificateThumbprint, CertificateThumbprint); variables.Set(SpecialVariables.Action.Azure.CertificateBytes, CertificateBytes); variables.Set(SpecialVariables.Action.Azure.CloudServiceName, CloudServiceName); variables.Set(SpecialVariables.Action.Azure.Slot, DeploymentSlot.ToString()); credentialsFactory.GetCredentials(AzureSubscriptionId, CertificateThumbprint, CertificateBytes) .Returns(new FakeSubscriptionCloudCredentials(AzureSubscriptionId)); convention = new ConfigureAzureCloudServiceConvention(fileSystem, credentialsFactory, configurationRetriever); }
public void Install(RunningDeployment deployment) { if (deployment.Variables.GetFlag(SpecialVariables.Action.Azure.CloudServicePackageExtractionDisabled, false)) return; Log.VerboseFormat("Ensuring cloud-service-package is {0} format.", PackageFormats.V20120315.ToString()); var packagePath = deployment.Variables.Get(SpecialVariables.Action.Azure.CloudServicePackagePath); var packageFormat = PackageConverter.GetFormat(packagePath); switch (packageFormat) { case PackageFormats.Legacy: Log.VerboseFormat("Package is Legacy format. Converting to {0} format.", PackageFormats.V20120315.ToString()); ConvertPackage(packagePath); return; case PackageFormats.V20120315: Log.VerboseFormat("Package is {0} format.", PackageFormats.V20120315.ToString()); return; default: throw new InvalidOperationException("Unexpected PackageFormat: " + packageFormat); } }
public void Install(RunningDeployment deployment) { var variables = deployment.Variables; var subscriptionId = variables.Get(SpecialVariables.Action.Azure.SubscriptionId); var certificate = Convert.FromBase64String(variables.Get(SpecialVariables.Action.Azure.CertificateBytes)); var webAppName = variables.Get(SpecialVariables.Action.Azure.WebAppName); Log.Info("Deploying to Azure WebApp '{0}' using subscription-id '{1}'", webAppName, subscriptionId); var publishProfile = GetPublishProfile(subscriptionId, webAppName, certificate); var changeSummary = DeploymentManager .CreateObject("contentPath", deployment.CurrentDirectory) .SyncTo("contentPath", BuildPath(publishProfile.MSDeploySite, variables), DeploymentOptions(publishProfile), DeploymentSyncOptions(variables)); Log.Info("Successfully deployed to Azure. {0} objects added. {1} objects updated. {2} objects deleted.", changeSummary.ObjectsAdded, changeSummary.ObjectsUpdated, changeSummary.ObjectsDeleted); }
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 ConventionProcessor(RunningDeployment deployment, List <IConvention> conventions, ILog log) { this.deployment = deployment; this.conventions = conventions; this.log = 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); 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; }
public ConventionProcessor(RunningDeployment deployment, List <IConvention> conventions) { this.deployment = deployment; this.conventions = conventions; }