From 3db3ec72904660898a60ed6c2dbd4d1670c96b6d Mon Sep 17 00:00:00 2001 From: Stefano Gessa Date: Sat, 3 Aug 2024 07:23:54 +0700 Subject: [PATCH] =?UTF-8?q?=EF=BB=BFUpdate=20docker=20files=20(#205)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Update docker files * Update .NET * Add container to ingest metadata * Add container to process database seeding and file ingestion * Add entrypoint for db-seed container * Remove unused ENV variables * Clean up * Clean up --- .env.example | 1 + Maple2.Database.Seed/docker-entrypoint.sh | 13 ++ Maple2.Server.Game/Dockerfile | 4 +- Maple2.Server.Login/Dockerfile | 5 +- Maple2.Server.Web/Dockerfile | 4 +- Maple2.Server.World/Dockerfile | 5 +- Maple2.Tools/Dotenv.cs | 4 +- compose.yml | 140 ++++++++++++++++------ 8 files changed, 127 insertions(+), 49 deletions(-) create mode 100755 Maple2.Database.Seed/docker-entrypoint.sh diff --git a/.env.example b/.env.example index c2f2c0a5..64d9383e 100644 --- a/.env.example +++ b/.env.example @@ -1,5 +1,6 @@ # Maple2.File.Ingest +# To use with docker, rename MS2_DATA_FOLDER to MS2_DOCKER_DATA_FOLDER MS2_DATA_FOLDER=C:/Nexon/Library/maplestory2/ # Database connection diff --git a/Maple2.Database.Seed/docker-entrypoint.sh b/Maple2.Database.Seed/docker-entrypoint.sh new file mode 100755 index 00000000..97555720 --- /dev/null +++ b/Maple2.Database.Seed/docker-entrypoint.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +if [ ! -f /root/.dotnet/tools/dotnet-ef ]; then + echo -n 'Installing dotnet EF... ' + dotnet tool install --global dotnet-ef 2>&1 > /dev/null + echo 'done' +fi + +export PATH="$PATH:/root/.dotnet/tools" + +cd /app/Maple2.Database.Seed + +dotnet run diff --git a/Maple2.Server.Game/Dockerfile b/Maple2.Server.Game/Dockerfile index 3ee70ff2..11cf4abd 100644 --- a/Maple2.Server.Game/Dockerfile +++ b/Maple2.Server.Game/Dockerfile @@ -1,11 +1,11 @@ -FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base +FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base WORKDIR /app # Game Server #EXPOSE 20002 # Channel Service #EXPOSE 21002 -FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build +FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build WORKDIR /src COPY ["Maple2.Server.Game/Maple2.Server.Game.csproj", "Maple2.Server.Game/"] COPY ["Maple2.Tools/Maple2.Tools.csproj", "Maple2.Tools/"] diff --git a/Maple2.Server.Login/Dockerfile b/Maple2.Server.Login/Dockerfile index 76e0effb..108c696b 100644 --- a/Maple2.Server.Login/Dockerfile +++ b/Maple2.Server.Login/Dockerfile @@ -1,9 +1,9 @@ -FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base +FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base WORKDIR /app # Login Server EXPOSE 20001 -FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build +FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build WORKDIR /src COPY ["Maple2.Server.Login/Maple2.Server.Login.csproj", "Maple2.Server.Login/"] COPY ["Maple2.Tools/Maple2.Tools.csproj", "Maple2.Tools/"] @@ -21,4 +21,3 @@ RUN dotnet publish -r win-x64 "Maple2.Server.Login.csproj" -c Debug -o /app/publ FROM base AS final WORKDIR /app COPY --from=publish /app/publish . -ENTRYPOINT ["dotnet", "Maple2.Server.Login.dll"] diff --git a/Maple2.Server.Web/Dockerfile b/Maple2.Server.Web/Dockerfile index 03c14a77..41b0b234 100644 --- a/Maple2.Server.Web/Dockerfile +++ b/Maple2.Server.Web/Dockerfile @@ -1,11 +1,11 @@ -FROM mcr.microsoft.com/dotnet/runtime:7.0 AS base +FROM mcr.microsoft.com/dotnet/runtime:8.0 AS base WORKDIR /app # Web Service (HTTP) EXPOSE 80 # Web Service (HTTPS) # EXPOSE 443 -FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build +FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build WORKDIR /src COPY ["Maple2.Server.Web/Maple2.Server.Web.csproj", "Maple2.Server.Web/"] COPY ["Maple2.Database/Maple2.Database.csproj", "Maple2.Database/"] diff --git a/Maple2.Server.World/Dockerfile b/Maple2.Server.World/Dockerfile index 2bf7cd01..ea98ba23 100644 --- a/Maple2.Server.World/Dockerfile +++ b/Maple2.Server.World/Dockerfile @@ -1,9 +1,9 @@ -FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base +FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base WORKDIR /app # World Service, Global Service EXPOSE 21001 -FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build +FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build WORKDIR /src COPY ["Maple2.Server.World/Maple2.Server.World.csproj", "Maple2.Server.World/"] COPY ["Maple2.Tools/Maple2.Tools.csproj", "Maple2.Tools/"] @@ -21,4 +21,3 @@ RUN dotnet publish -r win-x64 "Maple2.Server.World.csproj" -c Debug -o /app/publ FROM base AS final WORKDIR /app COPY --from=publish /app/publish . -ENTRYPOINT ["dotnet", "Maple2.Server.World.dll"] diff --git a/Maple2.Tools/Dotenv.cs b/Maple2.Tools/Dotenv.cs index 82694484..c6be2cd0 100644 --- a/Maple2.Tools/Dotenv.cs +++ b/Maple2.Tools/Dotenv.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.IO; namespace Maple2.Tools; @@ -7,7 +7,7 @@ public static void Load() { string dotenv = Path.Combine(Paths.SOLUTION_DIR, ".env"); if (!File.Exists(dotenv)) { - throw new FileNotFoundException(".env file not found!"); + return; } foreach (string line in File.ReadAllLines(dotenv)) { diff --git a/compose.yml b/compose.yml index aa8112f3..90e70c7e 100644 --- a/compose.yml +++ b/compose.yml @@ -1,81 +1,147 @@ services: - world: - build: - context: . - dockerfile: ./Maple2.Server.World/Dockerfile - image: maple2-world:dev - ports: - - "21001:21001" + db-seed: + container_name: maple2-db-seed + image: mcr.microsoft.com/dotnet/sdk:8.0 + entrypoint: /app/Maple2.Database.Seed/docker-entrypoint.sh + depends_on: + - mysql + links: + - mysql + env_file: + - .env environment: - GAME_DB_CONNECTION: "Server=host.docker.internal;Database=game-server;User=root;Password=maplestory;oldguids=true" - DATA_DB_CONNECTION: "Server=host.docker.internal;Database=maple-data;User=root;Password=maplestory;oldguids=true" - CHANNEL_SERVICE: "game-main,game-alt" - GAME_IP: "127.0.0.1" - LOGIN_IP: "127.0.0.1" + DB_IP: mysql + volumes: + - .:/app + - dotnet_tools:/root/.dotnet/tools + + file-ingest: + container_name: maple2-file-ingest + image: mcr.microsoft.com/dotnet/sdk:8.0 + working_dir: /app/Maple2.File.Ingest + command: dotnet run + depends_on: + - mysql + links: + - mysql + env_file: + - .env + environment: + DB_IP: mysql + MS2_DATA_FOLDER: /ClientData + volumes: + - .:/app + - ${MS2_DOCKER_DATA_FOLDER}:/ClientData login: build: context: . dockerfile: ./Maple2.Server.Login/Dockerfile - image: maple2-login:dev + container_name: maple2-login + image: maple2/login + command: dotnet Maple2.Server.Login.dll depends_on: - - world + mysql: + condition: service_started + world: + condition: service_started ports: - - "20001:20001" + - 20001:20001 links: - - "world" + - world + env_file: + - .env environment: - GAME_DB_CONNECTION: "Server=host.docker.internal;Database=game-server;User=root;Password=maplestory;oldguids=true" - DATA_DB_CONNECTION: "Server=host.docker.internal;Database=maple-data;User=root;Password=maplestory;oldguids=true" - WORLD_SERVICE: "world" - LOGIN_IP: "127.0.0.1" - WEB_URI: "http://127.0.0.1" + DB_IP: mysql + WORLD_SERVICE: world + + world: + build: + context: . + dockerfile: ./Maple2.Server.World/Dockerfile + container_name: maple2-world + image: maple2/world + command: dotnet Maple2.Server.World.dll + depends_on: + - mysql + ports: + - 21001:21001 + env_file: + - .env + environment: + DB_IP: mysql + CHANNEL_SERVICE: "game-main,game-alt" game-main: build: context: . dockerfile: ./Maple2.Server.Game/Dockerfile - image: maple2-game:dev + image: maple2/game depends_on: + - mysql - world ports: - - "20002:20002" - - "21002:21002" + - 20002:20002 + - 21002:21002 + env_file: + - .env environment: - GAME_DB_CONNECTION: "Server=host.docker.internal;Database=game-server;User=root;Password=maplestory;oldguids=true" - DATA_DB_CONNECTION: "Server=host.docker.internal;Database=maple-data;User=root;Password=maplestory;oldguids=true" + DB_IP: mysql GAME_CHANNEL: 1 GAME_PORT: 20002 GRPC_CHANNEL_PORT: 21002 - WORLD_SERVICE: "world" + WORLD_SERVICE: world GAME_IP: "127.0.0.1" game-alt: build: context: . dockerfile: ./Maple2.Server.Game/Dockerfile - image: maple2-game:dev + image: maple2/game depends_on: + - mysql - world ports: - - "20003:20003" - - "21003:21003" + - 20003:20003 + - 21003:21003 + env_file: + - .env environment: - GAME_DB_CONNECTION: "Server=host.docker.internal;Database=game-server;User=root;Password=maplestory;oldguids=true" - DATA_DB_CONNECTION: "Server=host.docker.internal;Database=maple-data;User=root;Password=maplestory;oldguids=true" + DB_IP: mysql GAME_CHANNEL: 2 GAME_PORT: 20003 GRPC_CHANNEL_PORT: 21003 - WORLD_SERVICE: "world" + WORLD_SERVICE: world GAME_IP: "127.0.0.1" web: build: context: . dockerfile: ./Maple2.Server.Web/Dockerfile - image: maple2-web:dev + image: maple2/web + depends_on: + - mysql ports: - - "80:80" - - "443:443" + - 80:80 + - 443:443 + env_file: + - .env environment: - GAME_DB_CONNECTION: "Server=host.docker.internal;Database=game-server;User=root;Password=maplestory;oldguids=true" + DB_IP: mysql + + mysql: + image: mysql:8.0 + restart: unless-stopped + container_name: maple2-db + env_file: + - .env + environment: + MYSQL_ROOT_PASSWORD: ${DB_PASSWORD} + volumes: + - mysql:/var/lib/mysql + ports: + - 3306:3306 + +volumes: + dotnet_tools: + mysql: