First attempt to send deployment json into discord bot container.
This commit is contained in:
parent
d4522f0d9c
commit
cc8a860f41
|
@ -1,5 +1,6 @@
|
||||||
using Core;
|
using Core;
|
||||||
using KubernetesWorkflow;
|
using KubernetesWorkflow;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace CodexDiscordBotPlugin
|
namespace CodexDiscordBotPlugin
|
||||||
{
|
{
|
||||||
|
@ -31,15 +32,33 @@ namespace CodexDiscordBotPlugin
|
||||||
public RunningContainer Deploy(DiscordBotStartupConfig config)
|
public RunningContainer Deploy(DiscordBotStartupConfig config)
|
||||||
{
|
{
|
||||||
var workflow = tools.CreateWorkflow();
|
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();
|
var startupConfig = new StartupConfig();
|
||||||
startupConfig.NameOverride = config.Name;
|
startupConfig.NameOverride = config.Name;
|
||||||
startupConfig.Add(config);
|
startupConfig.Add(config);
|
||||||
var rc = workflow.Start(1, new DiscordBotContainerRecipe(), startupConfig);
|
var rc = workflow.Start(1, new DiscordBotContainerRecipe(), startupConfig);
|
||||||
|
|
||||||
// write deployment into endpoints folder.
|
|
||||||
|
|
||||||
|
|
||||||
return rc.Containers.Single();
|
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 = ">>";
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue