Ejemplo n.º 1
0
        public StoredPackage GetPackage(PhysicalPackageMetadata metadata)
        {
            fileSystem.EnsureDirectoryExists(rootDirectory);

            foreach (var file in PackageFiles(metadata.PackageAndVersionSearchPattern))
            {
                var storedPackage = GetPackage(file);
                if (storedPackage == null)
                {
                    continue;
                }

                if (!string.Equals(storedPackage.Metadata.PackageId, metadata.PackageId, StringComparison.OrdinalIgnoreCase) ||
                    !VersionFactory.TryCreateVersion(storedPackage.Metadata.Version, out IVersion packageVersion, metadata.VersionFormat) ||
                    !packageVersion.Equals(VersionFactory.CreateVersion(metadata.Version, metadata.VersionFormat)))
                {
                    continue;
                }

                if (string.IsNullOrWhiteSpace(metadata.Hash))
                {
                    return(storedPackage);
                }

                if (metadata.Hash == storedPackage.Metadata.Hash)
                {
                    return(storedPackage);
                }
            }

            return(null);
        }
Ejemplo n.º 2
0
        public StoredPackage GetPackage(PackageMetadata metadata)
        {
            var name = GetNameOfPackage(metadata);

            fileSystem.EnsureDirectoryExists(rootDirectory);

            var files = fileSystem.EnumerateFilesRecursively(rootDirectory, name + ".nupkg-*");

            foreach (var file in files)
            {
                var storedPackage = GetPackage(file);
                if (storedPackage == null)
                {
                    continue;
                }

                if (!string.Equals(storedPackage.Metadata.Id, metadata.Id, StringComparison.OrdinalIgnoreCase) || !string.Equals(storedPackage.Metadata.Version, metadata.Version, StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }

                if (string.IsNullOrWhiteSpace(metadata.Hash))
                {
                    return(storedPackage);
                }

                if (metadata.Hash == storedPackage.Metadata.Hash)
                {
                    return(storedPackage);
                }
            }

            return(null);
        }
Ejemplo n.º 3
0
        void ExtractLayouts(Package package, PackageDefinition manifest, string workingDirectory)
        {
            var localContentDirectory = Path.Combine(workingDirectory, AzureCloudServiceConventions.PackageFolders.LocalContent);

            fileSystem.EnsureDirectoryExists(localContentDirectory);

            foreach (var layout in manifest.Layouts)
            {
                if (!layout.Name.StartsWith(AzureCloudServiceConventions.RoleLayoutPrefix))
                {
                    continue;
                }

                var layoutDirectory = Path.Combine(localContentDirectory, layout.Name.Substring(AzureCloudServiceConventions.RoleLayoutPrefix.Length));
                fileSystem.EnsureDirectoryExists(layoutDirectory);

                foreach (var fileDefinition in layout.FileDefinitions)
                {
                    var contentDefinition =
                        manifest.GetContentDefinition(fileDefinition.Description.DataContentReference);

                    var destinationFileName = Path.Combine(layoutDirectory, fileDefinition.FilePath.TrimStart('\\'));
                    ExtractPart(
                        package.GetPart(PackUriHelper.ResolvePartUri(new Uri("/", UriKind.Relative),
                                                                     contentDefinition.Description.DataStorePath)),
                        destinationFileName);
                }
            }
        }
Ejemplo n.º 4
0
        public PackagePhysicalFileMetadata DownloadPackage(string packageId,
                                                           IVersion version,
                                                           string feedId,
                                                           Uri feedUri,
                                                           string?feedUsername,
                                                           string?feedPassword,
                                                           bool forcePackageDownload,
                                                           int maxDownloadAttempts,
                                                           TimeSpan downloadAttemptBackoff)
        {
            var cacheDirectory = PackageDownloaderUtils.GetPackageRoot(feedId);

            fileSystem.EnsureDirectoryExists(cacheDirectory);

            if (!forcePackageDownload)
            {
                var downloaded = SourceFromCache(packageId, version, cacheDirectory);
                if (downloaded != null)
                {
                    Log.VerboseFormat("Package was found in cache. No need to download. Using file: '{0}'", downloaded.FullFilePath);
                    return(downloaded);
                }
            }

            return(DownloadPackage(packageId,
                                   version,
                                   feedUri,
                                   feedPassword,
                                   cacheDirectory,
                                   maxDownloadAttempts,
                                   downloadAttemptBackoff));
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
        public PackagePhysicalFileMetadata?GetPackage(string packageId, IVersion version, string hash)
        {
            fileSystem.EnsureDirectoryExists(GetPackagesDirectory());
            foreach (var file in PackageFiles(packageId, version))
            {
                var packageNameMetadata = PackageMetadata(file);
                if (packageNameMetadata == null)
                {
                    continue;
                }

                if (!string.Equals(packageNameMetadata.PackageId, packageId, StringComparison.OrdinalIgnoreCase) ||
                    !packageNameMetadata.Version.Equals(version))
                {
                    continue;
                }

                var physicalPackageMetadata = PackagePhysicalFileMetadata.Build(file, packageNameMetadata);

                if (string.IsNullOrWhiteSpace(hash) || hash == physicalPackageMetadata?.Hash)
                {
                    return(physicalPackageMetadata);
                }
            }

            return(null);
        }
Ejemplo n.º 7
0
        public void ExtractToStagingDirectory(PathToPackage?pathToPackage, IPackageExtractor?customPackageExtractor = null)
        {
            var targetPath = Path.Combine(Environment.CurrentDirectory, "staging");

            fileSystem.EnsureDirectoryExists(targetPath);
            Extract(pathToPackage, targetPath, PackageVariables.Output.InstallationDirectoryPath, customPackageExtractor);
        }
Ejemplo n.º 8
0
        public StoredPackage GetPackage(ExtendedPackageMetadata metadata)
        {
            var name = GetNameOfPackage(metadata);

            fileSystem.EnsureDirectoryExists(rootDirectory);

            foreach (var file in PackageFiles(name))
            {
                var storedPackage = GetPackage(file);
                if (storedPackage == null)
                {
                    continue;
                }

                if (!string.Equals(storedPackage.Metadata.Id, metadata.Id, StringComparison.OrdinalIgnoreCase) || NuGetVersion.Parse(storedPackage.Metadata.Version) != NuGetVersion.Parse(metadata.Version))
                {
                    continue;
                }

                if (string.IsNullOrWhiteSpace(metadata.Hash))
                {
                    return(storedPackage);
                }

                if (metadata.Hash == storedPackage.Metadata.Hash)
                {
                    return(storedPackage);
                }
            }

            return(null);
        }
Ejemplo n.º 9
0
        public string GetFileNameForPackage(string name, string prefix = null)
        {
            var fullPath = Path.Combine(GetPackageRoot(prefix), name + BitConverter.ToString(Guid.NewGuid().ToByteArray()).Replace("-", string.Empty) + ".nupkg");

            fileSystem.EnsureDirectoryExists(rootDirectory);

            return(fullPath);
        }
        string GetInitialExtractionDirectory(VariableDictionary variables)
        {
            var root = variables.Get(SpecialVariables.Tentacle.Agent.ApplicationDirectoryPath)
                       ?? variables.Evaluate("#{env:SystemDrive}\\Applications");

            root = AppendEnvironmentNameIfProvided(variables, root);
            fileSystem.EnsureDirectoryExists(root);
            fileSystem.EnsureDiskHasEnoughFreeSpace(root);
            return(root);
        }
Ejemplo n.º 11
0
        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")));
        }
Ejemplo n.º 12
0
        public PackagePhysicalFileMetadata DownloadPackage(
            string packageId,
            IVersion version,
            string feedId,
            Uri feedUri,
            ICredentials feedCredentials,
            bool forcePackageDownload,
            int maxDownloadAttempts,
            TimeSpan downloadAttemptBackoff)
        {
            ServicePointManager.SecurityProtocol |= (SecurityProtocolType)3072;
            var cacheDirectory = PackageDownloaderUtils.GetPackageRoot(feedId);

            fileSystem.EnsureDirectoryExists(cacheDirectory);

            if (!forcePackageDownload)
            {
                var downloaded = SourceFromCache(packageId, version, cacheDirectory);
                if (downloaded != null)
                {
                    Log.VerboseFormat("Package was found in cache. No need to download. Using file: '{0}'", downloaded.FullFilePath);
                    return(downloaded);
                }
            }

            return(DownloadPackage(packageId,
                                   version,
                                   feedUri,
                                   feedCredentials,
                                   cacheDirectory,
                                   maxDownloadAttempts,
                                   downloadAttemptBackoff));
        }
Ejemplo n.º 13
0
        void Write(IEnumerable <XElement> elements)
        {
            if (string.IsNullOrWhiteSpace(JournalPath))
            {
                throw new InvalidOperationException("JournalPath has not been set");
            }

            fileSystem.EnsureDirectoryExists(Path.GetDirectoryName(JournalPath));

            var tempPath = JournalPath + ".temp-" + Guid.NewGuid() + ".xml";

            var root     = new XElement("Deployments");
            var document = new XDocument(root);

            foreach (var element in elements)
            {
                root.Add(element);
            }

            using (var stream = fileSystem.OpenFile(tempPath, FileMode.Create, FileAccess.Write))
            {
                document.Save(stream);
            }

            fileSystem.OverwriteAndDelete(JournalPath, tempPath);
        }
Ejemplo n.º 14
0
        public void SetUp()
        {
            tempDirectory = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
            firstSensitiveVariablesFileName   = Path.Combine(tempDirectory, "firstVariableSet.secret");
            secondSensitiveVariablesFileName  = Path.Combine(tempDirectory, "secondVariableSet.secret");
            firstInsensitiveVariablesFileName = Path.ChangeExtension(firstSensitiveVariablesFileName, "json");
            fileSystem = CalamariPhysicalFileSystem.GetPhysicalFileSystem();
            fileSystem.EnsureDirectoryExists(tempDirectory);

            CreateSensitiveVariableFile();
            CreateInSensitiveVariableFile();

            options = CommonOptions.Parse(new[]
            {
                "Test",
                "--variables",
                firstInsensitiveVariablesFileName,
                "--sensitiveVariables",
                firstSensitiveVariablesFileName,
                "--sensitiveVariables",
                secondSensitiveVariablesFileName,
                "--sensitiveVariablesPassword",
                encryptionPassword
            });
        }
Ejemplo n.º 15
0
        public void ExtractToStagingDirectory(PathToPackage pathToPackage, IPackageExtractor customPackageExtractor = null)
        {
            var targetPath = Path.Combine(Environment.CurrentDirectory, "staging");

            fileSystem.EnsureDirectoryExists(targetPath);
            Extract(pathToPackage, targetPath, customPackageExtractor);
        }
        public void SetUp()
        {
            tempDirectory = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
            insensitiveVariablesFileName = Path.Combine(tempDirectory, "myVariables.json");
            sensitiveVariablesFileName   = Path.ChangeExtension(insensitiveVariablesFileName, "secret");
            fileSystem = CalamariPhysicalFileSystem.GetPhysicalFileSystem();
            fileSystem.EnsureDirectoryExists(tempDirectory);

            CreateSensitiveVariableFile();
            CreateInSensitiveVariableFile();
        }
Ejemplo n.º 17
0
        void Save()
        {
            var onlyJournalEntries = journalEntries.Select(p => p.Value);
            var json = JsonConvert.SerializeObject(new PackageData(onlyJournalEntries, Cache));

            fileSystem.EnsureDirectoryExists(Path.GetDirectoryName(journalPath));
            //save to temp file first
            var tempFilePath = $"{journalPath}.temp.{Guid.NewGuid()}.json";

            fileSystem.WriteAllText(tempFilePath, json, Encoding.UTF8);
            fileSystem.OverwriteAndDelete(journalPath, tempFilePath);
        }
        /// This will be specific to Tenant and/or Environment if these variables are available.
        static string GetEnvironmentApplicationDirectory(ICalamariFileSystem fileSystem, VariableDictionary variables)
        {
            var root = GetApplicationDirectoryRoot(fileSystem, variables);

            root = AppendTenantNameIfProvided(fileSystem, variables, root);
            root = AppendEnvironmentNameIfProvided(fileSystem, variables, root);

            fileSystem.EnsureDirectoryExists(root);
            fileSystem.EnsureDiskHasEnoughFreeSpace(root);

            return(root);
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Attempt to find a package id and version in the local cache
        /// </summary>
        /// <param name="packageId">The desired package id</param>
        /// <param name="version">The desired version</param>
        /// <param name="cacheDirectory">The location of cached files</param>
        /// <returns>The path to a cached version of the file, or null if none are found</returns>
        string SourceFromCache(
            string packageId,
            IVersion version,
            string cacheDirectory)
        {
            Guard.NotNullOrWhiteSpace(packageId, "packageId can not be null");
            Guard.NotNull(version, "version can not be null");
            Guard.NotNullOrWhiteSpace(cacheDirectory, "cacheDirectory can not be null");

            Log.VerboseFormat("Checking package cache for package {0} {1}", packageId, version.ToString());

            fileSystem.EnsureDirectoryExists(cacheDirectory);

            var filename = new MavenPackageID(packageId).FileSystemName;

            return(JarExtractor.EXTENSIONS
                   .Select(extension => filename + "*" + extension)
                   // Convert the search pattern to matching file paths
                   .SelectMany(searchPattern => fileSystem.EnumerateFilesRecursively(cacheDirectory, searchPattern))
                   // Filter out unparseable and unmatched results
                   .FirstOrDefault(file => FileMatchesDetails(file, packageId, version)));
        }
Ejemplo n.º 20
0
        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);
        }
