Updated docker and repo check for no internet connection
This commit is contained in:
25
.dockerignore
Normal file
25
.dockerignore
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
**/.dockerignore
|
||||||
|
**/.env
|
||||||
|
**/.git
|
||||||
|
**/.gitignore
|
||||||
|
**/.project
|
||||||
|
**/.settings
|
||||||
|
**/.toolstarget
|
||||||
|
**/.vs
|
||||||
|
**/.vscode
|
||||||
|
**/.idea
|
||||||
|
**/*.*proj.user
|
||||||
|
**/*.dbmdl
|
||||||
|
**/*.jfm
|
||||||
|
**/azds.yaml
|
||||||
|
**/bin
|
||||||
|
**/charts
|
||||||
|
**/docker-compose*
|
||||||
|
**/Dockerfile*
|
||||||
|
**/node_modules
|
||||||
|
**/npm-debug.log
|
||||||
|
**/obj
|
||||||
|
**/secrets.dev.yaml
|
||||||
|
**/values.dev.yaml
|
||||||
|
LICENSE
|
||||||
|
README.md
|
||||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -453,4 +453,5 @@ $RECYCLE.BIN/
|
|||||||
!.vscode/launch.json
|
!.vscode/launch.json
|
||||||
!.vscode/extensions.json
|
!.vscode/extensions.json
|
||||||
|
|
||||||
/DiscordBotWebUI/Data
|
/DiscordBotWebUI/Data
|
||||||
|
/DiscordBot/Data
|
||||||
@@ -11,6 +11,7 @@
|
|||||||
<PublishAot>False</PublishAot>
|
<PublishAot>False</PublishAot>
|
||||||
<FileVersion>1.0.4.0</FileVersion>
|
<FileVersion>1.0.4.0</FileVersion>
|
||||||
<IsPackable>false</IsPackable>
|
<IsPackable>false</IsPackable>
|
||||||
|
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||||
<DebugType>full</DebugType>
|
<DebugType>full</DebugType>
|
||||||
@@ -42,4 +43,9 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\DiscordBotCore\DiscordBotCore.csproj" />
|
<ProjectReference Include="..\DiscordBotCore\DiscordBotCore.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Content Include="..\.dockerignore">
|
||||||
|
<Link>.dockerignore</Link>
|
||||||
|
</Content>
|
||||||
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
24
DiscordBot/Dockerfile
Normal file
24
DiscordBot/Dockerfile
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
|
||||||
|
USER $APP_UID
|
||||||
|
WORKDIR /app
|
||||||
|
EXPOSE 5055
|
||||||
|
|
||||||
|
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
|
||||||
|
ARG BUILD_CONFIGURATION=Release
|
||||||
|
WORKDIR /src
|
||||||
|
COPY ["DiscordBot/DiscordBot.csproj", "DiscordBot/"]
|
||||||
|
COPY ["DiscordBotCore/DiscordBotCore.csproj", "DiscordBotCore/"]
|
||||||
|
RUN dotnet restore "DiscordBot/DiscordBot.csproj"
|
||||||
|
COPY . .
|
||||||
|
WORKDIR "/src/DiscordBot"
|
||||||
|
RUN dotnet build "DiscordBot.csproj" -c $BUILD_CONFIGURATION -o /app/build
|
||||||
|
|
||||||
|
FROM build AS publish
|
||||||
|
ARG BUILD_CONFIGURATION=Release
|
||||||
|
RUN dotnet publish "DiscordBot.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
|
||||||
|
|
||||||
|
FROM base AS final
|
||||||
|
WORKDIR /app
|
||||||
|
COPY --from=publish /app/publish .
|
||||||
|
EXPOSE 5055
|
||||||
|
ENTRYPOINT ["dotnet", "DiscordBot.dll"]
|
||||||
@@ -24,6 +24,7 @@ public class Program
|
|||||||
await LoadComponents(args);
|
await LoadComponents(args);
|
||||||
await PrepareConsole();
|
await PrepareConsole();
|
||||||
await PluginMethods.RefreshPlugins(false);
|
await PluginMethods.RefreshPlugins(false);
|
||||||
|
|
||||||
await ConsoleInputHandler();
|
await ConsoleInputHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,7 +56,6 @@ public class Program
|
|||||||
AnsiConsole.MarkupLine("[yellow]Git SethBot: https://github.com/andreitdr/SethDiscordBot [/]");
|
AnsiConsole.MarkupLine("[yellow]Git SethBot: https://github.com/andreitdr/SethDiscordBot [/]");
|
||||||
|
|
||||||
AnsiConsole.MarkupLine("[yellow]Remember to close the bot using the shutdown command ([/][red]exit[/][yellow]) or some settings won't be saved[/]");
|
AnsiConsole.MarkupLine("[yellow]Remember to close the bot using the shutdown command ([/][red]exit[/][yellow]) or some settings won't be saved[/]");
|
||||||
AnsiConsole.MarkupLine($"[yellow]Running on [/][magenta]{(OperatingSystem.IsWindows() ? "Windows" : "Linux")}[/]");
|
|
||||||
|
|
||||||
AnsiConsole.MarkupLine("[yellow]===== Seth Discord Bot =====[/]");
|
AnsiConsole.MarkupLine("[yellow]===== Seth Discord Bot =====[/]");
|
||||||
|
|
||||||
@@ -118,7 +118,9 @@ public class Program
|
|||||||
if (!Application.CurrentApplication.ApplicationEnvironmentVariables.ContainsKey("ServerID") ||
|
if (!Application.CurrentApplication.ApplicationEnvironmentVariables.ContainsKey("ServerID") ||
|
||||||
!Application.CurrentApplication.ApplicationEnvironmentVariables.ContainsKey("token") ||
|
!Application.CurrentApplication.ApplicationEnvironmentVariables.ContainsKey("token") ||
|
||||||
!Application.CurrentApplication.ApplicationEnvironmentVariables.ContainsKey("prefix"))
|
!Application.CurrentApplication.ApplicationEnvironmentVariables.ContainsKey("prefix"))
|
||||||
|
{
|
||||||
await Installer.GenerateStartupConfig();
|
await Installer.GenerateStartupConfig();
|
||||||
|
}
|
||||||
|
|
||||||
if (args.Length > 0)
|
if (args.Length > 0)
|
||||||
{
|
{
|
||||||
@@ -127,7 +129,7 @@ public class Program
|
|||||||
if(args.Contains("--socket-api"))
|
if(args.Contains("--socket-api"))
|
||||||
Application.InitializeThreadedSockets();
|
Application.InitializeThreadedSockets();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ namespace DiscordBotCore
|
|||||||
{
|
{
|
||||||
if (!await OnlineFunctions.IsInternetConnected())
|
if (!await OnlineFunctions.IsInternetConnected())
|
||||||
{
|
{
|
||||||
Console.WriteLine("No internet connection detected. Exiting ...");
|
Console.WriteLine("The main repository server is not reachable. Please check your internet connection.");
|
||||||
Environment.Exit(0);
|
Environment.Exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,6 +95,24 @@ namespace DiscordBotCore
|
|||||||
CurrentApplication.InternalActionManager = new InternalActionManager();
|
CurrentApplication.InternalActionManager = new InternalActionManager();
|
||||||
await CurrentApplication.InternalActionManager.Initialize();
|
await CurrentApplication.InternalActionManager.Initialize();
|
||||||
|
|
||||||
|
if (OperatingSystem.IsWindows())
|
||||||
|
{
|
||||||
|
CurrentApplication.ApplicationEnvironmentVariables.Add("console.terminal", "cmd");
|
||||||
|
CurrentApplication.ApplicationEnvironmentVariables.Add("console.cmd_prefix", "/c ");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(OperatingSystem.IsLinux())
|
||||||
|
{
|
||||||
|
CurrentApplication.ApplicationEnvironmentVariables.Add("console.terminal", "bash");
|
||||||
|
CurrentApplication.ApplicationEnvironmentVariables.Add("console.cmd_prefix", string.Empty);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(OperatingSystem.IsMacOS())
|
||||||
|
{
|
||||||
|
CurrentApplication.ApplicationEnvironmentVariables.Add("console.terminal", "sh");
|
||||||
|
CurrentApplication.ApplicationEnvironmentVariables.Add("console.cmd_prefix", string.Empty);
|
||||||
|
}
|
||||||
|
|
||||||
IsRunning = true;
|
IsRunning = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,5 +164,10 @@ namespace DiscordBotCore
|
|||||||
var result = Path.Combine(_PluginsFolder, path);
|
var result = Path.Combine(_PluginsFolder, path);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void Log(string message, LogType? logType = LogType.Info)
|
||||||
|
{
|
||||||
|
CurrentApplication.Logger.Log(message, logType);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ internal static class OnlineFunctions
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
using var client = new HttpClient();
|
using var client = new HttpClient();
|
||||||
await client.GetStringAsync("https://www.google.com");
|
await client.GetStringAsync("files.wizzy-server.ro");
|
||||||
result = true;
|
result = true;
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
|
|||||||
@@ -13,8 +13,9 @@ namespace DiscordBotCore.Online;
|
|||||||
|
|
||||||
public sealed class PluginManager
|
public sealed class PluginManager
|
||||||
{
|
{
|
||||||
|
private static readonly string _LibrariesBaseFolder = "Libraries";
|
||||||
private readonly PluginRepository _PluginRepository;
|
private readonly PluginRepository _PluginRepository;
|
||||||
internal InstallingPluginInformation InstallingPluginInformation { get; private set; }
|
internal InstallingPluginInformation? InstallingPluginInformation { get; private set; }
|
||||||
|
|
||||||
public PluginManager(PluginRepository pluginRepository)
|
public PluginManager(PluginRepository pluginRepository)
|
||||||
{
|
{
|
||||||
@@ -41,8 +42,7 @@ public sealed class PluginManager
|
|||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// try to get the best matching plugin using the pluginName as a search query
|
|
||||||
PluginOnlineInfo? result = plugins.Find(pl => pl.Name.Contains(pluginName, StringComparison.CurrentCultureIgnoreCase));
|
PluginOnlineInfo? result = plugins.Find(pl => pl.Name.Contains(pluginName, StringComparison.CurrentCultureIgnoreCase));
|
||||||
if (result is null)
|
if (result is null)
|
||||||
{
|
{
|
||||||
@@ -62,9 +62,20 @@ public sealed class PluginManager
|
|||||||
|
|
||||||
public async Task ExecutePluginInstallScripts(List<OnlineScriptDependencyInfo> listOfDependencies)
|
public async Task ExecutePluginInstallScripts(List<OnlineScriptDependencyInfo> listOfDependencies)
|
||||||
{
|
{
|
||||||
string consoleType = OperatingSystem.IsWindows() ? "cmd.exe" : "bash";
|
string? console = Application.CurrentApplication.ApplicationEnvironmentVariables.Get<string>("console.terminal");
|
||||||
|
if (string.IsNullOrEmpty(console))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
string? cmd_prefix = Application.CurrentApplication.ApplicationEnvironmentVariables.Get<string>("console.cmd_prefix");
|
||||||
|
if (string.IsNullOrEmpty(cmd_prefix))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
foreach (var script in listOfDependencies)
|
foreach (var script in listOfDependencies)
|
||||||
await ServerCom.RunConsoleCommand(consoleType, "/c " + script.ScriptContent);
|
await ServerCom.RunConsoleCommand(console, $"{cmd_prefix}{script.ScriptContent}");
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task AppendPluginToDatabase(PluginInfo pluginData)
|
public async Task AppendPluginToDatabase(PluginInfo pluginData)
|
||||||
@@ -147,8 +158,8 @@ public sealed class PluginManager
|
|||||||
|
|
||||||
await RemovePluginFromDatabase(pluginInfo.PluginName);
|
await RemovePluginFromDatabase(pluginInfo.PluginName);
|
||||||
|
|
||||||
if (Directory.Exists($"Libraries/{pluginInfo.PluginName}"))
|
if (Directory.Exists($"{_LibrariesBaseFolder}/{pluginInfo.PluginName}"))
|
||||||
Directory.Delete($"Libraries/{pluginInfo.PluginName}", true);
|
Directory.Delete($"{_LibrariesBaseFolder}/{pluginInfo.PluginName}", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<string?> GetDependencyLocation(string dependencyName)
|
public async Task<string?> GetDependencyLocation(string dependencyName)
|
||||||
@@ -186,7 +197,7 @@ public sealed class PluginManager
|
|||||||
|
|
||||||
public string GenerateDependencyRelativePath(string pluginName, string dependencyPath)
|
public string GenerateDependencyRelativePath(string pluginName, string dependencyPath)
|
||||||
{
|
{
|
||||||
string relative = $"./Libraries/{pluginName}/{dependencyPath}";
|
string relative = $"./{_LibrariesBaseFolder}/{pluginName}/{dependencyPath}";
|
||||||
return relative;
|
return relative;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -242,11 +253,19 @@ public sealed class PluginManager
|
|||||||
{
|
{
|
||||||
foreach (var scriptDependency in pluginData.ScriptDependencies)
|
foreach (var scriptDependency in pluginData.ScriptDependencies)
|
||||||
{
|
{
|
||||||
string console = OperatingSystem.IsWindows() ? "start cmd.exe" : "bash";
|
string? console = Application.CurrentApplication.ApplicationEnvironmentVariables.Get<string>("console.terminal");
|
||||||
string arguments = OperatingSystem.IsWindows()
|
if (string.IsNullOrEmpty(console))
|
||||||
? $"/c {scriptDependency.ScriptContent}"
|
{
|
||||||
: scriptDependency.ScriptContent;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
string? cmdPrefix = Application.CurrentApplication.ApplicationEnvironmentVariables.Get<string>("console.cmd_prefix");
|
||||||
|
if (string.IsNullOrEmpty(cmdPrefix))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
string arguments = $"{cmdPrefix}{scriptDependency.ScriptContent}";
|
||||||
await ServerCom.RunConsoleCommand(console, arguments);
|
await ServerCom.RunConsoleCommand(console, arguments);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -288,14 +307,27 @@ public sealed class PluginManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (pluginData.HasScriptDependencies)
|
if (pluginData.HasScriptDependencies)
|
||||||
|
{
|
||||||
foreach (var scriptDependency in pluginData.ScriptDependencies)
|
foreach (var scriptDependency in pluginData.ScriptDependencies)
|
||||||
{
|
{
|
||||||
|
string? console = Application.CurrentApplication.ApplicationEnvironmentVariables.Get<string>("console.terminal");
|
||||||
|
if (string.IsNullOrEmpty(console))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
string? cmdPrefix = Application.CurrentApplication.ApplicationEnvironmentVariables.Get<string>("console.cmd_prefix");
|
||||||
|
if (string.IsNullOrEmpty(cmdPrefix))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
string console = OperatingSystem.IsWindows() ? "start cmd.exe" : "bash";
|
string arguments = $"{cmdPrefix}{scriptDependency.ScriptContent}";
|
||||||
string arguments = OperatingSystem.IsWindows() ? $"/c {scriptDependency.ScriptContent}" : scriptDependency.ScriptContent;
|
|
||||||
|
|
||||||
await ServerCom.RunConsoleCommand(console, arguments);
|
await ServerCom.RunConsoleCommand(console, arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
PluginInfo pluginInfo = PluginInfo.FromOnlineInfo(pluginData);
|
PluginInfo pluginInfo = PluginInfo.FromOnlineInfo(pluginData);
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ namespace DiscordBotCore.Repository;
|
|||||||
|
|
||||||
public sealed class PluginRepository : RepositoryBase
|
public sealed class PluginRepository : RepositoryBase
|
||||||
{
|
{
|
||||||
public static readonly PluginRepository Default = new PluginRepository("Testing", "https://wizzy-server.ro/SethDiscordBot/PluginsRepo", "PluginsList.json");
|
public static readonly PluginRepository Default = new PluginRepository("Testing", "https://files.wizzy-server.ro/SethDiscordBot/PluginsRepo", "PluginsList.json");
|
||||||
|
|
||||||
private PluginRepository(string repositoryName, string repositoryUrl, string databaseFile) : base(repositoryName, repositoryUrl, databaseFile)
|
private PluginRepository(string repositoryName, string repositoryUrl, string databaseFile) : base(repositoryName, repositoryUrl, databaseFile)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -21,6 +21,9 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Content Remove="Data\**" />
|
<Content Remove="Data\**" />
|
||||||
|
<Content Include="..\.dockerignore">
|
||||||
|
<Link>.dockerignore</Link>
|
||||||
|
</Content>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
23
DiscordBotWebUI/Dockerfile
Normal file
23
DiscordBotWebUI/Dockerfile
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
|
||||||
|
USER $APP_UID
|
||||||
|
WORKDIR /app
|
||||||
|
EXPOSE 8080
|
||||||
|
EXPOSE 8081
|
||||||
|
|
||||||
|
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
|
||||||
|
ARG BUILD_CONFIGURATION=Release
|
||||||
|
WORKDIR /src
|
||||||
|
COPY ["DiscordBotWebUI/DiscordBotWebUI.csproj", "DiscordBotWebUI/"]
|
||||||
|
RUN dotnet restore "DiscordBotWebUI/DiscordBotWebUI.csproj"
|
||||||
|
COPY . .
|
||||||
|
WORKDIR "/src/DiscordBotWebUI"
|
||||||
|
RUN dotnet build "DiscordBotWebUI.csproj" -c $BUILD_CONFIGURATION -o /app/build
|
||||||
|
|
||||||
|
FROM build AS publish
|
||||||
|
ARG BUILD_CONFIGURATION=Release
|
||||||
|
RUN dotnet publish "DiscordBotWebUI.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
|
||||||
|
|
||||||
|
FROM base AS final
|
||||||
|
WORKDIR /app
|
||||||
|
COPY --from=publish /app/publish .
|
||||||
|
ENTRYPOINT ["dotnet", "DiscordBotWebUI.dll"]
|
||||||
@@ -13,7 +13,7 @@ string logo =
|
|||||||
\___ \ / _ \ __| '_ \ | | | | / __|/ __/ _ \| '__/ _` | | _ < / _ \| __|
|
\___ \ / _ \ __| '_ \ | | | | / __|/ __/ _ \| '__/ _` | | _ < / _ \| __|
|
||||||
____) | __/ |_| | | | | |__| | \__ \ (_| (_) | | | (_| | | |_) | (_) | |_
|
____) | __/ |_| | | | | |__| | \__ \ (_| (_) | | | (_| | | |_) | (_) | |_
|
||||||
|_____/ \___|\__|_| |_| |_____/|_|___/\___\___/|_| \__,_| |____/ \___/ \__|
|
|_____/ \___|\__|_| |_| |_____/|_|___/\___\___/|_| \__,_| |____/ \___/ \__|
|
||||||
(WEB Edition)
|
(Official Web UI)
|
||||||
|
|
||||||
";
|
";
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,22 @@
|
|||||||
services:
|
services:
|
||||||
discordbotwebui:
|
discord-bot-client:
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: DiscordBot/Dockerfile
|
||||||
|
tty: true
|
||||||
|
stdin_open: true
|
||||||
|
|
||||||
|
discord-bot-webui:
|
||||||
build:
|
build:
|
||||||
context: .
|
context: .
|
||||||
dockerfile: DiscordBotWebUI/Dockerfile
|
dockerfile: DiscordBotWebUI/Dockerfile
|
||||||
|
|
||||||
|
|
||||||
|
networks:
|
||||||
|
custom_bridge:
|
||||||
|
driver: bridge
|
||||||
|
ipam:
|
||||||
|
driver: default
|
||||||
|
config:
|
||||||
|
- subnet: "172.20.100.0/24"
|
||||||
|
gateway: "172.20.100.1"
|
||||||
Reference in New Issue
Block a user