示例#1
0
        public static async Task BuildAsync(IConsole console, FileInfo path, Verbosity verbosity, bool interactive)
        {
            var output      = new OutputContext(console, verbosity);
            var application = await ApplicationFactory.CreateAsync(output, path);

            if (application.Services.Count == 0)
            {
                throw new CommandException($"No services found in \"{application.Source.Name}\"");
            }

            await ExecuteBuildAsync(output, application, environment : "production", interactive);
        }
示例#2
0
        public static async Task GenerateAsync(OutputContext output, FileInfo path, bool interactive, string ns, string?framework = null, ApplicationFactoryFilter?filter = null)
        {
            var application = await ApplicationFactory.CreateAsync(output, path, framework, filter);

            if (application.Services.Count == 0)
            {
                throw new CommandException($"No services found in \"{application.Source.Name}\"");
            }
            if (!string.IsNullOrEmpty(ns))
            {
                application.Namespace = ns;
            }
            await ExecuteGenerateAsync(output, application, environment : "production", interactive);
        }
示例#3
0
        public static async Task GenerateAsync(IConsole console, FileInfo path, Verbosity verbosity, bool interactive, string ns)
        {
            var output = new OutputContext(console, verbosity);

            output.WriteInfoLine("Loading Application Details...");
            var application = await ApplicationFactory.CreateAsync(output, path);

            if (application.Services.Count == 0)
            {
                throw new CommandException($"No services found in \"{application.Source.Name}\"");
            }
            if (!String.IsNullOrEmpty(ns))
            {
                application.Namespace = ns;
            }
            await ExecuteGenerateAsync(output, application, environment : "production", interactive);
        }
示例#4
0
        public static Command CreateDeployCommand()
        {
            var command = new Command("deploy", "deploy the application")
            {
                CommonArguments.Path_Required,
                StandardOptions.Interactive,
                StandardOptions.Verbosity,
                StandardOptions.Namespace,
                StandardOptions.Tags,
            };

            command.AddOption(new Option(new[] { "-f", "--force" })
            {
                Description = "Override validation and force deployment.",
                Required    = false
            });

            command.Handler = CommandHandler.Create <IConsole, FileInfo, Verbosity, bool, bool, string, string[]>(async(console, path, verbosity, interactive, force, @namespace, tags) =>
            {
                // Workaround for https://github.com/dotnet/command-line-api/issues/723#issuecomment-593062654
                if (path is null)
                {
                    throw new CommandException("No project or solution file was found.");
                }

                var output = new OutputContext(console, verbosity);

                output.WriteInfoLine("Loading Application Details...");

                var filter = ApplicationFactoryFilter.GetApplicationFactoryFilter(tags);

                var application = await ApplicationFactory.CreateAsync(output, path, filter);
                if (application.Services.Count == 0)
                {
                    throw new CommandException($"No services found in \"{application.Source.Name}\"");
                }
                if (!string.IsNullOrEmpty(@namespace))
                {
                    application.Namespace = @namespace;
                }
                await ExecuteDeployAsync(new OutputContext(console, verbosity), application, environment: "production", interactive, force);
            });

            return(command);
        }
示例#5
0
        public static Command CreateDeployCommand()
        {
            var command = new Command("deploy", "deploy the application")
            {
                CommonArguments.Path_Required,
                StandardOptions.Interactive,
                StandardOptions.Verbosity,
                StandardOptions.Namespace,
                StandardOptions.Framework,
                StandardOptions.Tags,
                StandardOptions.CreateForce("Override validation and force deployment.")
            };

            command.Handler = CommandHandler.Create <DeployCommandArguments>(async args =>
            {
                // Workaround for https://github.com/dotnet/command-line-api/issues/723#issuecomment-593062654
                if (args.Path is null)
                {
                    throw new CommandException("No project or solution file was found.");
                }

                var output = new OutputContext(args.Console, args.Verbosity);
                output.WriteInfoLine("Loading Application Details...");

                var filter = ApplicationFactoryFilter.GetApplicationFactoryFilter(args.Tags);

                var application = await ApplicationFactory.CreateAsync(output, args.Path, args.Framework, filter);
                if (application.Services.Count == 0)
                {
                    throw new CommandException($"No services found in \"{application.Source.Name}\"");
                }

                if (!string.IsNullOrEmpty(args.Namespace))
                {
                    application.Namespace = args.Namespace;
                }

                var executeOutput = new OutputContext(args.Console, args.Verbosity);
                await ExecuteDeployAsync(executeOutput, application, environment: "production", args.Interactive, args.Force);
            });

            return(command);
        }
