Пример #1
0
 public PackagedScriptConvention(string scriptFilePrefix, ICalamariFileSystem fileSystem, IScriptEngineSelector scriptEngineSelector, ICommandLineRunner commandLineRunner)
 {
     this.scriptFilePrefix     = scriptFilePrefix;
     this.fileSystem           = fileSystem;
     this.scriptEngineSelector = scriptEngineSelector;
     this.commandLineRunner    = commandLineRunner;
 }
Пример #2
0
 public ApplyCommand(ILog log, IVariables variables, ICalamariFileSystem fileSystem, ICommandLineRunner commandLineRunner, ISubstituteInFiles substituteInFiles, IExtractPackage extractPackage)
     : base(log, variables, fileSystem, substituteInFiles, extractPackage)
 {
     this.log               = log;
     this.fileSystem        = fileSystem;
     this.commandLineRunner = commandLineRunner;
 }
Пример #3
0
        public CommandResult ExecuteScript(Script script, ScriptSyntax scriptSyntax, ICommandLineRunner commandLineRunner, Dictionary <string, string>?environmentVars)
        {
            if (NextWrapper == null)
            {
                throw new InvalidOperationException("NextWrapper has not been set.");
            }

            var workingDirectory = Path.GetDirectoryName(script.File);

            if (workingDirectory == null)
            {
                throw new InvalidOperationException("Working directory has not been set correctly.");
            }

            variables.Set("OctopusFunctionAppenderTargetScript", $"{script.File}");
            variables.Set("OctopusFunctionAppenderTargetScriptParameters", script.Parameters);
            var copyScriptFile = variables.Get(ScriptFunctionsVariables.CopyScriptWrapper);
            var scriptFile     = CreateContextScriptFile(workingDirectory, scriptSyntax);

            if (!String.IsNullOrEmpty(copyScriptFile))
            {
                var destinationFile = copyScriptFile;
                if (!Path.IsPathRooted(copyScriptFile))
                {
                    destinationFile = Path.Combine(workingDirectory, copyScriptFile);
                }

                File.Copy(scriptFile, destinationFile, true);
            }

            using (var contextScriptFile = new TemporaryFile(scriptFile))
            {
                return(NextWrapper.ExecuteScript(new Script(contextScriptFile.FilePath), scriptSyntax, commandLineRunner, environmentVars));
            }
        }
Пример #4
0
        public CommandResult Execute(
            Script script,
            CalamariVariableDictionary variables,
            ICommandLineRunner commandLineRunner,
            Dictionary <string, string> environmentVars = null)
        {
            var executable       = PythonBootstrapper.FindPythonExecutable();
            var workingDirectory = Path.GetDirectoryName(script.File);

            var dependencyInstallerFile      = PythonBootstrapper.PrepareDependencyInstaller(workingDirectory);
            var dependencyInstallerArguments = PythonBootstrapper.FormatCommandArguments(dependencyInstallerFile, string.Empty);

            using (new TemporaryFile(dependencyInstallerFile))
            {
                var result = commandLineRunner.Execute(new CommandLineInvocation(executable, dependencyInstallerArguments,
                                                                                 workingDirectory,
                                                                                 environmentVars));

                if (result.ExitCode != 0)
                {
                    return(result);
                }
            }

            var configurationFile = PythonBootstrapper.PrepareConfigurationFile(workingDirectory, variables);
            var bootstrapFile     = PythonBootstrapper.PrepareBootstrapFile(script, workingDirectory, configurationFile);
            var arguments         = PythonBootstrapper.FormatCommandArguments(bootstrapFile, script.Parameters);

            using (new TemporaryFile(configurationFile))
                using (new TemporaryFile(bootstrapFile))
                {
                    return(commandLineRunner.Execute(new CommandLineInvocation(executable, arguments, workingDirectory,
                                                                               environmentVars)));
                }
        }
Пример #5
0
 public NodeExecutor(CommonOptions options, IVariables variables, ICommandLineRunner commandLineRunner, ILog log)
 {
     this.options           = options;
     this.variables         = variables;
     this.commandLineRunner = commandLineRunner;
     this.log = log;
 }
Пример #6
0
        public CommandResult Execute(
            Script script,
            CalamariVariableDictionary variables,
            ICommandLineRunner commandLineRunner,
            StringDictionary environmentVars = null)
        {
            var workingDirectory = Path.GetDirectoryName(script.File);

            var executable             = PowerShellBootstrapper.PathToPowerShellExecutable();
            var bootstrapFile          = PowerShellBootstrapper.PrepareBootstrapFile(script, variables);
            var debuggingBootstrapFile = PowerShellBootstrapper.PrepareDebuggingBootstrapFile(script);
            var arguments = PowerShellBootstrapper.FormatCommandArguments(bootstrapFile, debuggingBootstrapFile, variables);

            var userName = variables.Get(SpecialVariables.Action.PowerShell.UserName);
            var password = ToSecureString(variables.Get(SpecialVariables.Action.PowerShell.Password));

            using (new TemporaryFile(bootstrapFile))
            {
                using (new TemporaryFile(debuggingBootstrapFile))
                {
                    var invocation = new CommandLineInvocation(
                        executable,
                        arguments,
                        workingDirectory,
                        environmentVars,
                        userName,
                        password);
                    return(commandLineRunner.Execute(invocation));
                }
            }
        }
Пример #7
0
 public DestroyBehaviour(ILog log,
                         ICalamariFileSystem fileSystem,
                         ICommandLineRunner commandLineRunner) : base(log)
 {
     this.fileSystem        = fileSystem;
     this.commandLineRunner = commandLineRunner;
 }
 public HelmUpgradeConvention(ILog log, IScriptEngine scriptEngine, ICommandLineRunner commandLineRunner, ICalamariFileSystem fileSystem)
 {
     this.log               = log;
     this.scriptEngine      = scriptEngine;
     this.commandLineRunner = commandLineRunner;
     this.fileSystem        = fileSystem;
 }
Пример #9
0
 public ConfiguredScriptConvention(string deploymentStage, ICalamariFileSystem fileSystem, IScriptEngine scriptEngine, ICommandLineRunner commandLineRunner)
 {
     this.deploymentStage   = deploymentStage;
     this.scriptEngine      = scriptEngine;
     this.fileSystem        = fileSystem;
     this.commandLineRunner = commandLineRunner;
 }
Пример #10
0
 public PackagedScriptRunner(string scriptFilePrefix, ICalamariFileSystem fileSystem, IScriptEngine scriptEngine, ICommandLineRunner commandLineRunner)
 {
     this.scriptFilePrefix  = scriptFilePrefix;
     this.fileSystem        = fileSystem;
     this.scriptEngine      = scriptEngine;
     this.commandLineRunner = commandLineRunner;
 }
Пример #11
0
 public DockerImagePackageDownloader(IScriptEngine scriptEngine, ICalamariFileSystem fileSystem, ICommandLineRunner commandLineRunner, IVariables variables)
 {
     this.scriptEngine      = scriptEngine;
     this.fileSystem        = fileSystem;
     this.commandLineRunner = commandLineRunner;
     this.variables         = variables;
 }
 public PackagedScriptConvention(string scriptFilePrefix, ICalamariFileSystem fileSystem, IScriptEngine scriptEngine, ICommandLineRunner commandLineRunner)
 {
     this.scriptFilePrefix = scriptFilePrefix;
     this.fileSystem = fileSystem;
     this.scriptEngine = scriptEngine;
     this.commandLineRunner = commandLineRunner;
 }
Пример #13
0
 public JavaLibraryCommand(IScriptEngine scriptEngine, ICalamariFileSystem fileSystem, IVariables variables, ICommandLineRunner commandLineRunner)
 {
     Options.Add("actionType=", "The step type being invoked.", v => actionType = v);
     this.scriptEngine      = scriptEngine;
     this.fileSystem        = fileSystem;
     this.variables         = variables;
     this.commandLineRunner = commandLineRunner;
 }
