From 8acfefbaa389ecd2e3d559e50ae81b22a3505caa Mon Sep 17 00:00:00 2001 From: Bims Date: Sat, 5 Oct 2024 17:26:25 +0200 Subject: [PATCH 1/4] Add docker files --- .dockerignore | 25 +++++++++++++++++++++++++ BattleBitMinigames.csproj | 1 + Dockerfile | 20 ++++++++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..cd967fc --- /dev/null +++ b/.dockerignore @@ -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 \ No newline at end of file diff --git a/BattleBitMinigames.csproj b/BattleBitMinigames.csproj index ed6f5f1..3159c13 100644 --- a/BattleBitMinigames.csproj +++ b/BattleBitMinigames.csproj @@ -5,6 +5,7 @@ enable enable BattleBitMinigames + Linux diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..1cb6f1f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,20 @@ +FROM mcr.microsoft.com/dotnet/runtime:6.0 AS base +WORKDIR /app + +FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build +ARG BUILD_CONFIGURATION=Release +WORKDIR /src +COPY ["BattleBitMinigames.csproj", "./"] +RUN dotnet restore "BattleBitMinigames.csproj" +COPY . . +WORKDIR "/src/" +RUN dotnet build "BattleBitMinigames.csproj" -c $BUILD_CONFIGURATION -o /app/build + +FROM build AS publish +ARG BUILD_CONFIGURATION=Release +RUN dotnet publish "BattleBitMinigames.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false + +FROM base AS final +WORKDIR /app +COPY --from=publish /app/publish . +ENTRYPOINT ["dotnet", "BattleBitMinigames.dll"] From cbaf8a090154c0b2313ad15f2786271f68f2668f Mon Sep 17 00:00:00 2001 From: Bims Date: Sat, 5 Oct 2024 17:26:55 +0200 Subject: [PATCH 2/4] add docker compose --- docker-compose.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 docker-compose.yml diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..8a32b5b --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,13 @@ +services: + battlebitminigames: + image: battlebitminigames + build: + context: . + dockerfile: Dockerfile + volumes: + - "./appsettings.json:/app/appsettings.json" + networks: + - battlebit + +networks: + battlebit: \ No newline at end of file From 5344f315179d37afa74e4403e9f3274a48ab11be Mon Sep 17 00:00:00 2001 From: Bims Date: Sat, 5 Oct 2024 17:33:48 +0200 Subject: [PATCH 3/4] add proper solution --- BattleBitMiniGames.sln | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 BattleBitMiniGames.sln diff --git a/BattleBitMiniGames.sln b/BattleBitMiniGames.sln new file mode 100644 index 0000000..4a05136 --- /dev/null +++ b/BattleBitMiniGames.sln @@ -0,0 +1,15 @@ +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{FA8F5709-D424-4435-AB63-E82CD78AFC05}") = "BattleBitMinigames", "BattleBitMinigames.csproj", "{AAECC0BF-4E85-4B20-AA90-11BC73D21F20}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {AAECC0BF-4E85-4B20-AA90-11BC73D21F20}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AAECC0BF-4E85-4B20-AA90-11BC73D21F20}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AAECC0BF-4E85-4B20-AA90-11BC73D21F20}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AAECC0BF-4E85-4B20-AA90-11BC73D21F20}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal \ No newline at end of file From d5144c2c954acbc17348cb451c6b7134144b6f8d Mon Sep 17 00:00:00 2001 From: Bims Date: Sat, 5 Oct 2024 17:39:53 +0200 Subject: [PATCH 4/4] make command handler static, allow stdin + tty --- Handlers/ConsoleCommandHandler.cs | 14 +++++++------- Program.cs | 5 ++--- docker-compose.yml | 5 ++++- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/Handlers/ConsoleCommandHandler.cs b/Handlers/ConsoleCommandHandler.cs index 8ddfc9d..e0d161d 100644 --- a/Handlers/ConsoleCommandHandler.cs +++ b/Handlers/ConsoleCommandHandler.cs @@ -2,16 +2,16 @@ namespace BattleBitMinigames.Handlers; -public class ConsoleCommandHandler +public static class ConsoleCommandHandler { - public void Listen() + public static void Listen() { while (true) { - string? command = Console.ReadLine(); + var command = Console.ReadLine(); if (command is null) { - Program.Logger.Warn("No std in stream available."); + Program.Logger.Warn("No stdin stream available."); Program.Logger.Error("Exiting..."); return; } @@ -22,12 +22,12 @@ public void Listen() continue; } - string[] commandParts = command.Split(" ", StringSplitOptions.RemoveEmptyEntries); + var commandParts = command.Split(" ", StringSplitOptions.RemoveEmptyEntries); if (commandParts.Length == 0) continue; - string commandName = commandParts[0]; + var commandName = commandParts[0]; - ConsoleCommand? consoleCommand = ConsoleCommandList.Commands.FirstOrDefault(c => c.Name == commandName); + var consoleCommand = ConsoleCommandList.Commands.FirstOrDefault(c => c.Name == commandName); if (consoleCommand == null) { Program.Logger.Error($"Command {commandName} not found."); diff --git a/Program.cs b/Program.cs index dd0906e..fc85958 100644 --- a/Program.cs +++ b/Program.cs @@ -272,9 +272,8 @@ private static async Task OnGameServerConnected(GameServer serv await Task.CompletedTask; } - private void StartCommandHandler() + private static void StartCommandHandler() { - ConsoleCommandHandler commandHandler = new(); - commandHandler.Listen(); + ConsoleCommandHandler.Listen(); } } \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 8a32b5b..79f8a66 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,11 +1,14 @@ services: battlebitminigames: + container_name: battlebitminigames image: battlebitminigames + stdin_open: true + tty: true build: context: . dockerfile: Dockerfile volumes: - - "./appsettings.json:/app/appsettings.json" + - "./bin/Debug/net6.0/appsettings.json:/app/appsettings.json" networks: - battlebit