Пример #1
0
 public void ShouldNotIncludeIISRelatedInfoInErrorMessageWhenAccessDeniedException()
 {
     variables.Set(SpecialVariables.Package.CustomInstallationDirectory, customInstallationDirectory);
     fileSystem.CopyDirectory(Arg.Any <string>(), Arg.Any <string>())
     .ThrowsForAnyArgs(
         new UnauthorizedAccessException($"Access to the path {customInstallationDirectory} was denied."));
     CreateConvention().Install(deployment);
 }
Пример #2
0
        public void Install(RunningDeployment deployment)
        {
            var customInstallationDirectory = deployment.Variables.Get(SpecialVariables.Package.CustomInstallationDirectory);
            var sourceDirectory             = deployment.Variables.Get(SpecialVariables.OriginalPackageDirectoryPath);

            if (string.IsNullOrWhiteSpace(customInstallationDirectory))
            {
                Log.Verbose("The package has been installed to: " + sourceDirectory);
                Log.VerboseFormat("If you would like the package to be installed to an alternative location, please specify the variable '{0}'", SpecialVariables.Package.CustomInstallationDirectory);
                // If the variable was not set then we set it, as it makes it simpler for anything to depend on it from this point on
                deployment.Variables.Set(SpecialVariables.Package.CustomInstallationDirectory,
                                         sourceDirectory);

                return;
            }

            // Purge if requested
            if (deployment.Variables.GetFlag(
                    SpecialVariables.Package.CustomInstallationDirectoryShouldBePurgedBeforeDeployment))
            {
                Log.Info("Purging the directory '{0}'", customInstallationDirectory);
                fileSystem.PurgeDirectory(deployment.CustomDirectory, FailureOptions.ThrowOnFailure);
            }

            // Copy files from staging area to custom directory
            Log.Info("Copying package contents to '{0}'", customInstallationDirectory);
            int count = fileSystem.CopyDirectory(deployment.StagingDirectory, deployment.CustomDirectory);

            Log.Info("Copied {0} files", count);

            // From this point on, the current directory will be the custom-directory
            deployment.CurrentDirectoryProvider = DeploymentWorkingDirectory.CustomDirectory;

            Log.SetOutputVariable(SpecialVariables.Package.Output.InstallationDirectoryPath, deployment.CustomDirectory, deployment.Variables);
        }
Пример #3
0
        public void Install(RunningDeployment deployment)
        {
            string errorString;
            var    customInstallationDirectory = deployment.Variables.Get(SpecialVariables.Package.CustomInstallationDirectory, out errorString);
            var    sourceDirectory             = deployment.Variables.Get(SpecialVariables.OriginalPackageDirectoryPath);

            if (string.IsNullOrWhiteSpace(customInstallationDirectory))
            {
                Log.Verbose("The package has been installed to: " + sourceDirectory);
                Log.VerboseFormat(
                    "If you would like the package to be installed to an alternative location, please specify the variable '{0}'",
                    SpecialVariables.Package.CustomInstallationDirectory);
                // If the variable was not set then we set it, as it makes it simpler for anything to depend on it from this point on
                deployment.Variables.Set(SpecialVariables.Package.CustomInstallationDirectory,
                                         sourceDirectory);

                return;
            }

            if (!string.IsNullOrEmpty(errorString))
            {
                throw new CommandException(
                          $"An error occurred when evaluating the value for the custom install directory. {errorString}");
            }

            if (string.IsNullOrEmpty(Path.GetPathRoot(customInstallationDirectory)))
            {
                throw new CommandException(
                          $"The custom install directory '{customInstallationDirectory}' is a relative path, please specify the path as an absolute path or a UNC path.");
            }

            if (customInstallationDirectory.IsChildDirectoryOf(sourceDirectory))
            {
                throw new CommandException(
                          $"The custom install directory '{customInstallationDirectory}' is a child directory of the base installation directory '{sourceDirectory}', please specify a different destination.");
            }

            // Purge if requested
            if (deployment.Variables.GetFlag(
                    SpecialVariables.Package.CustomInstallationDirectoryShouldBePurgedBeforeDeployment))
            {
                Log.Info("Purging the directory '{0}'", customInstallationDirectory);
                fileSystem.PurgeDirectory(deployment.CustomDirectory, FailureOptions.ThrowOnFailure);
            }

            // Copy files from staging area to custom directory
            Log.Info("Copying package contents to '{0}'", customInstallationDirectory);
            int count = fileSystem.CopyDirectory(deployment.StagingDirectory, deployment.CustomDirectory);

            Log.Info("Copied {0} files", count);

            // From this point on, the current directory will be the custom-directory
            deployment.CurrentDirectoryProvider = DeploymentWorkingDirectory.CustomDirectory;

            Log.SetOutputVariable(SpecialVariables.Package.Output.InstallationDirectoryPath, deployment.CustomDirectory, deployment.Variables);
            Log.SetOutputVariable(SpecialVariables.Package.Output.DeprecatedInstallationDirectoryPath, deployment.CustomDirectory, deployment.Variables);
            Log.SetOutputVariable(SpecialVariables.Package.Output.CopiedFileCount, count.ToString(), deployment.Variables);
        }
