First attempt to send deployment json into discord bot container.

This commit is contained in:
benbierens 2023-10-24 10:17:57 +02:00
parent d4522f0d9c
commit cc8a860f41
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
1 changed files with 23 additions and 4 deletions

View File

@ -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 = ">>";
}
}
}
}