Esempio n. 1
0
        private static async Task ExecuteAsync(OutputContext output, FileInfo projectFile, List <string> outputs, bool force)
        {
            output.WriteBanner();

            var application = await ApplicationFactory.CreateApplicationAsync(output, projectFile);

            var steps = new List <ServiceExecutor.Step>();

            if (outputs.Count == 0 || outputs.Contains("container"))
            {
                steps.Add(new GenerateDockerfileStep()
                {
                    Force = force,
                });
            }

            if (outputs.Count == 0 || outputs.Contains("chart"))
            {
                steps.Add(new GenerateHelmChartStep());
            }

            var executor = new ServiceExecutor(output, application, steps);

            foreach (var service in application.Services)
            {
                if (service.IsMatchForProject(application, projectFile))
                {
                    await executor.ExecuteAsync(service);
                }
            }
        }
Esempio n. 2
0
        private static async Task ExecuteAsync(OutputContext output, FileInfo projectFile, string environment)
        {
            output.WriteBanner();

            var application = await ApplicationFactory.CreateApplicationAsync(output, projectFile);

            if (application.Globals.Registry?.Hostname == null)
            {
                throw new CommandException("A registry is required for push operations. run 'dotnet-opulence init'.");
            }

            var steps = new ServiceExecutor.Step[]
            {
                new CombineStep()
                {
                    Environment = environment,
                },
                new BuildDockerImageStep()
                {
                    Environment = environment,
                },
                new PushDockerImageStep()
                {
                    Environment = environment,
                },
            };

            var executor = new ServiceExecutor(output, application, steps);

            foreach (var service in application.Services)
            {
                if (service.IsMatchForProject(application, projectFile))
                {
                    await executor.ExecuteAsync(service);
                }
            }
        }
Esempio n. 3
0
        private static async Task ExecuteAsync(OutputContext output, DirectoryInfo directory)
        {
            output.WriteBanner();

            string?solutionFilePath = null;
            string?opulenceFilePath = null;

            using (var step = output.BeginStep("Looking For Existing Config..."))
            {
                opulenceFilePath = DirectorySearch.AscendingSearch(directory.FullName, "Opulence.csx");
                if (opulenceFilePath != null)
                {
                    output.WriteInfoLine($"Found 'Opulence.csx' at '{opulenceFilePath}'");
                    step.MarkComplete();
                    return;
                }
                else
                {
                    output.WriteInfoLine("Not Found");
                    step.MarkComplete();
                }
            }

            using (var step = output.BeginStep("Looking For .sln File..."))
            {
                solutionFilePath = DirectorySearch.AscendingWildcardSearch(directory.FullName, "*.sln").FirstOrDefault()?.FullName;
                if (opulenceFilePath == null &&
                    solutionFilePath != null &&
                    output.Confirm($"Use '{Path.GetDirectoryName(solutionFilePath)}' as Root?"))
                {
                    opulenceFilePath = Path.Combine(Path.GetDirectoryName(solutionFilePath) !, "Opulence.csx");
                    step.MarkComplete();
                }
                else
                {
                    output.WriteInfoLine("Not Found.");
                    step.MarkComplete();
                }
            }

            if (opulenceFilePath == null &&
                Path.GetFullPath(directory.FullName) != Path.GetFullPath(Environment.CurrentDirectory))
            {
                // User specified a directory other than the current one
                using (var step = output.BeginStep("Trying Project Directory..."))
                {
                    if (output.Confirm("Use Project Directory as Root?"))
                    {
                        opulenceFilePath = Path.Combine(directory.FullName, "Opulence.csx");
                    }

                    step.MarkComplete();
                }
            }

            if (opulenceFilePath == null)
            {
                using (var step = output.BeginStep("Trying Current Directory..."))
                {
                    if (output.Confirm("Use Current Directory as Root?"))
                    {
                        opulenceFilePath = Path.Combine(directory.FullName, "Opulence.csx");
                    }

                    step.MarkComplete();
                }
            }

            if (opulenceFilePath == null)
            {
                throw new CommandException("Cannot Determine Root Directory.");
            }

            using (var step = output.BeginStep("Writing Opulence.csx ..."))
            {
                var hostname = output.Prompt("Enter the Container Registry (ex: 'example.azurecr.io' for Azure or 'example' for dockerhub)");

                var services = new List <(string, string)>();
                if (solutionFilePath != null && output.Confirm($"Use solution file '{solutionFilePath}' to initialize services?"))
                {
                    services.AddRange(ReadServicesFromSolution(solutionFilePath));
                    services.Sort((a, b) => a.Item1.CompareTo(b.Item1));
                }

                using var stream = File.OpenWrite(opulenceFilePath);
                using var writer = new StreamWriter(stream, Encoding.UTF8, leaveOpen: true);

                await WriteOpulenceConfigAsync(writer, hostname, services);

                output.WriteInfoLine($"Initialized Opulence Config at '{opulenceFilePath}'.");
                step.MarkComplete();
            }
        }
