From c3fb7384e33efb7f664dd86667bba4eef15940c4 Mon Sep 17 00:00:00 2001 From: benbierens Date: Mon, 11 Dec 2023 11:09:29 +0100 Subject: [PATCH] Sets up deploying discordbot with geth env vars --- .../DiscordBotContainerRecipe.cs | 8 +++++++ .../DiscordBotStartupConfig.cs | 24 ++++++++++++++++++- Tools/CodexNetDeployer/Deployer.cs | 17 ++++++++++--- 3 files changed, 45 insertions(+), 4 deletions(-) diff --git a/ProjectPlugins/CodexDiscordBotPlugin/DiscordBotContainerRecipe.cs b/ProjectPlugins/CodexDiscordBotPlugin/DiscordBotContainerRecipe.cs index 8a5dcd3..ea69f3b 100644 --- a/ProjectPlugins/CodexDiscordBotPlugin/DiscordBotContainerRecipe.cs +++ b/ProjectPlugins/CodexDiscordBotPlugin/DiscordBotContainerRecipe.cs @@ -22,6 +22,14 @@ namespace CodexDiscordBotPlugin AddEnvVar("KUBECONFIG", "/opt/kubeconfig.yaml"); AddEnvVar("KUBENAMESPACE", config.KubeNamespace); + var gethInfo = config.GethInfo; + AddEnvVar("GETH_HOST", gethInfo.Host); + AddEnvVar("GETH_HTTP_PORT", gethInfo.Port.ToString()); + AddEnvVar("GETH_PRIVATE_KEY", gethInfo.PrivKey); + AddEnvVar("CODEXCONTRACTS_MARKETPLACEADDRESS", gethInfo.MarketplaceAddress); + AddEnvVar("CODEXCONTRACTS_TOKENADDRESS", gethInfo.TokenAddress); + AddEnvVar("CODEXCONTRACTS_ABI", gethInfo.Abi); + if (!string.IsNullOrEmpty(config.DataPath)) { AddEnvVar("DATAPATH", config.DataPath); diff --git a/ProjectPlugins/CodexDiscordBotPlugin/DiscordBotStartupConfig.cs b/ProjectPlugins/CodexDiscordBotPlugin/DiscordBotStartupConfig.cs index e590cfa..85c103f 100644 --- a/ProjectPlugins/CodexDiscordBotPlugin/DiscordBotStartupConfig.cs +++ b/ProjectPlugins/CodexDiscordBotPlugin/DiscordBotStartupConfig.cs @@ -2,7 +2,7 @@ { public class DiscordBotStartupConfig { - public DiscordBotStartupConfig(string name, string token, string serverName, string adminRoleName, string adminChannelName, string kubeNamespace) + public DiscordBotStartupConfig(string name, string token, string serverName, string adminRoleName, string adminChannelName, string kubeNamespace, DiscordBotGethInfo gethInfo) { Name = name; Token = token; @@ -10,6 +10,7 @@ AdminRoleName = adminRoleName; AdminChannelName = adminChannelName; KubeNamespace = kubeNamespace; + GethInfo = gethInfo; } public string Name { get; } @@ -18,6 +19,27 @@ public string AdminRoleName { get; } public string AdminChannelName { get; } public string KubeNamespace { get; } + public DiscordBotGethInfo GethInfo { get; } public string? DataPath { get; set; } } + + public class DiscordBotGethInfo + { + public DiscordBotGethInfo(string host, int port, string privKey, string marketplaceAddress, string tokenAddress, string abi) + { + Host = host; + Port = port; + PrivKey = privKey; + MarketplaceAddress = marketplaceAddress; + TokenAddress = tokenAddress; + Abi = abi; + } + + public string Host { get; } + public int Port { get; } + public string PrivKey { get; } + public string MarketplaceAddress { get; } + public string TokenAddress { get; } + public string Abi { get; } + } } diff --git a/Tools/CodexNetDeployer/Deployer.cs b/Tools/CodexNetDeployer/Deployer.cs index bf993ef..1461784 100644 --- a/Tools/CodexNetDeployer/Deployer.cs +++ b/Tools/CodexNetDeployer/Deployer.cs @@ -82,7 +82,7 @@ namespace CodexNetDeployer var codexInstances = CreateCodexInstances(startResults); - var discordBotContainer = DeployDiscordBot(ci); + var discordBotContainer = DeployDiscordBot(ci, gethDeployment, contractsDeployment); return new CodexDeployment(codexInstances, gethDeployment, contractsDeployment, metricsService, discordBotContainer, CreateMetadata(startUtc)); } @@ -120,18 +120,29 @@ namespace CodexNetDeployer }); } - private RunningContainers? DeployDiscordBot(CoreInterface ci) + private RunningContainers? DeployDiscordBot(CoreInterface ci, GethDeployment gethDeployment, CodexContractsDeployment contractsDeployment) { if (!config.DeployDiscordBot) return null; Log("Deploying Discord bot..."); + var addr = gethDeployment.Container.GetInternalAddress(GethContainerRecipe.HttpPortTag); + var info = new DiscordBotGethInfo( + host: addr.Host, + port: addr.Port, + privKey: gethDeployment.Account.PrivateKey, + marketplaceAddress: contractsDeployment.MarketplaceAddress, + tokenAddress: contractsDeployment.TokenAddress, + abi: contractsDeployment.Abi + ); + var rc = ci.DeployCodexDiscordBot(new DiscordBotStartupConfig( name: "discordbot-" + config.DeploymentName, token: config.DiscordBotToken, serverName: config.DiscordBotServerName, adminRoleName: config.DiscordBotAdminRoleName, adminChannelName: config.DiscordBotAdminChannelName, - kubeNamespace: config.KubeNamespace) + kubeNamespace: config.KubeNamespace, + gethInfo: info) { DataPath = config.DiscordBotDataPath });