示例#6
0
        public static async Task UndeployAsync(OutputContext output, FileInfo path, string @namespace, bool interactive, bool whatIf, ApplicationFactoryFilter?filter = null)
        {
            var watch = System.Diagnostics.Stopwatch.StartNew();

            var application = await ApplicationFactory.CreateAsync(output, path, null, filter);

            if (!string.IsNullOrEmpty(@namespace))
            {
                application.Namespace = @namespace;
            }

            await ExecuteUndeployAsync(output, application, @namespace, interactive, whatIf);

            watch.Stop();

            TimeSpan elapsedTime = watch.Elapsed;

            output.WriteAlwaysLine($"Time Elapsed: {elapsedTime.Hours:00}:{elapsedTime.Minutes:00}:{elapsedTime.Seconds:00}:{elapsedTime.Milliseconds / 10:00}");
        }
示例#7
0
        public static Command CreatePushCommand()
        {
            var command = new Command("push", "build and push application containers to registry")
            {
                CommonArguments.Path_Required,
                StandardOptions.Interactive,
                StandardOptions.Verbosity,
            };

            command.AddOption(new Option(new[] { "-f", "--force" })
            {
                Description = "Override validation and force push.",
                Required    = false
            });

            command.Handler = CommandHandler.Create <IConsole, FileInfo, Verbosity, bool, bool>(async(console, path, verbosity, interactive, force) =>
            {
                // Workaround for https://github.com/dotnet/command-line-api/issues/723#issuecomment-593062654
                if (path is null)
                {
                    throw new CommandException("No project or solution file was found.");
                }

                var output = new OutputContext(console, verbosity);

                output.WriteInfoLine("Loading Application Details...");
                var application = await ApplicationFactory.CreateAsync(output, path);
                if (application.Services.Count == 0)
                {
                    throw new CommandException($"No services found in \"{application.Source.Name}\"");
                }

                await ExecutePushAsync(new OutputContext(console, verbosity), application, environment: "production", interactive, force);
            });

            return(command);
        }
示例#8
0
        public static async Task UndeployAsync(IConsole console, FileInfo path, Verbosity verbosity, string @namespace, bool interactive, bool whatIf, string[] tags)
        {
            var watch = System.Diagnostics.Stopwatch.StartNew();

            var output = new OutputContext(console, verbosity);

            output.WriteInfoLine("Loading Application Details...");

            var filter      = ApplicationFactoryFilter.GetApplicationFactoryFilter(tags);
            var application = await ApplicationFactory.CreateAsync(output, path, filter);

            if (!string.IsNullOrEmpty(@namespace))
            {
                application.Namespace = @namespace;
            }

            await ExecuteUndeployAsync(output, application, @namespace, interactive, whatIf);

            watch.Stop();

            TimeSpan elapsedTime = watch.Elapsed;

            output.WriteAlwaysLine($"Time Elapsed: {elapsedTime.Hours:00}:{elapsedTime.Minutes:00}:{elapsedTime.Seconds:00}:{elapsedTime.Milliseconds / 10:00}");
        }