Esempio n. 4
0
        private static async Task ExecuteAsync(OutputContext output, FileInfo projectFile, DirectoryInfo outputDirectory, string environment, bool force)
        {
            output.WriteBanner();

            var application = await ApplicationFactory.CreateApplicationAsync(output, projectFile);

            var steps = new List <ServiceExecutor.Step>
            {
                new CombineStep()
                {
                    Environment = environment,
                },
                new BuildDockerImageStep()
                {
                    Environment = environment,
                },
            };

            if (application.Globals.DeploymentKind == DeploymentKind.None)
            {
                // No extra steps
            }
            else if (application.Globals.DeploymentKind == DeploymentKind.Kubernetes)
            {
                steps.Add(new GenerateKubernetesManifestStep()
                {
                    Environment = environment,
                });
            }
            else if (application.Globals.DeploymentKind == DeploymentKind.Oam)
            {
                steps.Add(new GenerateOamComponentStep()
                {
                    Environment = environment,
                });
            }
            else
            {
                throw new InvalidOperationException($"Unknown DeploymentKind: " + application.Globals.DeploymentKind);
            }

            // If this is command is for a project, then write out the component manifest
            // for just the project. We won't run the "application package" part.
            if (!string.Equals(".sln", projectFile.Extension, StringComparison.Ordinal))
            {
                steps.Add(new WriteServiceYamlStep()
                {
                    OutputDirectory = outputDirectory, Force = force,
                });
            }

            var executor = new ServiceExecutor(output, application, steps);

            foreach (var service in application.Services)
            {
                if (service.IsMatchForProject(application, projectFile))
                {
                    await executor.ExecuteAsync(service);
                }
            }

            if (string.Equals(".sln", projectFile.Extension, StringComparison.Ordinal))
            {
                await PackageApplicationAsync(output, application, outputDirectory, Path.GetFileNameWithoutExtension(projectFile.Name), environment);
            }
        }
Esempio n. 5
0
        private static async Task ExecuteAsync(OutputContext output, FileInfo projectFile, string environment)
        {
            output.WriteBanner();

            var application = await ApplicationFactory.CreateApplicationAsync(output, projectFile);

            if (application.Globals.Registry?.Hostname == null)
            {
                throw new CommandException("A registry is required for deploy operations. run 'dotnet-opulence init'.");
            }

            var steps = new List <ServiceExecutor.Step>()
            {
                new CombineStep()
                {
                    Environment = environment,
                },
                new BuildDockerImageStep()
                {
                    Environment = environment,
                },
                new PushDockerImageStep()
                {
                    Environment = environment,
                },
            };

            if (application.Globals.DeploymentKind == DeploymentKind.None)
            {
                // No extra steps
            }
            else if (application.Globals.DeploymentKind == DeploymentKind.Kubernetes)
            {
                steps.Add(new GenerateKubernetesManifestStep()
                {
                    Environment = environment,
                });
            }
            else if (application.Globals.DeploymentKind == DeploymentKind.Oam)
            {
                steps.Add(new GenerateOamComponentStep()
                {
                    Environment = environment,
                });
            }
            else
            {
                throw new InvalidOperationException($"Unknown DeploymentKind: " + application.Globals.DeploymentKind);
            }

            // If this is command is for a project, then deploy the component manifest
            // for just the project. We won't run the "application deploy" part.
            if (!string.Equals(".sln", projectFile.Extension, StringComparison.Ordinal))
            {
                steps.Add(new DeployServiceYamlStep()
                {
                    Environment = environment,
                });
            }

            var executor = new ServiceExecutor(output, application, steps);

            foreach (var service in application.Services)
            {
                if (service.IsMatchForProject(application, projectFile))
                {
                    await executor.ExecuteAsync(service);
                }
            }

            if (string.Equals(".sln", projectFile.Extension, StringComparison.Ordinal))
            {
                await PackageApplicationAsync(output, application, Path.GetFileNameWithoutExtension(projectFile.Name), environment);
            }
        }