Moves discord bot datafiles to volume
This commit is contained in:
parent
69296577f8
commit
4102ce0a04
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,5 +16,6 @@
|
|||
public string ServerName { get; }
|
||||
public string AdminRoleName { get; }
|
||||
public string AdminChannelName { get; }
|
||||
public string? DataPath { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,10 +21,9 @@ namespace BiblioTech
|
|||
var uniformArgs = new ArgsUniform<Configuration>(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<string> Validate()
|
||||
{
|
||||
var errors = new List<string>();
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue