mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-10 01:08:26 -04:00
NEW: add NadekoBot__creds env to specify alternative creds.yml
This commit is contained in:
@@ -39,6 +39,7 @@ COPY docker-entrypoint.sh /usr/local/sbin
|
|||||||
|
|
||||||
ENV shard_id=0
|
ENV shard_id=0
|
||||||
ENV total_shards=1
|
ENV total_shards=1
|
||||||
|
ENV NadekoBot__creds=/app/data/creds.yml
|
||||||
|
|
||||||
VOLUME [ "/app/data" ]
|
VOLUME [ "/app/data" ]
|
||||||
ENTRYPOINT [ "/usr/local/sbin/docker-entrypoint.sh" ]
|
ENTRYPOINT [ "/usr/local/sbin/docker-entrypoint.sh" ]
|
||||||
|
@@ -13,7 +13,15 @@ do
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
# fix folder permissions
|
# creds.yml migration
|
||||||
|
if [ -f /app/creds.yml ]; then
|
||||||
|
echo "Default location for creds.yml is now /app/data/creds.yml."
|
||||||
|
echo "Please move your creds.yml and update your docker-compose.yml accordingly."
|
||||||
|
|
||||||
|
export Nadeko_creds=/app/creds.yml
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ensure nadeko can write on /app/data
|
||||||
chown -R nadeko:nadeko "$data"
|
chown -R nadeko:nadeko "$data"
|
||||||
|
|
||||||
# drop to regular user and launch command
|
# drop to regular user and launch command
|
||||||
|
@@ -34,13 +34,13 @@ public sealed class Bot
|
|||||||
private readonly IBotCredsProvider _credsProvider;
|
private readonly IBotCredsProvider _credsProvider;
|
||||||
// private readonly InteractionService _interactionService;
|
// private readonly InteractionService _interactionService;
|
||||||
|
|
||||||
public Bot(int shardId, int? totalShards)
|
public Bot(int shardId, int? totalShards, string credPath = null)
|
||||||
{
|
{
|
||||||
if (shardId < 0)
|
if (shardId < 0)
|
||||||
throw new ArgumentOutOfRangeException(nameof(shardId));
|
throw new ArgumentOutOfRangeException(nameof(shardId));
|
||||||
|
|
||||||
ShardId = shardId;
|
ShardId = shardId;
|
||||||
_credsProvider = new BotCredsProvider(totalShards);
|
_credsProvider = new BotCredsProvider(totalShards, credPath);
|
||||||
_creds = _credsProvider.GetCreds();
|
_creds = _credsProvider.GetCreds();
|
||||||
|
|
||||||
_db = new(_credsProvider);
|
_db = new(_credsProvider);
|
||||||
|
@@ -25,4 +25,4 @@ if (args.Length > 0 && args[0] != "run")
|
|||||||
LogSetup.SetupLogger(shardId);
|
LogSetup.SetupLogger(shardId);
|
||||||
Log.Information("Pid: {ProcessId}", pid);
|
Log.Information("Pid: {ProcessId}", pid);
|
||||||
|
|
||||||
await new Bot(shardId, totalShards).RunAndBlockAsync();
|
await new Bot(shardId, totalShards, Environment.GetEnvironmentVariable("NadekoBot__creds")).RunAndBlockAsync();
|
@@ -18,11 +18,9 @@ public sealed class BotCredsProvider : IBotCredsProvider
|
|||||||
private const string CREDS_FILE_NAME = "creds.yml";
|
private const string CREDS_FILE_NAME = "creds.yml";
|
||||||
private const string CREDS_EXAMPLE_FILE_NAME = "creds_example.yml";
|
private const string CREDS_EXAMPLE_FILE_NAME = "creds_example.yml";
|
||||||
|
|
||||||
private string CredsPath
|
private string CredsPath { get; }
|
||||||
=> Path.Combine(Directory.GetCurrentDirectory(), CREDS_FILE_NAME);
|
|
||||||
|
|
||||||
private string CredsExamplePath
|
private string CredsExamplePath { get; }
|
||||||
=> Path.Combine(Directory.GetCurrentDirectory(), CREDS_EXAMPLE_FILE_NAME);
|
|
||||||
|
|
||||||
private readonly int? _totalShards;
|
private readonly int? _totalShards;
|
||||||
|
|
||||||
@@ -34,9 +32,21 @@ public sealed class BotCredsProvider : IBotCredsProvider
|
|||||||
private readonly object _reloadLock = new();
|
private readonly object _reloadLock = new();
|
||||||
private readonly IDisposable _changeToken;
|
private readonly IDisposable _changeToken;
|
||||||
|
|
||||||
public BotCredsProvider(int? totalShards = null)
|
public BotCredsProvider(int? totalShards = null, string credPath = null)
|
||||||
{
|
{
|
||||||
_totalShards = totalShards;
|
_totalShards = totalShards;
|
||||||
|
|
||||||
|
if (!string.IsNullOrWhiteSpace(credPath))
|
||||||
|
{
|
||||||
|
CredsPath = credPath;
|
||||||
|
CredsExamplePath = Path.Combine(Path.GetDirectoryName(credPath), CREDS_EXAMPLE_FILE_NAME);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CredsPath = Path.Combine(Directory.GetCurrentDirectory(), CREDS_FILE_NAME);
|
||||||
|
CredsExamplePath = Path.Combine(Directory.GetCurrentDirectory(), CREDS_EXAMPLE_FILE_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (!File.Exists(CredsExamplePath))
|
if (!File.Exists(CredsExamplePath))
|
||||||
|
Reference in New Issue
Block a user