Пример #14
0
 public CommandResult ExecuteScript(Script script,
                                    ScriptSyntax scriptSyntax,
                                    ICommandLineRunner commandLineRunner,
                                    Dictionary <string, string> environmentVars)
 {
     WasCalled = true;
     return(NextWrapper.ExecuteScript(script, scriptSyntax, commandLineRunner, environmentVars));
 }
 public ConfiguredScriptConvention(string deploymentStage, IScriptEngine scriptEngine,
     ICalamariFileSystem fileSystem, ICommandLineRunner commandLineRunner)
 {
     this.deploymentStage = deploymentStage;
     this.scriptEngine = scriptEngine;
     this.fileSystem = fileSystem;
     this.commandLineRunner = commandLineRunner;
 }
Пример #16
0
 public DeployAzureCloudServicePackageConvention(ICalamariFileSystem fileSystem, ICalamariEmbeddedResources embeddedResources,
                                                 IScriptEngine scriptEngine, ICommandLineRunner commandLineRunner)
 {
     this.fileSystem        = fileSystem;
     this.embeddedResources = embeddedResources;
     this.scriptEngine      = scriptEngine;
     this.commandLineRunner = commandLineRunner;
 }
 protected PackagedScriptRunner(ILog log, string scriptFilePrefix, ICalamariFileSystem fileSystem, IScriptEngine scriptEngine, ICommandLineRunner commandLineRunner)
 {
     this.log = log;
     this.scriptFilePrefix  = scriptFilePrefix;
     this.fileSystem        = fileSystem;
     this.scriptEngine      = scriptEngine;
     this.commandLineRunner = commandLineRunner;
 }
Пример #18
0
 public RePackArchiveConvention(
     ICalamariFileSystem fileSystem,
     ICommandOutput commandOutput,
     ICommandLineRunner commandLineRunner)
 {
     this.fileSystem = fileSystem;
     this.jarTool    = new JarTool(commandLineRunner, commandOutput, fileSystem);
 }
Пример #19
0
 public ConfiguredScriptBehaviour(string deploymentStage, ILog log, ICalamariFileSystem fileSystem, IScriptEngine scriptEngine, ICommandLineRunner commandLineRunner)
 {
     this.deploymentStage   = deploymentStage;
     this.log               = log;
     this.scriptEngine      = scriptEngine;
     this.fileSystem        = fileSystem;
     this.commandLineRunner = commandLineRunner;
 }
 public DeployAzureCloudServicePackageConvention(ICalamariFileSystem fileSystem, ICalamariEmbeddedResources embeddedResources, 
     IScriptEngine scriptEngine, ICommandLineRunner commandLineRunner)
 {
     this.fileSystem = fileSystem;
     this.embeddedResources = embeddedResources;
     this.scriptEngine = scriptEngine;
     this.commandLineRunner = commandLineRunner;
 }
Пример #21
0
        public CommandResult Execute(Script script,
                                     IVariables variables,
                                     ICommandLineRunner commandLineRunner,
                                     Dictionary <string, string>?environmentVars = null)
        {
            var environmentVariablesIncludingProxy = environmentVars ?? new Dictionary <string, string>();

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

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

            CommandResult?result = null;

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

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

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

            return(result !);
        }
Пример #22
0
 public CommandResult ExecuteScript(Script script,
                                    ScriptSyntax scriptSyntax,
                                    CalamariVariableDictionary variables,
                                    ICommandLineRunner commandLineRunner,
                                    StringDictionary environmentVars)
 {
     WasCalled = true;
     return(NextWrapper.ExecuteScript(script, scriptSyntax, variables, commandLineRunner, environmentVars));
 }
Пример #23
0
 public FeatureScriptConvention(string deploymentStage, ICalamariFileSystem fileSystem, ICalamariEmbeddedResources embeddedResources, 
     IScriptEngine scriptEngine, ICommandLineRunner commandLineRunner)
 {
     this.deploymentStage = deploymentStage;
     this.fileSystem = fileSystem;
     this.embeddedResources = embeddedResources;
     this.scriptEngine = scriptEngine;
     this.commandLineRunner = commandLineRunner;
 }