Ejemplo n.º 21
0
        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);
        }
        // When a package has been installed once, Octopus gives users the ability to 'force' a redeployment of the package.
        // This is often useful for example if a deployment partially completes and the installation is in an invalid state
        // (e.g., corrupt files are left on disk, or the package is only half extracted). We *can't* just uninstall the package
        // or overwrite the files, since they might be locked by IIS or another process. So instead we create a new unique
        // directory.
        static string EnsureTargetPathExistsAndIsEmpty(string desiredTargetPath, ICalamariFileSystem fileSystem)
        {
            var target = desiredTargetPath;

            using (Semaphore.Acquire("Octopus.Calamari.ExtractionDirectory", "Another process is finding an extraction directory, please wait..."))
            {
                for (var i = 1; fileSystem.DirectoryExists(target) || fileSystem.FileExists(target); i++)
                {
                    target = desiredTargetPath + "_" + i;
                }

                fileSystem.EnsureDirectoryExists(target);
            }

            return(target);
        }
Ejemplo n.º 23
0
        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");
        }
Ejemplo n.º 24
0
        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");
        }
Ejemplo n.º 25
0
        public PackagePhysicalFileMetadata DownloadPackage(string packageId,
                                                           IVersion version,
                                                           string feedId,
                                                           Uri feedUri,
                                                           string?feedUsername,
                                                           string?feedPassword,
                                                           bool forcePackageDownload,
                                                           int maxDownloadAttempts,
                                                           TimeSpan downloadAttemptBackoff)
        {
            var cacheDirectory = PackageDownloaderUtils.GetPackageRoot(feedId);

            fileSystem.EnsureDirectoryExists(cacheDirectory);

            if (!forcePackageDownload)
            {
                var downloaded = SourceFromCache(packageId, version, cacheDirectory);
                if (downloaded != null)
                {
                    Log.VerboseFormat("Package was found in cache. No need to download. Using file: '{0}'", downloaded.FullFilePath);
                    return(downloaded);
                }
            }

            var feedCredentials = GetFeedCredentials(feedUsername, feedPassword);

            var package = GetChartDetails(feedUri, feedCredentials, packageId, CancellationToken.None);

            if (string.IsNullOrEmpty(package.PackageId))
            {
                throw new CommandException($"There was an error fetching the chart from the provided repository. The package id was not valid ({package.PackageId})");
            }

            var packageVersion = package.Versions.FirstOrDefault(v => version.Equals(v.Version));
            var foundUrl       = packageVersion?.Urls.FirstOrDefault();

            if (foundUrl == null)
            {
                throw new CommandException("Could not determine download url from chart repository. Please check associated index.yaml is correct.");
            }

            var packageUrl = foundUrl.IsValidUrl() ? new Uri(foundUrl, UriKind.Absolute) :  new Uri(feedUri, foundUrl);

            return(DownloadChart(packageUrl, packageId, version, feedCredentials, cacheDirectory));
        }
