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); }
public void SetUp() { fileSystem = CalamariPhysicalFileSystem.GetPhysicalFileSystem(); // Ensure tenticle directory exists tentacleDirectory = Path.Combine(Path.GetTempPath(), "CalamariTestTentacle"); var tentacleHiddenDirectory = Path.Combine(tentacleDirectory, ".tentacle"); fileSystem.EnsureDirectoryExists(tentacleDirectory); fileSystem.EnsureDirectoryExists(tentacleHiddenDirectory); fileSystem.PurgeDirectory(tentacleHiddenDirectory, FailureOptions.ThrowOnFailure); Environment.SetEnvironmentVariable("TentacleJournal", Path.Combine(tentacleHiddenDirectory, "DeploymentJournal.xml" )); variables = new VariableDictionary(); variables.EnrichWithEnvironmentVariables(); deploymentJournal = new DeploymentJournal(fileSystem, new SystemSemaphore(), variables); packagesDirectory = Path.Combine(Path.GetTempPath(), "CalamariTestPackages"); fileSystem.EnsureDirectoryExists(packagesDirectory); stagingDirectory = Path.Combine(Path.GetTempPath(), "CalamariTestStaging"); fileSystem.EnsureDirectoryExists(stagingDirectory); // Create some artificats const string retentionPolicySet1 = "retentionPolicySet1"; CreateDeployment(Path.Combine(packagesDirectory, "Acme.1.0.0.nupkg"), Path.Combine(stagingDirectory, "Acme.1.0.0"), new DateTimeOffset(new DateTime(2015, 01, 26), new TimeSpan(10, 0,0)), retentionPolicySet1); CreateDeployment(Path.Combine(packagesDirectory, "Acme.1.1.0.nupkg"), Path.Combine(stagingDirectory, "Acme.1.1.0"), new DateTimeOffset(new DateTime(2015, 02, 01), new TimeSpan(10, 0,0)), retentionPolicySet1); CreateDeployment(Path.Combine(packagesDirectory, "Acme.1.2.0.nupkg"), Path.Combine(stagingDirectory, "Acme.1.2.0"), new DateTimeOffset(new DateTime(2015, 02, 10), new TimeSpan(10, 0,0)), retentionPolicySet1); }
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); }
public void ShouldCopyFilesToCustomInstallationDirectory() { // Set-up a custom installation directory string customInstallDirectory = Path.Combine(Path.GetTempPath(), "CalamariTestInstall"); fileSystem.EnsureDirectoryExists(customInstallDirectory); // Ensure the directory is empty before we start fileSystem.PurgeDirectory(customInstallDirectory, FailureOptions.ThrowOnFailure); variables.Set(SpecialVariables.Package.CustomInstallationDirectory, customInstallDirectory); var result = DeployPackage("Acme.Web"); // Assert content was copied to custom-installation directory Assert.IsTrue(fileSystem.FileExists(Path.Combine(customInstallDirectory, "assets", "styles.css"))); }
public virtual void SetUp() { fileSystem = CalamariPhysicalFileSystem.GetPhysicalFileSystem(); log = new InMemoryLog(); // Ensure staging directory exists and is empty applicationDirectory = Path.Combine(Path.GetTempPath(), "CalamariTestStaging"); fileSystem.EnsureDirectoryExists(applicationDirectory); fileSystem.PurgeDirectory(applicationDirectory, FailureOptions.ThrowOnFailure); Environment.SetEnvironmentVariable("TentacleJournal", Path.Combine(applicationDirectory, "DeploymentJournal.xml")); variables = new VariablesFactory(fileSystem).Create(new CommonOptions("test")); variables.Set(TentacleVariables.Agent.ApplicationDirectoryPath, applicationDirectory); }
public void SetUp() { fileSystem = CalamariPhysicalFileSystem.GetPhysicalFileSystem(); // Ensure staging directory exists and is empty stagingDirectory = Path.Combine(Path.GetTempPath(), "CalamariTestStaging"); customDirectory = Path.Combine(Path.GetTempPath(), "CalamariTestCustom"); fileSystem.EnsureDirectoryExists(stagingDirectory); fileSystem.PurgeDirectory(stagingDirectory, FailureOptions.ThrowOnFailure); Environment.SetEnvironmentVariable("TentacleJournal", Path.Combine(stagingDirectory, "DeploymentJournal.xml")); variables = new VariableDictionary(); variables.EnrichWithEnvironmentVariables(); variables.Set(SpecialVariables.Tentacle.Agent.ApplicationDirectoryPath, stagingDirectory); variables.Set("PreDeployGreeting", "Bonjour"); }
public void SetUp() { fileSystem = CalamariPhysicalFileSystem.GetPhysicalFileSystem(); // Ensure staging directory exists and is empty stagingDirectory = Path.Combine(Path.GetTempPath(), "CalamariTestStaging"); customDirectory = Path.Combine(Path.GetTempPath(), "CalamariTestCustom"); fileSystem.EnsureDirectoryExists(stagingDirectory); fileSystem.PurgeDirectory(stagingDirectory, FailureOptions.ThrowOnFailure); Environment.SetEnvironmentVariable("TentacleJournal", Path.Combine(stagingDirectory, "DeploymentJournal.xml" )); variables = new VariableDictionary(); variables.EnrichWithEnvironmentVariables(); variables.Set(SpecialVariables.Tentacle.Agent.ApplicationDirectoryPath, stagingDirectory); variables.Set("PreDeployGreeting", "Bonjour"); }
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)); }
public virtual void SetUp() { fileSystem = CalamariPhysicalFileSystem.GetPhysicalFileSystem(); log = new InMemoryLog(); // Ensure staging directory exists and is empty applicationDirectory = Path.Combine(Path.GetTempPath(), "CalamariTestStaging"); fileSystem.EnsureDirectoryExists(applicationDirectory); fileSystem.PurgeDirectory(applicationDirectory, FailureOptions.ThrowOnFailure); Environment.SetEnvironmentVariable("TentacleJournal", Path.Combine(applicationDirectory, "DeploymentJournal.xml")); sourcePackage = TestEnvironment.GetTestPath("Java", "Fixtures", "Deployment", "Packages", "HelloWorld.0.0.1.jar"); }
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); } }
public void SetUp() { fileSystem = CalamariPhysicalFileSystem.GetPhysicalFileSystem(); // Ensure tenticle directory exists tentacleDirectory = Path.Combine(Path.GetTempPath(), "CalamariTestTentacle"); var tentacleHiddenDirectory = Path.Combine(tentacleDirectory, ".tentacle"); fileSystem.EnsureDirectoryExists(tentacleDirectory); fileSystem.EnsureDirectoryExists(tentacleHiddenDirectory); fileSystem.PurgeDirectory(tentacleHiddenDirectory, FailureOptions.ThrowOnFailure); Environment.SetEnvironmentVariable("TentacleJournal", Path.Combine(tentacleHiddenDirectory, "DeploymentJournal.xml")); Environment.SetEnvironmentVariable("TentacleHome", tentacleHiddenDirectory); variables = new VariableDictionary(); variables.EnrichWithEnvironmentVariables(); deploymentJournal = new DeploymentJournal(fileSystem, SemaphoreFactory.Get(), variables); packagesDirectory = Path.Combine(Path.GetTempPath(), "CalamariTestPackages"); fileSystem.EnsureDirectoryExists(packagesDirectory); stagingDirectory = Path.Combine(Path.GetTempPath(), "CalamariTestStaging"); fileSystem.EnsureDirectoryExists(stagingDirectory); // Create some artificats const string retentionPolicySet1 = "retentionPolicySet1"; CreateDeployment(Path.Combine(packagesDirectory, "Acme.1.0.0.nupkg"), Path.Combine(stagingDirectory, "Acme.1.0.0"), new DateTimeOffset(new DateTime(2015, 01, 26), new TimeSpan(10, 0, 0)), retentionPolicySet1); CreateDeployment(Path.Combine(packagesDirectory, "Acme.1.1.0.nupkg"), Path.Combine(stagingDirectory, "Acme.1.1.0"), new DateTimeOffset(new DateTime(2015, 02, 01), new TimeSpan(10, 0, 0)), retentionPolicySet1); CreateDeployment(Path.Combine(packagesDirectory, "Acme.1.2.0.nupkg"), Path.Combine(stagingDirectory, "Acme.1.2.0"), new DateTimeOffset(new DateTime(2015, 02, 10), new TimeSpan(10, 0, 0)), retentionPolicySet1); }
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 ); } }