예제 #1
0
        /// <summary>
        /// Download specified nuget packages and their dependencies
        /// </summary>
        /// <param name="configuration">The node configuration</param>
        private void InstallPackages(NodeStartUpConfiguration configuration)
        {
            var xmlDocument = new XmlDocument();
            xmlDocument.LoadXml("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<packages>\n</packages>\n");
            // ReSharper disable PossibleNullReferenceException
            var rootNode = xmlDocument.DocumentElement.SelectSingleNode("/packages");
            foreach (var package in configuration.Packages)
            {
                var packageNode = (XmlElement)rootNode.AppendChild(xmlDocument.CreateElement("package"));
                packageNode.SetAttribute("id", package.Id);
                packageNode.SetAttribute("version", package.Version);
            }

            xmlDocument.Save(Path.Combine(this.WorkingDirectory, "packages.config"));
            using (var process = new Process())
            {
                process.StartInfo.UseShellExecute = false;
                process.StartInfo.WorkingDirectory = Path.GetFullPath(this.WorkingDirectory);
                process.StartInfo.FileName = "nuget.exe";
                process.StartInfo.Arguments =
                    "install packages.config -PreRelease -NonInteractive -ConfigFile nuget.config -OutputDirectory packages -DisableParallelProcessing";
                process.Start();
                process.WaitForExit();

                if (process.ExitCode != 0)
                {
                    throw new Exception("Could not install packages");
                }
            }

            //Checking installation
            var installedPackages = Directory.GetDirectories(Path.Combine(this.WorkingDirectory, "packages")).Select(Path.GetFileName).ToList();
            var missedPackages = configuration.Packages
                .Where(p => installedPackages.All(d => !Regex.IsMatch(d, $"^{Regex.Escape(p.Id)}(\\.\\d+){{0,4}}(\\-[\\w\\d\\-]*)?$")))
                .ToList();
            foreach (var packageName in missedPackages)
            {
                Console.WriteLine($@"Package {packageName.Id} was not installed");
            }

            if (missedPackages.Any())
            {
                throw new Exception("Could not install packages");
            }
        }
예제 #2
0
        /// <summary>
        /// Sets NuGet configuration file from parameters
        /// </summary>
        /// <param name="configuration">Current node configuration</param>
        private void PrepareNuGetConfig(NodeStartUpConfiguration configuration)
        {
            var configPath = Path.Combine(this.WorkingDirectory, "nuget.config");

            File.Copy(
                // ReSharper disable once AssignNullToNotNullAttribute
                Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "nuget.exe"),
                Path.Combine(this.WorkingDirectory, "nuget.exe"));

            XmlDocument doc = new XmlDocument();
            doc.LoadXml(Resources.NugetConfig);
            var root = doc.SelectSingleNode("/configuration/packageSources");

            int index = 0;
            foreach (var packageSource in configuration.PackageSources)
            {
                var addNode = doc.CreateElement("add");
                addNode.SetAttribute("key", $"s{index++}");
                addNode.SetAttribute("value", packageSource);
                root?.AppendChild(addNode);
            }

            doc.Save(configPath);
        }
예제 #3
0
        /// <summary>
        /// Creates the runnable service from installed packages
        /// </summary>
        /// <param name="configuration">Current node configuration</param>
        private void CreateService(NodeStartUpConfiguration configuration)
        {
            Console.WriteLine(@"Creating service");
            var serviceDir = Path.Combine(this.WorkingDirectory, "service");
            Directory.CreateDirectory(serviceDir);

            var matches = new[]
                              {
                                  new Regex("(^|\\+)net45", RegexOptions.IgnoreCase),
                                  new Regex("(^|\\+)net40", RegexOptions.IgnoreCase),
                                  new Regex("(^|\\+)net35", RegexOptions.IgnoreCase),
                                  new Regex("(^|\\+)net20", RegexOptions.IgnoreCase),
                                  new Regex("(^|\\+)dotnet", RegexOptions.IgnoreCase),
                                  new Regex("(^|\\+)netcore45", RegexOptions.IgnoreCase),
                              };

            foreach (var directory in Directory.GetDirectories(Path.Combine(this.WorkingDirectory, "packages")))
            {
                if (!Directory.Exists(Path.Combine(directory, "lib")))
                {
                    continue;
                }

                var specificDirs = Directory.GetDirectories(Path.Combine(directory, "lib")).Select(d => d.Split(Path.DirectorySeparatorChar).Last()).ToList();

                var endDir =
                    matches
                        .Select(m => specificDirs.FirstOrDefault(m.IsMatch))
                        .FirstOrDefault(d => d != null);

                endDir = endDir != null ? Path.Combine(directory, "lib", endDir) : Path.Combine(directory, "lib");
                Console.WriteLine($@"Installing {Path.GetDirectoryName(directory)} from {endDir}");
                this.CopyFilesRecursively(new DirectoryInfo(endDir), new DirectoryInfo(Path.Combine(this.WorkingDirectory, "service")));
            }

            File.WriteAllText(Path.Combine(serviceDir, "akka.hocon"), configuration.Configuration);
            Console.WriteLine($@"General configuration: \n {configuration.Configuration}");

            // cluster self-join is not welcomed
            var seeds = configuration.Seeds.ToList();
            string startConfig = $@"{{
                ClusterKit.NodeManager.NodeTemplateVersion = {configuration.NodeTemplateVersion}
                ClusterKit.NodeManager.NodeTemplate = {configuration.NodeTemplate}
                ClusterKit.NodeManager.ContainerType = {this.ContainerType}
                ClusterKit.NodeManager.NodeId = { this.Uid }
                akka.cluster.seed-nodes = [{string.Join(", ", seeds.Select(s => $"\"{s}\""))}]
            }}";
            File.WriteAllText(Path.Combine(serviceDir, "start.hocon"), startConfig);
            Console.WriteLine($@"Start configuration: \n {startConfig}");
        }