Ejemplo n.º 26
0
        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");
        }
Ejemplo n.º 27
0
        public void Install(RunningDeployment deployment)
        {
            var transferPath = CrossPlatform.ExpandPathEnvironmentVariables(deployment.Variables.Get(PackageVariables.TransferPath));
            fileSystem.EnsureDirectoryExists(transferPath);
            var fileName = deployment.Variables.Get(PackageVariables.OriginalFileName) ?? Path.GetFileName(deployment.PackageFilePath);
            var filePath = Path.Combine(transferPath, fileName);

            if (fileSystem.FileExists(filePath))
            {
                log.Info($"File {filePath} already exists so it will be attempted to be overwritten");
            }

            fileSystem.CopyFile(deployment.PackageFilePath, filePath);

           log.Info($"Copied package '{fileName}' to directory '{transferPath}'");
           log.SetOutputVariableButDoNotAddToVariables(PackageVariables.Output.DirectoryPath, transferPath);
           log.SetOutputVariableButDoNotAddToVariables(PackageVariables.Output.FileName, fileName);
           log.SetOutputVariableButDoNotAddToVariables(PackageVariables.Output.FilePath, filePath);
        }
Ejemplo n.º 28
0
        private void CreateDeployment(string extractedFrom, string extractedTo, DateTimeOffset date, string retentionPolicySet)
        {
            fileSystem.EnsureDirectoryExists(extractedTo);
            fileSystem.OverwriteFile(Path.Combine(extractedTo, "an_artifact.txt"), "lorem ipsum");
            fileSystem.OverwriteFile(extractedFrom, "lorem ipsum");

            deploymentJournal.AddJournalEntry(new JournalEntry(new XElement("Deployment",
                                                                            new XAttribute("Id", Guid.NewGuid().ToString()),
                                                                            new XAttribute("EnvironmentId", "blah"),
                                                                            new XAttribute("ProjectId", "blah"),
                                                                            new XAttribute("PackageId", "blah"),
                                                                            new XAttribute("PackageVersion", "blah"),
                                                                            new XAttribute("InstalledOn", date.UtcDateTime.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture)),
                                                                            new XAttribute("ExtractedFrom", extractedFrom),
                                                                            new XAttribute("ExtractedTo", extractedTo),
                                                                            new XAttribute("RetentionPolicySet", retentionPolicySet),
                                                                            new XAttribute("WasSuccessFul", true.ToString())
                                                                            )));
        }