Пример #24
0
 public FeatureScriptConvention(string deploymentStage, ICalamariFileSystem fileSystem, ICalamariEmbeddedResources embeddedResources,
                                IScriptEngine scriptEngine, ICommandLineRunner commandLineRunner)
 {
     this.deploymentStage   = deploymentStage;
     this.fileSystem        = fileSystem;
     this.embeddedResources = embeddedResources;
     this.scriptEngine      = scriptEngine;
     this.commandLineRunner = commandLineRunner;
 }
        public CommandResult ExecuteScript(Script script,
                                           ScriptSyntax scriptSyntax,
                                           CalamariVariableDictionary variables,
                                           ICommandLineRunner commandLineRunner,
                                           StringDictionary environmentVars)
        {
            // We only execute this hook if the connection endpoint has been set
            if (!IsEnabled(scriptSyntax))
            {
                throw new InvalidOperationException(
                          "This script wrapper hook is not enabled, and should not have been run");
            }

            if (!ServiceFabricHelper.IsServiceFabricSdkKeyInRegistry())
            {
                throw new Exception("Could not find the Azure Service Fabric SDK on this server. This SDK is required before running Service Fabric commands.");
            }

            var workingDirectory = Path.GetDirectoryName(script.File);

            variables.Set("OctopusFabricTargetScript", "\"" + script.File + "\"");
            variables.Set("OctopusFabricTargetScriptParameters", script.Parameters);

            // Azure PS modules are required for looking up Azure environments (needed for AAD url lookup in Service Fabric world).
            SetAzureModulesLoadingMethod(variables);

            // Read thumbprint from our client cert variable (if applicable).
            var securityMode         = variables.Get(SpecialVariables.Action.ServiceFabric.SecurityMode);
            var clientCertThumbprint = string.Empty;

            if (securityMode == AzureServiceFabricSecurityMode.SecureClientCertificate.ToString())
            {
                var certificateVariable = GetMandatoryVariable(variables, SpecialVariables.Action.ServiceFabric.ClientCertVariable);
                clientCertThumbprint = variables.Get($"{certificateVariable}.{SpecialVariables.Certificate.Properties.Thumbprint}");
            }

            // Set output variables for our script to access.
            SetOutputVariable("OctopusFabricConnectionEndpoint", variables.Get(SpecialVariables.Action.ServiceFabric.ConnectionEndpoint), variables);
            SetOutputVariable("OctopusFabricSecurityMode", variables.Get(SpecialVariables.Action.ServiceFabric.SecurityMode), variables);
            SetOutputVariable("OctopusFabricServerCertThumbprint", variables.Get(SpecialVariables.Action.ServiceFabric.ServerCertThumbprint), variables);
            SetOutputVariable("OctopusFabricClientCertThumbprint", clientCertThumbprint, variables);
            SetOutputVariable("OctopusFabricCertificateFindType", variables.Get(SpecialVariables.Action.ServiceFabric.CertificateFindType, "FindByThumbprint"), variables);
            SetOutputVariable("OctopusFabricCertificateFindValueOverride", variables.Get(SpecialVariables.Action.ServiceFabric.CertificateFindValueOverride), variables);
            SetOutputVariable("OctopusFabricCertificateStoreLocation", variables.Get(SpecialVariables.Action.ServiceFabric.CertificateStoreLocation, "LocalMachine"), variables);
            SetOutputVariable("OctopusFabricCertificateStoreName", variables.Get(SpecialVariables.Action.ServiceFabric.CertificateStoreName, "MY"), variables);
            SetOutputVariable("OctopusFabricAadCredentialType", variables.Get(SpecialVariables.Action.ServiceFabric.AadCredentialType), variables);
            SetOutputVariable("OctopusFabricAadClientCredentialSecret", variables.Get(SpecialVariables.Action.ServiceFabric.AadClientCredentialSecret), variables);
            SetOutputVariable("OctopusFabricAadUserCredentialUsername", variables.Get(SpecialVariables.Action.ServiceFabric.AadUserCredentialUsername), variables);
            SetOutputVariable("OctopusFabricAadUserCredentialPassword", variables.Get(SpecialVariables.Action.ServiceFabric.AadUserCredentialPassword), variables);

            using (new TemporaryFile(Path.Combine(workingDirectory, "AzureProfile.json")))
                using (var contextScriptFile = new TemporaryFile(CreateContextScriptFile(workingDirectory)))
                {
                    return(NextWrapper.ExecuteScript(new Script(contextScriptFile.FilePath), scriptSyntax, variables, commandLineRunner, environmentVars));
                }
        }
 public SwapAzureDeploymentConvention(ICalamariFileSystem fileSystem,
                                      ICalamariEmbeddedResources embeddedResources,
                                      IScriptEngine scriptEngine,
                                      ICommandLineRunner commandLineRunner)
 {
     this.fileSystem        = fileSystem;
     this.embeddedResources = embeddedResources;
     this.scriptEngine      = scriptEngine;
     this.commandLineRunner = commandLineRunner;
 }
 public SwapAzureDeploymentConvention(ICalamariFileSystem fileSystem,
     ICalamariEmbeddedResources embeddedResources,
     IScriptEngine scriptEngine,
     ICommandLineRunner commandLineRunner)
 {
     this.fileSystem = fileSystem;
     this.embeddedResources = embeddedResources;
     this.scriptEngine = scriptEngine;
     this.commandLineRunner = commandLineRunner;
 }
        public CommandResult Execute(string scriptFile, CalamariVariableDictionary variables, ICommandLineRunner commandLineRunner)
        {
            var powerShellEngine = new PowerShellScriptEngine();
            if (variables.Get(SpecialVariables.Account.AccountType) == "AzureSubscription")
            {
                return new AzurePowerShellContext().ExecuteScript(powerShellEngine, scriptFile, variables, commandLineRunner);
            }

            return powerShellEngine.Execute(scriptFile, variables, commandLineRunner);
        }
