From 4102ce0a0434c77b90474079b06cdd91e720f17b Mon Sep 17 00:00:00 2001 From: benbierens Date: Wed, 25 Oct 2023 11:53:33 +0200 Subject: [PATCH] Moves discord bot datafiles to volume --- .../DiscordBotContainerRecipe.cs | 7 ++++++ .../DiscordBotStartupConfig.cs | 1 + Tools/BiblioTech/Configuration.cs | 25 ++++++++++++++----- Tools/BiblioTech/Program.cs | 13 +++++++--- Tools/CodexNetDeployer/Configuration.cs | 3 +++ Tools/CodexNetDeployer/Deployer.cs | 5 +++- .../CodexNetDeployer/deploy-public-testnet.sh | 3 ++- 7 files changed, 45 insertions(+), 12 deletions(-) diff --git a/ProjectPlugins/CodexDiscordBotPlugin/DiscordBotContainerRecipe.cs b/ProjectPlugins/CodexDiscordBotPlugin/DiscordBotContainerRecipe.cs index 9d1ba0a4..74e44d65 100644 --- a/ProjectPlugins/CodexDiscordBotPlugin/DiscordBotContainerRecipe.cs +++ b/ProjectPlugins/CodexDiscordBotPlugin/DiscordBotContainerRecipe.cs @@ -1,4 +1,5 @@ using KubernetesWorkflow; +using Utils; namespace CodexDiscordBotPlugin { @@ -15,6 +16,12 @@ namespace CodexDiscordBotPlugin AddEnvVar("SERVERNAME", config.ServerName); AddEnvVar("ADMINROLE", config.AdminRoleName); AddEnvVar("ADMINCHANNELNAME", config.AdminChannelName); + + if (config.DataPath != null) + { + AddEnvVar("DATAPATH", config.DataPath); + AddVolume(config.DataPath, 1.GB()); + } } } } diff --git a/ProjectPlugins/CodexDiscordBotPlugin/DiscordBotStartupConfig.cs b/ProjectPlugins/CodexDiscordBotPlugin/DiscordBotStartupConfig.cs index 3d769a14..bb00a8de 100644 --- a/ProjectPlugins/CodexDiscordBotPlugin/DiscordBotStartupConfig.cs +++ b/ProjectPlugins/CodexDiscordBotPlugin/DiscordBotStartupConfig.cs @@ -16,5 +16,6 @@ public string ServerName { get; } public string AdminRoleName { get; } public string AdminChannelName { get; } + public string? DataPath { get; set; } } } diff --git a/Tools/BiblioTech/Configuration.cs b/Tools/BiblioTech/Configuration.cs index adebc8bd..10e134ea 100644 --- a/Tools/BiblioTech/Configuration.cs +++ b/Tools/BiblioTech/Configuration.cs @@ -10,16 +10,29 @@ namespace BiblioTech [Uniform("server-name", "sn", "SERVERNAME", true, "Name of the Discord server")] public string ServerName { get; set; } = string.Empty; - [Uniform("endpoints", "e", "ENDPOINTS", false, "Path where endpoint JSONs are located. Also accepts codex-deployment JSONs.")] - public string EndpointsPath { get; set; } = "endpoints"; - - [Uniform("userdata", "u", "USERDATA", false, "Path where user data files will be saved.")] - public string UserDataPath { get; set; } = "userdata"; - + [Uniform("datapath", "dp", "DATAPATH", false, "Root path where all data files will be saved.")] + public string DataPath { get; set; } = "datapath"; + [Uniform("admin-role", "a", "ADMINROLE", true, "Name of the Discord server admin role")] public string AdminRoleName { get; set; } = string.Empty; [Uniform("admin-channel-name", "ac", "ADMINCHANNELNAME", true, "Name of the Discord server channel where admin commands are allowed.")] public string AdminChannelName { get; set; } = "admin-channel"; + + public string EndpointsPath + { + get + { + return Path.Combine(DataPath, "endpoints"); + } + } + + public string UserDataPath + { + get + { + return Path.Combine(DataPath, "users"); + } + } } } diff --git a/Tools/BiblioTech/Program.cs b/Tools/BiblioTech/Program.cs index 0310057c..97926fff 100644 --- a/Tools/BiblioTech/Program.cs +++ b/Tools/BiblioTech/Program.cs @@ -21,10 +21,9 @@ namespace BiblioTech var uniformArgs = new ArgsUniform(PrintHelp, args); Config = uniformArgs.Parse(); - if (!Directory.Exists(Config.UserDataPath)) - { - Directory.CreateDirectory(Config.UserDataPath); - } + EnsurePath(Config.DataPath); + EnsurePath(Config.UserDataPath); + EnsurePath(Config.EndpointsPath); return new Program().MainAsync(); } @@ -71,5 +70,11 @@ namespace BiblioTech Console.WriteLine(msg.ToString()); return Task.CompletedTask; } + + private static void EnsurePath(string path) + { + if (Directory.Exists(path)) return; + Directory.CreateDirectory(path); + } } } diff --git a/Tools/CodexNetDeployer/Configuration.cs b/Tools/CodexNetDeployer/Configuration.cs index e09cf2b9..f021b120 100644 --- a/Tools/CodexNetDeployer/Configuration.cs +++ b/Tools/CodexNetDeployer/Configuration.cs @@ -116,6 +116,9 @@ namespace CodexNetDeployer [Uniform("dbot-adminchannelname", "dbotacn", "DBOTADMINCHANNELNAME", false, "Required if discord-bot is true. Name of the Discord channel in which admin commands are allowed.")] public string DiscordBotAdminChannelName { get; set; } = string.Empty; + [Uniform("dbot-datapath", "dbotdp", "DBOTDATAPATH", false, "Optional. Path in container where bot will save all data.")] + public string DiscordBotDataPath { get; set; } = string.Empty; + public List Validate() { var errors = new List(); diff --git a/Tools/CodexNetDeployer/Deployer.cs b/Tools/CodexNetDeployer/Deployer.cs index 73625ccc..5302d7a7 100644 --- a/Tools/CodexNetDeployer/Deployer.cs +++ b/Tools/CodexNetDeployer/Deployer.cs @@ -130,7 +130,10 @@ namespace CodexNetDeployer token: config.DiscordBotToken, serverName: config.DiscordBotServerName, adminRoleName: config.DiscordBotAdminRoleName, - adminChannelName: config.DiscordBotAdminChannelName)); + adminChannelName: config.DiscordBotAdminChannelName) + { + DataPath = config.DiscordBotDataPath + }); Log("Discord bot deployed."); return rc; diff --git a/Tools/CodexNetDeployer/deploy-public-testnet.sh b/Tools/CodexNetDeployer/deploy-public-testnet.sh index d30cbf5a..0b36c0a3 100644 --- a/Tools/CodexNetDeployer/deploy-public-testnet.sh +++ b/Tools/CodexNetDeployer/deploy-public-testnet.sh @@ -26,4 +26,5 @@ dotnet run \ --dbot-token=tokenhere \ --dbot-servername=namehere \ --dbot-adminrolename=alsonamehere \ - --dbot-adminchannelname=channelname + --dbot-adminchannelname=channelname \ + --dbot-datapath=/var/botdata