Removes codexdeployment from input of discord bot.

This commit is contained in:
benbierens 2023-10-24 13:48:24 +02:00
parent ade08a27fe
commit dfe477d192
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
4 changed files with 6 additions and 31 deletions

View File

@ -1,6 +1,5 @@
using Core; using Core;
using KubernetesWorkflow; using KubernetesWorkflow;
using Newtonsoft.Json;
namespace CodexDiscordBotPlugin namespace CodexDiscordBotPlugin
{ {
@ -22,7 +21,7 @@ namespace CodexDiscordBotPlugin
public void AddMetadata(IAddMetadata metadata) public void AddMetadata(IAddMetadata metadata)
{ {
metadata.Add("codexdiscordbotid", "todo"); metadata.Add("codexdiscordbotid", new DiscordBotContainerRecipe().Image);
} }
public void Decommission() public void Decommission()
@ -32,9 +31,7 @@ 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); return StartContainer(workflow, config);
WriteCodexDeploymentToContainerFile(workflow, container, config);
return container;
} }
private RunningContainer StartContainer(IStartupWorkflow workflow, DiscordBotStartupConfig config) private RunningContainer StartContainer(IStartupWorkflow workflow, DiscordBotStartupConfig config)
@ -45,20 +42,5 @@ namespace CodexDiscordBotPlugin
var rc = workflow.Start(1, new DiscordBotContainerRecipe(), startupConfig); var rc = workflow.Start(1, new DiscordBotContainerRecipe(), startupConfig);
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 = ">>";
}
}
} }
} }

View File

@ -4,7 +4,6 @@ namespace CodexDiscordBotPlugin
{ {
public class DiscordBotContainerRecipe : ContainerRecipeFactory public class DiscordBotContainerRecipe : ContainerRecipeFactory
{ {
public const string EndpointsPath = "/var/endpoints";
public override string AppName => "discordbot-bibliotech"; public override string AppName => "discordbot-bibliotech";
public override string Image => "thatbenbierens/codex-discordbot:initial"; public override string Image => "thatbenbierens/codex-discordbot:initial";
@ -15,8 +14,6 @@ namespace CodexDiscordBotPlugin
AddEnvVar("TOKEN", config.Token); AddEnvVar("TOKEN", config.Token);
AddEnvVar("SERVERNAME", config.ServerName); AddEnvVar("SERVERNAME", config.ServerName);
AddEnvVar("ADMINROLE", config.AdminRoleName); AddEnvVar("ADMINROLE", config.AdminRoleName);
AddEnvVar("ENDPOINTS", EndpointsPath);
} }
} }
} }

View File

@ -4,19 +4,17 @@ namespace CodexDiscordBotPlugin
{ {
public class DiscordBotStartupConfig public class DiscordBotStartupConfig
{ {
public DiscordBotStartupConfig(string name, string token, string serverName, string adminRoleName, CodexDeployment codexDeployment) public DiscordBotStartupConfig(string name, string token, string serverName, string adminRoleName)
{ {
Name = name; Name = name;
Token = token; Token = token;
ServerName = serverName; ServerName = serverName;
AdminRoleName = adminRoleName; AdminRoleName = adminRoleName;
CodexDeployment = codexDeployment;
} }
public string Name { get; } public string Name { get; }
public string Token { get; } public string Token { get; }
public string ServerName { get; } public string ServerName { get; }
public string AdminRoleName { get; } public string AdminRoleName { get; }
public CodexDeployment CodexDeployment { get; }
} }
} }

View File

@ -82,13 +82,12 @@ namespace CodexNetDeployer
var codexContainers = startResults.Select(s => s.CodexNode.Container).ToArray(); var codexContainers = startResults.Select(s => s.CodexNode.Container).ToArray();
var deployment = new CodexDeployment(codexContainers, gethDeployment, contractsDeployment, metricsService, null, CreateMetadata(startUtc)); var discordBotContainer = DeployDiscordBot(ci);
var discordBotContainer = DeployDiscordBot(ci, deployment);
return new CodexDeployment(codexContainers, gethDeployment, contractsDeployment, metricsService, discordBotContainer, CreateMetadata(startUtc)); return new CodexDeployment(codexContainers, gethDeployment, contractsDeployment, metricsService, discordBotContainer, CreateMetadata(startUtc));
} }
private RunningContainer? DeployDiscordBot(CoreInterface ci, CodexDeployment deployment) private RunningContainer? DeployDiscordBot(CoreInterface ci)
{ {
if (!config.DeployDiscordBot) return null; if (!config.DeployDiscordBot) return null;
Log("Deploying Discord bot..."); Log("Deploying Discord bot...");
@ -97,8 +96,7 @@ namespace CodexNetDeployer
name: "discordbot-" + config.DeploymentName, name: "discordbot-" + config.DeploymentName,
token: config.DiscordBotToken, token: config.DiscordBotToken,
serverName: config.DiscordBotServerName, serverName: config.DiscordBotServerName,
adminRoleName: config.DiscordBotAdminRoleName, adminRoleName: config.DiscordBotAdminRoleName));
deployment));
Log("Discord bot deployed."); Log("Discord bot deployed.");
return rc; return rc;