Пример #4
0
        void InitializeTerraformEnvironmentVariables()
        {
            defaultEnvironmentVariables = new CommandLineToolsProxyEnvironmentVariables().EnvironmentVariables;

            defaultEnvironmentVariables.Add("TF_IN_AUTOMATION", "1");
            defaultEnvironmentVariables.Add("TF_LOG", "TRACE");
            defaultEnvironmentVariables.Add("TF_LOG_PATH", logPath);
            defaultEnvironmentVariables.Add("TF_INPUT", "0");

            var customPluginDir = deployment.Variables.Get(TerraformSpecialVariables.Action.Terraform.PluginsDirectory);
            var pluginsPath     = Path.Combine(deployment.CurrentDirectory, "terraformplugins");

            fileSystem.EnsureDirectoryExists(pluginsPath);

            if (!string.IsNullOrEmpty(customPluginDir))
            {
                fileSystem.CopyDirectory(customPluginDir, pluginsPath);
            }

            defaultEnvironmentVariables.Add("TF_PLUGIN_CACHE_DIR", pluginsPath);
        }
        public void Install(RunningDeployment deployment)
        {
            string errorString;
            var    customInstallationDirectory = deployment.Variables.Get(PackageVariables.CustomInstallationDirectory, out errorString);
            var    sourceDirectory             = deployment.Variables.Get(KnownVariables.OriginalPackageDirectoryPath);

            if (string.IsNullOrWhiteSpace(customInstallationDirectory))
            {
                Log.Verbose("The package has been installed to: " + sourceDirectory);
                Log.Verbose("If you would like the package to be installed to an alternative location, please use the 'Custom installation directory' feature");
                // If the variable was not set then we set it, as it makes it simpler for anything to depend on it from this point on
                deployment.Variables.Set(PackageVariables.CustomInstallationDirectory,
                                         sourceDirectory);

                return;
            }

            Log.Verbose($"Installing package to custom directory {customInstallationDirectory}");

            if (!string.IsNullOrEmpty(errorString))
            {
                throw new CommandException(
                          $"An error occurred when evaluating the value for the custom install directory. {errorString}");
            }

            if (string.IsNullOrEmpty(Path.GetPathRoot(customInstallationDirectory)))
            {
                throw new CommandException(
                          $"The custom install directory '{customInstallationDirectory}' is a relative path, please specify the path as an absolute path or a UNC path.");
            }

            if (customInstallationDirectory.IsChildOf(sourceDirectory))
            {
                throw new CommandException(
                          $"The custom install directory '{customInstallationDirectory}' is a child directory of the base installation directory '{sourceDirectory}', please specify a different destination.");
            }

            try
            {
                // Purge if requested
                if (deployment.Variables.GetFlag(
                        PackageVariables.CustomInstallationDirectoryShouldBePurgedBeforeDeployment))
                {
                    Log.Info("Purging the directory '{0}'", customInstallationDirectory);
                    var purgeExlusions = deployment.Variables.GetPaths(PackageVariables.CustomInstallationDirectoryPurgeExclusions).ToArray();
                    if (purgeExlusions.Any())
                    {
                        Log.Info("Leaving files and directories that match any of: '{0}'", string.Join(", ", purgeExlusions));
                    }
                    fileSystem.PurgeDirectory(deployment.CustomDirectory, FailureOptions.ThrowOnFailure, purgeExlusions);
                }

                // Copy files from staging area to custom directory
                Log.Info("Copying package contents to '{0}'", customInstallationDirectory);
                int count = fileSystem.CopyDirectory(deployment.StagingDirectory, deployment.CustomDirectory);
                Log.Info("Copied {0} files", count);

                // From this point on, the current directory will be the custom-directory
                deployment.CurrentDirectoryProvider = DeploymentWorkingDirectory.CustomDirectory;

                Log.SetOutputVariable(PackageVariables.Output.InstallationDirectoryPath, deployment.CustomDirectory, deployment.Variables);
                Log.SetOutputVariable(PackageVariables.Output.DeprecatedInstallationDirectoryPath, deployment.CustomDirectory, deployment.Variables);
                Log.SetOutputVariable(PackageVariables.Output.CopiedFileCount, count.ToString(), deployment.Variables);
            }
            catch (UnauthorizedAccessException uae) when(uae.Message.StartsWith("Access to the path"))
            {
                var message = $"{uae.Message} Ensure that the application that uses this directory is not running.";

                if (CalamariEnvironment.IsRunningOnWindows)
                {
                    message += " If this is an IIS website, stop the application pool or use an app_offline.htm file " +
                               "(see https://g.octopushq.com/TakingWebsiteOffline).";
                }
                throw new CommandException(
                          message
                          );
            }
        }