示例#9
0
        private static Command CreateRunCommand()
        {
            var command = new Command("run", "run the application")
            {
                CommonArguments.Path_Required,

                new Option("--no-build")
                {
                    Description = "Do not build project files before running.",
                    Required    = false
                },
                new Option("--port")
                {
                    Description = "The port to run control plane on.",
                    Argument    = new Argument <int?>("port"),
                    Required    = false
                },
                new Option("--logs")
                {
                    Description = "Write structured application logs to the specified log provider. Supported providers are 'console', 'elastic' (Elasticsearch), 'ai' (ApplicationInsights), 'seq'.",
                    Argument    = new Argument <string>("logs"),
                    Required    = false
                },
                new Option("--dtrace")
                {
                    Description = "Write distributed traces to the specified tracing provider. Supported providers are 'zipkin'.",
                    Argument    = new Argument <string>("trace"),
                    Required    = false,
                },
                new Option("--metrics")
                {
                    Description = "Write metrics to the specified metrics provider.",
                    Argument    = new Argument <string>("metrics"),
                    Required    = false
                },
                new Option("--debug")
                {
                    Argument = new Argument <string[]>("service")
                    {
                        Arity = ArgumentArity.ZeroOrMore,
                    },
                    Description = "Wait for debugger attach to specific service. Specify \"*\" to wait for all services.",
                    Required    = false
                },
                new Option("--docker")
                {
                    Description = "Run projects as docker containers.",
                    Required    = false
                },
                new Option("--dashboard")
                {
                    Description = "Launch dashboard on run.",
                    Required    = false
                },
                new Option("--watch")
                {
                    Description = "Watches for code changes for all dotnet projects.",
                    Required    = false
                },
                StandardOptions.Framework,
                StandardOptions.Tags,
                StandardOptions.Verbosity,
            };

            command.Handler = CommandHandler.Create <RunCommandArguments>(async args =>
            {
                // Workaround for https://github.com/dotnet/command-line-api/issues/723#issuecomment-593062654
                if (args.Path is null)
                {
                    throw new CommandException("No project or solution file was found.");
                }

                var output = new OutputContext(args.Console, args.Verbosity);

                output.WriteInfoLine("Loading Application Details...");

                var filter = ApplicationFactoryFilter.GetApplicationFactoryFilter(args.Tags);

                var application = await ApplicationFactory.CreateAsync(output, args.Path, args.Framework, filter);
                if (application.Services.Count == 0)
                {
                    throw new CommandException($"No services found in \"{application.Source.Name}\"");
                }

                var options = new HostOptions()
                {
                    Dashboard = args.Dashboard,
                    Docker    = args.Docker,
                    NoBuild   = args.NoBuild,
                    Port      = args.Port,

                    // parsed later by the diagnostics code
                    DistributedTraceProvider = args.Dtrace,
                    LoggingProvider          = args.Logs,
                    MetricsProvider          = args.Metrics,
                    LogVerbosity             = args.Verbosity,
                    Watch = args.Watch
                };
                options.Debug.AddRange(args.Debug);

                await application.ProcessExtensionsAsync(options, output, ExtensionContext.OperationKind.LocalRun);

                InitializeThreadPoolSettings(application.Services.Count);

                output.WriteInfoLine("Launching Tye Host...");
                output.WriteInfoLine(string.Empty);

                await using var host = new TyeHost(application.ToHostingApplication(), options);
                await host.RunAsync();
            });

            return(command);
        }
示例#10
0
        private static Command CreateRunCommand(string[] args)
        {
            var command = new Command("run", "run the application")
            {
                CommonArguments.Path_Required,
            };

            // TODO: We'll need to support a --build-args
            command.AddOption(new Option("--no-build")
            {
                Description = "Do not build project files before running.",
                Required    = false
            });

            command.AddOption(new Option("--port")
            {
                Description = "The port to run control plane on.",
                Argument    = new Argument <int>("port"),
                Required    = false
            });

            command.AddOption(new Option("--logs")
            {
                Description = "Write structured application logs to the specified log providers. Supported providers are console, elastic (Elasticsearch), ai (ApplicationInsights), seq.",
                Argument    = new Argument <string>("logs"),
                Required    = false
            });

            command.AddOption(new Option("--dtrace")
            {
                Description = "Write distributed traces to the specified providers. Supported providers are zipkin.",
                Argument    = new Argument <string>("logs"),
                Required    = false
            });

            command.AddOption(new Option("--debug")
            {
                Argument    = new Argument <string[]>("service"),
                Description = "Wait for debugger attach to specific service. Specify \"*\" to wait for all services.",
                Required    = false
            });

            command.AddOption(new Option("--docker")
            {
                Description = "Run projects as docker containers.",
                Required    = false
            });

            command.Handler = CommandHandler.Create <IConsole, FileInfo, string[]>(async(console, path, debug) =>
            {
                // Workaround for https://github.com/dotnet/command-line-api/issues/723#issuecomment-593062654
                if (path is null)
                {
                    throw new CommandException("No project or solution file was found.");
                }

                var output       = new OutputContext(console, Verbosity.Quiet);
                var application  = await ApplicationFactory.CreateAsync(output, path);
                var serviceCount = application.Services.Count;

                InitializeThreadPoolSettings(serviceCount);

                using var host = new TyeHost(application.ToHostingApplication(), args, debug);
                await host.RunAsync();
            });

            return(command);
        }