protected void FetchHelmDependencies(DeploymentRendererContext context)
        {
            var requirementsLockFile = context.WorkingDirectory.GetFilePath("requirements.lock");

            if (requirementsLockFile.Exists)
            {
                requirementsLockFile.Delete();
            }

            var processStartInfo = new ProcessStartInfo("helm")
            {
                WorkingDirectory       = context.WorkingDirectory.FullName,
                RedirectStandardError  = true,
                RedirectStandardOutput = true
            };

            processStartInfo.ArgumentList.Add("dependency");
            processStartInfo.ArgumentList.Add("build");

            var process = new Process()
            {
                StartInfo = processStartInfo
            };

            process.OutputDataReceived += (sender, args) => { /* do nothing */ };
            process.ErrorDataReceived  += (sender, args) => { /* do nothing */ };
            process.Start();
            process.WaitForExit();
        }
        public override void Render(DeploymentRendererContext context)
        {
            var helmContext = (HelmRendererContext)context;

            var processStartInfo = new ProcessStartInfo("helm");

            processStartInfo.ArgumentList.Add("template");
            processStartInfo.ArgumentList.Add(context.Name);
            processStartInfo.ArgumentList.Add(".");
            processStartInfo.WorkingDirectory = context.WorkingDirectory.FullName;

            helmContext.ValueFiles.ForEach(x =>
            {
                processStartInfo.ArgumentList.Add("-f");
                processStartInfo.ArgumentList.Add(x);
            });

            var namespaceName = context.Namespace;

            if (!string.IsNullOrEmpty(namespaceName))
            {
                processStartInfo.ArgumentList.Add("--namespace");
                processStartInfo.ArgumentList.Add(namespaceName);
            }

            var environmentalVariables = new List <string>();

            if (context.Cluster != null)
            {
                environmentalVariables.Add($"cluster={context.Cluster}");
            }

            if (context.Environment != null)
            {
                environmentalVariables.Add($"environment={context.Environment}");
            }

            if (context.SubVertical != null)
            {
                environmentalVariables.Add($"subvertical={context.SubVertical}");
            }

            if (context.Vertical != null)
            {
                environmentalVariables.Add($"vertical={context.Vertical}");
            }

            processStartInfo.ArgumentList.Add("--set-string");
            processStartInfo.ArgumentList.Add(string.Join(",", environmentalVariables));

            if (_globalArguments.Value.Verbose)
            {
                Console.WriteLine($"{processStartInfo.FileName} {string.Join(" ", processStartInfo.ArgumentList)}");
            }

            Process.Start(processStartInfo)?.WaitForExit();
        }
        public override void Initialize(DeploymentRendererContext context)
        {
            FetchHelmDependencies(context);
            var helmContext = (HelmRendererContext)context;

            if (helmContext.Chart != null)
            {
                Fetch(context);
            }
        }
        public override void Fetch(DeploymentRendererContext context)
        {
            var helmContext = (HelmRendererContext)context;
            var chart       = helmContext.Chart !;

            var processStartInfo = new ProcessStartInfo("helm")
            {
                WorkingDirectory = context.WorkingDirectory.FullName
            };

            processStartInfo.ArgumentList.Add("fetch");
            processStartInfo.ArgumentList.Add(chart.Name);

            chart.Version.IsNotNullOrEmpty(s =>
            {
                processStartInfo.ArgumentList.Add("--version");
                processStartInfo.ArgumentList.Add(s);
            });

            processStartInfo.ArgumentList.Add("--repo");
            processStartInfo.ArgumentList.Add(chart.Repository.Url);

            chart.Repository.Is <UsernamePasswordAuthHelmChartRepository>()
            .Do(authHelmChartRepository =>
            {
                processStartInfo.ArgumentList.Add("--username");
                processStartInfo.ArgumentList.Add(authHelmChartRepository.Credentials.UserName);
                processStartInfo.ArgumentList.Add("--password");
                processStartInfo.ArgumentList.Add(authHelmChartRepository.Credentials.Password);
            }
                );
            var chartOutputPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("D"));

            processStartInfo.ArgumentList.Add("--destination");
            processStartInfo.ArgumentList.Add(chartOutputPath);
            processStartInfo.ArgumentList.Add("--untar");

            var process = Process.Start(processStartInfo);

            if (process == null)
            {
                throw new InvalidOperationException("Could not fetch helm chart [failed to start process]");
            }

            process.WaitForExit();

            // helm always extracts the chart to a subfolder, so we get the first subdirectory
            var chartOutputDirectory = new DirectoryInfo(chartOutputPath);
            var chartDirectory       = chartOutputDirectory.GetDirectories().First();

            chartDirectory.CopyRecursive(context.WorkingDirectory);
        }
 public abstract void Render(DeploymentRendererContext context);
 public abstract void Initialize(DeploymentRendererContext context);