示例#1
0
 public void CleanUp()
 {
     if (!string.IsNullOrWhiteSpace(stagingDirectory))
     {
         fileSystem.DeleteDirectory(stagingDirectory, FailureOptions.IgnoreFailure);
     }
 }
示例#2
0
 public void TearDown()
 {
     if (fileSystem.DirectoryExists(tempDirectory))
     {
         fileSystem.DeleteDirectory(tempDirectory, FailureOptions.IgnoreFailure);
     }
 }
示例#3
0
        /// <summary>
        /// Extracts the contents of the JAR's manifest file
        /// </summary>
        public string ExtractManifest(string jarPath)
        {
            const string manifestJarPath = "META-INF/MANIFEST.MF";

            var tempDirectory = fileSystem.CreateTemporaryDirectory();

            var extractJarCommand =
                new CommandLineInvocation("java", $"-cp \"{toolsPath}\" sun.tools.jar.Main xf \"{jarPath}\" \"{manifestJarPath}\"", tempDirectory);

            try
            {
                Log.Verbose($"Invoking '{extractJarCommand}' to extract '{manifestJarPath}'");
                var result = commandLineRunner.Execute(extractJarCommand);
                result.VerifySuccess();

                // Ensure our slashes point in the correct direction
                var extractedManifestPathComponents = new List <string> {
                    tempDirectory
                };
                extractedManifestPathComponents.AddRange(manifestJarPath.Split('/'));

                return(File.ReadAllText(Path.Combine(extractedManifestPathComponents.ToArray())));
            }
            catch (Exception ex)
            {
                throw new Exception($"Error invoking '{extractJarCommand}'", ex);
            }
            finally
            {
                fileSystem.DeleteDirectory(tempDirectory, FailureOptions.IgnoreFailure);
            }
        }
        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");
            }
        }
示例#5
0
        public void ShouldModifyIisWebsiteRoot()
        {
            // If the 'UpdateIisWebsite' variable is set, the website root will be updated

            // Create the website
            var originalWebRootPath = Path.Combine(Path.GetTempPath(), "CalamariTestIisSite");

            fileSystem.EnsureDirectoryExists(originalWebRootPath);
            var webServer = WebServerSupport.AutoDetect();
            var siteName  = "CalamariTest-" + Guid.NewGuid();

            webServer.CreateWebSiteOrVirtualDirectory(siteName, "/", originalWebRootPath, 1081);

            variables.Set(SpecialVariables.Package.UpdateIisWebsite, true.ToString());
            variables.Set(SpecialVariables.Package.UpdateIisWebsiteName, siteName);

            var result = DeployPackage("Acme.Web");

            Assert.AreEqual(
                Path.Combine(stagingDirectory, "Acme.Web\\1.0.0"),
                webServer.GetHomeDirectory(siteName, "/"));

            // And remove the website
            webServer.DeleteWebSite(siteName);
            fileSystem.DeleteDirectory(originalWebRootPath);
        }
示例#6
0
        public void ApplyRetentionPolicy(string retentionPolicySet, int?days, int?releases)
        {
            var deployments = deploymentJournal.GetAllJournalEntries().Where(x => x.RetentionPolicySet == retentionPolicySet);

            if (days.HasValue && days.Value > 0)
            {
                deployments = deployments.Where(x => x.InstalledOn < clock.GetUtcTime().AddDays(-days.Value)).ToList();
            }
            else if (releases.HasValue && releases.Value > 0)
            {
                var skipped = 0;

                // Keep the current release, plus specified releases value
                // Unsuccessful releases are not included in the count of releases to keep
                deployments = deployments
                              .OrderByDescending(x => x.InstalledOn)
                              .SkipWhile((x) => (x.WasSuccessful ? skipped++ : skipped) <= releases.Value)
                              .ToList();
            }

            foreach (var deployment in deployments)
            {
                if (fileSystem.DirectoryExists(deployment.ExtractedTo))
                {
                    Log.VerboseFormat("Removing directory '{0}'", deployment.ExtractedTo);
                    fileSystem.PurgeDirectory(deployment.ExtractedTo, DeletionOptions.TryThreeTimesIgnoreFailure);

                    try
                    {
                        fileSystem.DeleteDirectory(deployment.ExtractedTo);
                    }
                    catch (Exception ex)
                    {
                        Log.VerboseFormat("Could not delete directory '{0}' because some files could not be deleted: {1}", deployment.ExtractedFrom, ex.Message);
                    }
                }

                if (!string.IsNullOrWhiteSpace(deployment.ExtractedFrom) && fileSystem.FileExists(deployment.ExtractedFrom))
                {
                    Log.VerboseFormat("Removing package file '{0}'", deployment.ExtractedFrom);
                    fileSystem.DeleteFile(deployment.ExtractedFrom, DeletionOptions.TryThreeTimesIgnoreFailure);
                }
            }

            deploymentJournal.RemoveJournalEntries(deployments.Select(x => x.Id));
        }
示例#7
0
        void DeleteExtractionDestination(JournalEntry deployment, List <JournalEntry> preservedEntries)
        {
            if (!fileSystem.DirectoryExists(deployment.ExtractedTo) ||
                preservedEntries.Any(entry => deployment.ExtractedTo.Equals(entry.ExtractedTo, StringComparison.Ordinal)))
            {
                return;
            }

            Log.VerboseFormat("Removing directory '{0}'", deployment.ExtractedTo);
            fileSystem.PurgeDirectory(deployment.ExtractedTo, FailureOptions.IgnoreFailure);

            try
            {
                fileSystem.DeleteDirectory(deployment.ExtractedTo);
            }
            catch (Exception ex)
            {
                Log.VerboseFormat("Could not delete directory '{0}' because some files could not be deleted: {1}",
                                  deployment.ExtractedFrom, ex.Message);
            }
        }
示例#8
0
 public void Dispose()
 {
     fileSystem.DeleteDirectory(DirectoryPath, FailureOptions.IgnoreFailure);
 }