Ejemplo n.º 29
0
        private void Write(IEnumerable <XElement> elements)
        {
            fileSystem.EnsureDirectoryExists(Path.GetDirectoryName(JournalPath));

            var tempPath = JournalPath + ".temp-" + Guid.NewGuid() + ".xml";

            var root     = new XElement("Deployments");
            var document = new XDocument(root);

            foreach (var element in elements)
            {
                root.Add(element);
            }

            using (var stream = fileSystem.OpenFile(tempPath, FileMode.Create, FileAccess.Write))
                document.Save(stream);

            fileSystem.OverwriteAndDelete(JournalPath, tempPath);
        }
        public void Install(RunningDeployment deployment)
        {
            var transferPath = deployment.Variables.GetEvironmentExpandedPath(SpecialVariables.Package.TransferPath);

            fileSystem.EnsureDirectoryExists(transferPath);
            var fileName = deployment.Variables.Get(SpecialVariables.Package.OriginalFileName) ?? Path.GetFileName(deployment.PackageFilePath);
            var filePath = Path.Combine(transferPath, fileName);

            if (fileSystem.FileExists(filePath))
            {
                Log.Info($"File {filePath} already exists so it will be attempted to be overwritten");
            }

            fileSystem.CopyFile(deployment.PackageFilePath, filePath);

            Log.Info($"Copied package '{fileName}' to directory '{transferPath}'");
            Log.SetOutputVariable(SpecialVariables.Package.Output.DirectoryPath, transferPath);
            Log.SetOutputVariable(SpecialVariables.Package.Output.FileName, fileName);
            Log.SetOutputVariable(SpecialVariables.Package.Output.FilePath, filePath);
        }
Ejemplo n.º 31
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);
        }