示例#1
0
 public void SetUp()
 {
     tempDirectory = fileSystem.CreateTemporaryDirectory();
     nginxServer   = Substitute.For <NginxServer>();
     nginxServer.GetConfigRootDirectory().Returns("/etc/nginx/conf.d");
     nginxServer.GetSslRootDirectory().Returns("/etc/ssl");
 }
示例#2
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");
            }
        }
示例#4
0
        PackagePhysicalFileMetadata DownloadChart(string packageId, IVersion version, Uri feedUri,
                                                  ICredentials feedCredentials, string cacheDirectory)
        {
            var cred = feedCredentials.GetCredential(feedUri, "basic");

            var tempDirectory = fileSystem.CreateTemporaryDirectory();

            using (new TemporaryDirectory(tempDirectory))
            {
                var homeDir = Path.Combine(tempDirectory, "helm");
                if (!Directory.Exists(homeDir))
                {
                    Directory.CreateDirectory(homeDir);
                }
                var stagingDir = Path.Combine(tempDirectory, "staging");
                if (!Directory.Exists(stagingDir))
                {
                    Directory.CreateDirectory(stagingDir);
                }

                var log = new LogWrapper();
                Invoke($"init --home \"{homeDir}\" --client-only", tempDirectory, log);
                Invoke($"repo add --home \"{homeDir}\" {(string.IsNullOrEmpty(cred.UserName) ? "" : $"--username \"{cred.UserName}\" --password \"{cred.Password}\"")} {TempRepoName} {feedUri.ToString()}", tempDirectory, log);
                Invoke($"fetch --home \"{homeDir}\"  --version \"{version}\" --destination \"{stagingDir}\" {TempRepoName}/{packageId}", tempDirectory, log);

                var localDownloadName =
                    Path.Combine(cacheDirectory, PackageName.ToCachedFileName(packageId, version, Extension));

                fileSystem.MoveFile(Directory.GetFiles(stagingDir)[0], localDownloadName);
                return(PackagePhysicalFileMetadata.Build(localDownloadName));
            }
示例#5
0
        public void Execute(RunningDeployment deployment)
        {
            var variables = deployment.Variables;

            var(rootLocation, additionalLocations) = GetLocations(variables);
            if (rootLocation == null)
            {
                throw new NginxMissingRootLocationException();
            }

            var enabledBindings    = GetEnabledBindings(variables).ToList();
            var sslCertificates    = GetSslCertificates(enabledBindings, variables);
            var customNginxSslRoot = variables.Get(SpecialVariables.Action.Nginx.SslRoot);

            /*
             * Previous versions of the NGINX step did not expose the ability to define the file names of the configuration
             * files, and instead used the Package ID. This meant that multi-tenanted deployments that shared the same
             * package would overwrite each other when deployed to the same machine.
             *
             * To retain compatibility with existing deployments, the Package ID is still used as a default file name.
             * But if the config name setting has been defined, that is used instead.
             *
             * See https://github.com/OctopusDeploy/Issues/issues/6216
             */
            var virtualServerName =
                string.IsNullOrWhiteSpace(variables.Get(SpecialVariables.Action.Nginx.Server.ConfigName))
                    ? variables.Get(PackageVariables.PackageId)
                    : variables.Get(SpecialVariables.Action.Nginx.Server.ConfigName);

            nginxServer
            .WithVirtualServerName(virtualServerName)
            .WithHostName(variables.Get(SpecialVariables.Action.Nginx.Server.HostName))
            .WithServerBindings(enabledBindings, sslCertificates, customNginxSslRoot)
            .WithRootLocation(rootLocation)
            .WithAdditionalLocations(additionalLocations);

            Log.Verbose("Building nginx configuration");
            var customNginxConfRoot = variables.Get(SpecialVariables.Action.Nginx.ConfigRoot);

            nginxServer.BuildConfiguration(customNginxConfRoot);

            Log.Verbose("Saving nginx configuration");
            var tempDirectory = fileSystem.CreateTemporaryDirectory();

            variables.Set("OctopusNginxFeatureTempDirectory", tempDirectory);
            nginxServer.SaveConfiguration(tempDirectory);
        }
示例#6
0
        private PackagePhysicalFileMetadata DownloadChart(string packageId, IVersion version, Uri feedUri,
                                                          ICredentials feedCredentials, string cacheDirectory)
        {
            var cred = feedCredentials.GetCredential(feedUri, "basic");

            var syntax = new[] { ScriptSyntax.PowerShell, ScriptSyntax.Bash }.First(syntx =>
                                                                                    scriptEngine.GetSupportedTypes().Contains(syntx));

            var tempDirectory = fileSystem.CreateTemporaryDirectory();

            using (new TemporaryDirectory(tempDirectory))
            {
                var file   = GetFetchScript(tempDirectory, syntax);
                var result = scriptEngine.Execute(new Script(file), new CalamariVariableDictionary()
                {
                    ["Password"] = cred.Password,
                    ["Username"] = cred.UserName,
                    ["Version"]  = version.OriginalString,
                    ["Url"]      = feedUri.ToString(),
                    ["Package"]  = packageId,
                }, commandLineRunner,
                                                  new Dictionary <string, string>());
                if (!result.HasErrors)
                {
                    var localDownloadName =
                        Path.Combine(cacheDirectory, PackageName.ToCachedFileName(packageId, version, Extension));

                    var packageFile = fileSystem.EnumerateFiles(Path.Combine(tempDirectory, "staging")).First();
                    fileSystem.MoveFile(packageFile, localDownloadName);
                    return(PackagePhysicalFileMetadata.Build(localDownloadName));
                }
                else
                {
                    throw new Exception("Unable to download chart");
                }
            }
        }