Пример #29
0
 protected FeatureConventionBase(string deploymentStage, IEnumerable <IFeature> featureClasses, ICalamariFileSystem fileSystem,
                                 IScriptEngine scriptEngine, ICommandLineRunner commandLineRunner, ICalamariEmbeddedResources embeddedResources)
 {
     this.deploymentStage   = deploymentStage;
     this.fileSystem        = fileSystem;
     this.embeddedResources = embeddedResources;
     this.scriptEngine      = scriptEngine;
     this.commandLineRunner = commandLineRunner;
     this.featureClasses    = featureClasses?.ToList();
 }
Пример #30
0
 public DestroyPlanCommand(
     ILog log,
     IVariables variables,
     ICalamariFileSystem fileSystem,
     ICommandLineRunner commandLineRunner,
     ISubstituteInFiles substituteInFiles,
     IExtractPackage extractPackage)
     : base(log, variables, fileSystem, commandLineRunner, substituteInFiles, extractPackage)
 {
 }
Пример #31
0
        public CommandResult Execute(
            Script script,
            CalamariVariableDictionary variables,
            ICommandLineRunner commandLineRunner,
            Dictionary <string, string> environmentVars = null)
        {
            var syntax = ValidateScriptType(script);

            return(BuildWrapperChain(syntax)
                   .ExecuteScript(script, syntax, variables, commandLineRunner, environmentVars));
        }
Пример #32
0
 public ExecuteManifestCommand(IVariables variables,
                               IEnumerable <Meta <ILaunchTool, LaunchToolMeta> > executionTools,
                               ICalamariFileSystem fileSystem,
                               ILog log, ICommandLineRunner commandLineRunner)
 {
     this.variables         = variables;
     this.executionTools    = executionTools;
     this.fileSystem        = fileSystem;
     this.log               = log;
     this.commandLineRunner = commandLineRunner;
 }
