Skip to content

Commit

Permalink
Merge pull request #11 from BattleBit-Gamenight/docker
Browse files Browse the repository at this point in the history
Implement dockerfile & docker-dompose
  • Loading branch information
Bims-sh authored Oct 5, 2024
2 parents b77e5a1 + d5144c2 commit 4b879f5
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 10 deletions.
25 changes: 25 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions BattleBitMiniGames.sln
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions BattleBitMinigames.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>BattleBitMinigames</RootNamespace>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CommunityServerAPI" Version="1.0.8.1" />
Expand Down
20 changes: 20 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
14 changes: 7 additions & 7 deletions Handlers/ConsoleCommandHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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.");
Expand Down
5 changes: 2 additions & 3 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -272,9 +272,8 @@ private static async Task OnGameServerConnected(GameServer<BattleBitPlayer> serv
await Task.CompletedTask;
}

private void StartCommandHandler()
private static void StartCommandHandler()
{
ConsoleCommandHandler commandHandler = new();
commandHandler.Listen();
ConsoleCommandHandler.Listen();
}
}
16 changes: 16 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
services:
battlebitminigames:
container_name: battlebitminigames
image: battlebitminigames
stdin_open: true
tty: true
build:
context: .
dockerfile: Dockerfile
volumes:
- "./bin/Debug/net6.0/appsettings.json:/app/appsettings.json"
networks:
- battlebit

networks:
battlebit:

0 comments on commit 4b879f5

Please sign in to comment.