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) { 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)); } }
string CreateContextScriptFile(string workingDirectory) { var azureContextScriptFile = Path.Combine(workingDirectory, "Octopus.AzureServiceFabricContext.ps1"); var contextScript = embeddedResources.GetEmbeddedResourceText(Assembly.GetExecutingAssembly(), "Calamari.Azure.Scripts.AzureServiceFabricContext.ps1"); fileSystem.OverwriteFile(azureContextScriptFile, contextScript); return(azureContextScriptFile); }
string CreateContextScriptFile(string workingDirectory) { var azureContextScriptFile = Path.Combine(workingDirectory, "Octopus.AzureCloudServiceContext.ps1"); var contextScript = embeddedResources.GetEmbeddedResourceText(GetType().Assembly, $"{GetType().Assembly.GetName().Name}.Scripts.AzureCloudServiceContext.ps1"); fileSystem.OverwriteFile(azureContextScriptFile, contextScript); return(azureContextScriptFile); }
protected void Run(RunningDeployment deployment) { var features = deployment.Variables.GetStrings(SpecialVariables.Package.EnabledFeatures).Where(s => !string.IsNullOrWhiteSpace(s)).ToList(); if (!features.Any()) { return; } var assembly = typeof(FeatureScriptConventionBase).GetTypeInfo().Assembly; var embeddedResourceNames = new HashSet <string>(embeddedResources.GetEmbeddedResourceNames(assembly)); foreach (var featureScript in features.SelectMany(GetScriptNames)) { // Determine the embedded-resource name var scriptEmbeddedResource = GetEmbeddedResourceName(featureScript); // If there is a matching embedded resource if (!embeddedResourceNames.Contains(scriptEmbeddedResource)) { continue; } var scriptFile = Path.Combine(deployment.CurrentDirectory, featureScript); // To execute the script, we need a physical file on disk. // If one already exists, we don't recreate it, as this provides a handy // way to override behaviour. if (!fileSystem.FileExists(scriptFile)) { Log.VerboseFormat("Creating '{0}' from embedded resource", scriptFile); fileSystem.OverwriteFile(scriptFile, embeddedResources.GetEmbeddedResourceText(assembly, scriptEmbeddedResource)); } else { Log.WarnFormat("Did not overwrite '{0}', it was already on disk", scriptFile); } // Execute the script Log.VerboseFormat("Executing '{0}'", scriptFile); var result = scriptEngine.Execute(new Script(scriptFile), deployment.Variables, commandLineRunner); // And then delete it Log.VerboseFormat("Deleting '{0}'", scriptFile); 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 features = deployment.Variables.GetStrings(SpecialVariables.Package.EnabledFeatures).Where(s => !string.IsNullOrWhiteSpace(s)).ToList(); if (!features.Any()) { return; } var embeddedResourceNames = new HashSet <string>(embeddedResources.GetEmbeddedResourceNames()); foreach (var featureScript in features.SelectMany(GetScriptNames)) { // Determine the embedded-resource name var scriptEmbeddedResource = GetEmbeddedResourceName(featureScript); // If there is a matching embedded resource if (!embeddedResourceNames.Contains(scriptEmbeddedResource)) { continue; } var scriptFile = Path.Combine(deployment.CurrentDirectory, featureScript); // To execute the script, we need a physical file on disk. // If one already exists, we don't recreate it, as this provides a handy // way to override behaviour. if (!fileSystem.FileExists(scriptFile)) { fileSystem.OverwriteFile(scriptFile, embeddedResources.GetEmbeddedResourceText(scriptEmbeddedResource)); } // Execute the script Log.VerboseFormat("Executing '{0}'", scriptFile); var result = scriptEngineSelector.SelectEngine(scriptFile).Execute(scriptFile, deployment.Variables, commandLineRunner); // And then delete it fileSystem.DeleteFile(scriptFile, DeletionOptions.TryThreeTimesIgnoreFailure); if (result.ExitCode != 0) { throw new CommandException(string.Format("Script '{0}' returned non-zero exit code: {1}", scriptFile, result.ExitCode)); } } }
private void Arrange(ICollection <string> features, string suffix) { variables.Set(SpecialVariables.Package.EnabledFeatures, string.Join(",", features)); var embeddedResourceNames = new List <string>(); foreach (var feature in features) { var scriptName = FeatureScriptConvention.GetScriptName(feature, suffix, "ps1"); var embeddedResourceName = FeatureScriptConvention.GetEmbeddedResourceName(scriptName); embeddedResources.GetEmbeddedResourceText(embeddedResourceName).Returns(scriptContents); embeddedResourceNames.Add(embeddedResourceName); var scriptPath = Path.Combine(stagingDirectory, scriptName); scriptEngine.Execute(scriptPath, variables, commandLineRunner).Returns(new CommandResult("", 0)); } embeddedResources.GetEmbeddedResourceNames().Returns(embeddedResourceNames.ToArray()); }
public void Install(RunningDeployment deployment) { var variables = deployment.Variables; // Set output variables for our script to access. log.SetOutputVariable("PublishProfileFile", variables.Get(SpecialVariables.Action.ServiceFabric.PublishProfileFile, "PublishProfiles\\Cloud.xml"), variables); log.SetOutputVariable("DeployOnly", variables.Get(SpecialVariables.Action.ServiceFabric.DeployOnly, defaultValue: false.ToString()), variables); log.SetOutputVariable("UnregisterUnusedApplicationVersionsAfterUpgrade", variables.Get(SpecialVariables.Action.ServiceFabric.UnregisterUnusedApplicationVersionsAfterUpgrade, defaultValue: false.ToString()), variables); log.SetOutputVariable("OverrideUpgradeBehavior", variables.Get(SpecialVariables.Action.ServiceFabric.OverrideUpgradeBehavior, defaultValue: "None"), variables); log.SetOutputVariable("OverwriteBehavior", variables.Get(SpecialVariables.Action.ServiceFabric.OverwriteBehavior, defaultValue: "SameAppTypeAndVersion"), variables); log.SetOutputVariable("SkipPackageValidation", variables.Get(SpecialVariables.Action.ServiceFabric.SkipPackageValidation, defaultValue: false.ToString()), variables); log.SetOutputVariable("CopyPackageTimeoutSec", variables.Get(SpecialVariables.Action.ServiceFabric.CopyPackageTimeoutSec, defaultValue: 0.ToString()), variables); SetRegisterApplicationTypeTimeout(variables); // Package should have been extracted to the staging dir (as per the ExtractPackageToStagingDirectoryConvention). var targetPath = Path.Combine(Environment.CurrentDirectory, "staging"); log.SetOutputVariable("ApplicationPackagePath", targetPath, variables); if (deployment.Variables.GetFlag(SpecialVariables.Action.ServiceFabric.LogExtractedApplicationPackage)) { LogExtractedPackage(deployment.CurrentDirectory); } // The user may supply the script, to override behaviour. var scriptFile = Path.Combine(deployment.CurrentDirectory, "DeployToServiceFabric.ps1"); if (!fileSystem.FileExists(scriptFile)) { // Use our bundled version. fileSystem.OverwriteFile(scriptFile, embeddedResources.GetEmbeddedResourceText(GetType().Assembly, $"{GetType().Assembly.GetName().Name}.Scripts.DeployAzureServiceFabricApplication.ps1")); } var result = scriptEngine.Execute(new Script(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)); } }
void ExecuteFeatureScripts(RunningDeployment deployment, string feature, HashSet <string> embeddedResourceNames) { foreach (var featureScript in GetScriptNames(feature)) { // Determine the embedded-resource name var scriptEmbeddedResource = GetEmbeddedResourceName(featureScript); // If there is a matching embedded resource if (!embeddedResourceNames.Contains(scriptEmbeddedResource)) { continue; } var scriptFile = Path.Combine(deployment.CurrentDirectory, featureScript); // To execute the script, we need a physical file on disk. // If one already exists, we don't recreate it, as this provides a handy // way to override behaviour. if (!fileSystem.FileExists(scriptFile)) { Log.VerboseFormat("Creating '{0}' from embedded resource", scriptFile); fileSystem.OverwriteFile(scriptFile, embeddedResources.GetEmbeddedResourceText(Assembly, scriptEmbeddedResource)); } else { Log.WarnFormat("Did not overwrite '{0}', it was already on disk", scriptFile); } // Execute the script Log.VerboseFormat("Executing '{0}'", scriptFile); var result = scriptEngine.Execute(new Script(scriptFile), deployment.Variables, commandLineRunner); // And then delete it Log.VerboseFormat("Deleting '{0}'", scriptFile); 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)); } } }
string CreateContextScriptFile(string workingDirectory, ScriptSyntax syntax) { string contextFile; switch (syntax) { case ScriptSyntax.Bash: contextFile = "AzureContext.sh"; break; case ScriptSyntax.PowerShell: contextFile = "AzureContext.ps1"; break; default: throw new InvalidOperationException($"No Azure context wrapper exists for {syntax}"); } var azureContextScriptFile = Path.Combine(workingDirectory, $"Octopus.{contextFile}"); var contextScript = embeddedResources.GetEmbeddedResourceText(GetType().Assembly, $"Calamari.Azure.Scripts.{contextFile}"); fileSystem.OverwriteFile(azureContextScriptFile, contextScript); return(azureContextScriptFile); }