Пример #33
0
        public TerraformCliExecutor(
            ILog log,
            ICalamariFileSystem fileSystem,
            ICommandLineRunner commandLineRunner,
            RunningDeployment deployment,
            Dictionary <string, string> environmentVariables
            )
        {
            this.log                  = log;
            this.fileSystem           = fileSystem;
            this.commandLineRunner    = commandLineRunner;
            this.deployment           = deployment;
            variables                 = deployment.Variables;
            this.environmentVariables = environmentVariables;
            logPath = Path.Combine(deployment.CurrentDirectory, "terraform.log");

            /*
             * Terraform has an issue where it will not clean up temporary files created while downloading
             * providers: https://github.com/hashicorp/terraform/issues/28477
             *
             * By overriding the temporary directory and cleaning it up when Calamari is done,
             * we can work around the the issue.
             *
             * https://golang.org/pkg/os/#TempDir
             * On Unix systems, it returns $TMPDIR if non-empty, else /tmp. On Windows,
             * it uses GetTempPath, returning the first non-empty value from %TMP%,
             * %TEMP%, %USERPROFILE%, or the Windows directory. On Plan 9, it returns /tmp.
             */
            this.environmentVariables["TMP"]    = disposableDirectory.DirectoryPath;
            this.environmentVariables["TEMP"]   = disposableDirectory.DirectoryPath;
            this.environmentVariables["TMPDIR"] = disposableDirectory.DirectoryPath;

            templateDirectory = variables.Get(TerraformSpecialVariables.Action.Terraform.TemplateDirectory, deployment.CurrentDirectory);

            if (!string.IsNullOrEmpty(templateDirectory))
            {
                var templateDirectoryTemp = Path.Combine(deployment.CurrentDirectory, templateDirectory);

                if (!Directory.Exists(templateDirectoryTemp))
                {
                    throw new Exception($"Directory {templateDirectory} does not exist.");
                }

                templateDirectory = templateDirectoryTemp;
            }

            InitializeTerraformEnvironmentVariables();

            Version = GetVersion();

            InitializePlugins();

            InitializeWorkspace();
        }
Пример #34
0
        public CommandResult Execute(
            Script script,
            IVariables variables,
            ICommandLineRunner commandLineRunner,
            Dictionary <string, string> environmentVars = null)
        {
            var syntax = script.File.ToScriptType();

            return(BuildWrapperChain(syntax, variables)
                   .ExecuteScript(script, syntax, commandLineRunner, environmentVars));
        }
        public void SetUp()
        {
            log = Substitute.For <ILog>();
            log.When(x => x.SetOutputVariable(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <IVariables>()))
            .Do(x => outputVars.Add(x.ArgAt <string>(0), x.ArgAt <string>(1)));

            calamariFileSystem = Substitute.For <ICalamariFileSystem>();
            commandLineRunner  = Substitute.For <ICommandLineRunner>();
            variables          = new CalamariVariables();
            variables.Set(TerraformSpecialVariables.Action.Terraform.PlanJsonOutput, "True");
            runningDeployment = Substitute.For <RunningDeployment>(variables);
        }
        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 };
        }
Пример #37
0
 public DeployAzureServiceFabricAppConvention(
     ILog log,
     ICalamariFileSystem fileSystem,
     ICalamariEmbeddedResources embeddedResources,
     IScriptEngine scriptEngine,
     ICommandLineRunner commandLineRunner)
 {
     this.log               = log;
     this.fileSystem        = fileSystem;
     this.embeddedResources = embeddedResources;
     this.scriptEngine      = scriptEngine;
     this.commandLineRunner = commandLineRunner;
 }
Пример #38
0
        public CommandResult Execute(string scriptFile, VariableDictionary variables, ICommandLineRunner commandLineRunner)
        {
            var workingDirectory = Path.GetDirectoryName(scriptFile);

            var configurationFile = ScriptCSBootstrapper.PrepareConfigurationFile(workingDirectory, variables);
            var boostrapFile = ScriptCSBootstrapper.PrepareBootstrapFile(scriptFile, configurationFile, workingDirectory);

            using (new TemporaryFile(configurationFile))
            using (new TemporaryFile(boostrapFile))
            {
                return commandLineRunner.Execute(new CommandLineInvocation(ScriptCSBootstrapper.FindScriptCSExecutable(), ScriptCSBootstrapper.FormatCommandArguments(boostrapFile), workingDirectory));
            }
        }
