diff --git a/ProjectPlugins/CodexDiscordBotPlugin/CodexDiscordBotPlugin.cs b/ProjectPlugins/CodexDiscordBotPlugin/CodexDiscordBotPlugin.cs index feed993..14b80ee 100644 --- a/ProjectPlugins/CodexDiscordBotPlugin/CodexDiscordBotPlugin.cs +++ b/ProjectPlugins/CodexDiscordBotPlugin/CodexDiscordBotPlugin.cs @@ -1,5 +1,6 @@ using Core; using KubernetesWorkflow; +using Newtonsoft.Json; namespace CodexDiscordBotPlugin { @@ -31,15 +32,33 @@ namespace CodexDiscordBotPlugin public RunningContainer Deploy(DiscordBotStartupConfig config) { var workflow = tools.CreateWorkflow(); + var container = StartContainer(workflow, config); + WriteCodexDeploymentToContainerFile(workflow, container, config); + return container; + } + + private RunningContainer StartContainer(IStartupWorkflow workflow, DiscordBotStartupConfig config) + { var startupConfig = new StartupConfig(); startupConfig.NameOverride = config.Name; startupConfig.Add(config); var rc = workflow.Start(1, new DiscordBotContainerRecipe(), startupConfig); - - // write deployment into endpoints folder. - - return rc.Containers.Single(); } + + private void WriteCodexDeploymentToContainerFile(IStartupWorkflow workflow, RunningContainer rc, DiscordBotStartupConfig config) + { + var lines = JsonConvert.SerializeObject(config.CodexDeployment, Formatting.Indented).Split('\n'); + if (lines.Length < 10) throw new Exception("Didn't expect that."); + + var targetFile = DiscordBotContainerRecipe.EndpointsPath; + var op = ">"; + + foreach (var line in lines) + { + workflow.ExecuteCommand(rc, $"echo \"{line}\" {op} {targetFile}"); + op = ">>"; + } + } } }