Пример #39
0
        public CommandResult Execute(string scriptFile, CalamariVariableDictionary variables, ICommandLineRunner commandLineRunner)
        {
            var workingDirectory = Path.GetDirectoryName(scriptFile);

            var executable = PowerShellBootstrapper.PathToPowerShellExecutable();
            var boostrapFile = PowerShellBootstrapper.PrepareBootstrapFile(scriptFile, variables);
            var arguments = PowerShellBootstrapper.FormatCommandArguments(boostrapFile);

            using (new TemporaryFile(boostrapFile))
            {
                var invocation = new CommandLineInvocation(executable, arguments, workingDirectory);
                return commandLineRunner.Execute(invocation);
            }
        }
Пример #40
0
        public CommandResult Execute(string scriptFile, VariableDictionary variables, ICommandLineRunner commandLineRunner)
        {
            var scriptType = Path.GetExtension(scriptFile).TrimStart('.').ToScriptType();
            var engine = GetSpecificScriptEngine(scriptType);

            // When running Powershell against an Azure target, we load the Azure Powershell modules,
            // and set the Azure subscription
            if (scriptType == ScriptType.Powershell &&
                variables.Get(SpecialVariables.Account.AccountType) == "AzureSubscription")
            {
                var azureContextScriptFile = azurePowershellContext.CreateAzureContextScript(scriptFile, variables);
                return engine.Execute(azureContextScriptFile, variables, commandLineRunner);
            }

            return engine.Execute(scriptFile, variables, commandLineRunner);
        }
        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());
        }
Пример #42
0
        public CommandResult ExecuteScript(IScriptEngine scriptEngine, string scriptFile, CalamariVariableDictionary variables, ICommandLineRunner commandLineRunner)
        {
            var workingDirectory = Path.GetDirectoryName(scriptFile);
            variables.Set("OctopusAzureTargetScript", scriptFile);

            // If the Azure PowerShell module to use has not been explicitly configured, then default to the version
            // bundled with Calamari
            SetOutputVariable(SpecialVariables.Action.Azure.Output.ModulePath,
                variables.Get(SpecialVariables.Action.Azure.PowerShellModulePath, BuiltInAzurePowershellModulePath), variables);

            SetOutputVariable(SpecialVariables.Action.Azure.Output.SubscriptionId, variables.Get(SpecialVariables.Action.Azure.SubscriptionId), variables);
            SetOutputVariable(SpecialVariables.Action.Azure.Output.SubscriptionName, variables.Get(SpecialVariables.Account.Name), variables);

            using (new TemporaryFile(CreateAzureCertificate(workingDirectory, variables)))
            using (var contextScriptFile = new TemporaryFile(CreateContextScriptFile(workingDirectory)))
            {
                return scriptEngine.Execute(contextScriptFile.FilePath, variables, commandLineRunner);
            }
        }
 public CommandResult Execute(string scriptFile, CalamariVariableDictionary variables, ICommandLineRunner commandLineRunner)
 {
     var scriptType = Path.GetExtension(scriptFile).TrimStart('.').ToScriptType();
     return ScriptEngineRegistry.Instance.ScriptEngines[scriptType].Execute(scriptFile, variables, commandLineRunner);
 }
Пример #44
0
 public CommandResult Execute(string scriptFile, CalamariVariableDictionary variables, ICommandLineRunner commandLineRunner)
 {
     var scriptType = ValidateScriptType(scriptFile);
     return ScriptEngineRegistry.Instance.ScriptEngines[scriptType].Execute(scriptFile, variables, commandLineRunner);
 }
Пример #45
0
 public RollbackScriptConvention(string scriptFilePrefix, ICalamariFileSystem fileSystem, IScriptEngine scriptEngine, ICommandLineRunner commandLineRunner) :
     base(scriptFilePrefix, fileSystem, scriptEngine, commandLineRunner)
 {            
 }