Skip to content

Commit 01aef71

Browse files
committed
Add Docker
1 parent 031074d commit 01aef71

File tree

16 files changed

+177
-23
lines changed

16 files changed

+177
-23
lines changed

.dockerignore

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
**/.dockerignore
2+
**/.env
3+
**/.git
4+
**/.gitignore
5+
**/.project
6+
**/.settings
7+
**/.toolstarget
8+
**/.vs
9+
**/.vscode
10+
**/.idea
11+
**/*.*proj.user
12+
**/*.dbmdl
13+
**/*.jfm
14+
**/azds.yaml
15+
**/bin
16+
**/charts
17+
**/docker-compose*
18+
**/Dockerfile*
19+
**/node_modules
20+
**/npm-debug.log
21+
**/obj
22+
**/secrets.dev.yaml
23+
**/values.dev.yaml
24+
LICENSE
25+
README.md

Maple2.Database/Maple2.Database.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111

1212
<ItemGroup>
1313
<PackageReference Include="Caching.dll" Version="2.0.0.1" />
14-
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.5" />
15-
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="6.0.5" />
14+
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.6" />
15+
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="6.0.6" />
1616
<PackageReference Include="Wivuu.JsonPolymorphism" Version="1.0.16" />
1717
</ItemGroup>
1818

Maple2.File.Ingest/Program.cs

+6-2
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,19 @@
1111
const string env = "Live";
1212
const string xmlPath = @"C:\Nexon\Library\Library\maplestory2\appdata\Data\Xml.m2d";
1313
const string exportedPath = @"C:\Nexon\Library\Library\maplestory2\appdata\Data\Resource\Exported.m2d";
14-
const string connectionString = "Server=localhost;Database=maple-data;User=root;Password=maplestory";
1514

1615
Console.OutputEncoding = System.Text.Encoding.UTF8;
1716

17+
string? dataDbConnection = Environment.GetEnvironmentVariable("DATA_DB_CONNECTION");
18+
if (dataDbConnection == null) {
19+
throw new ArgumentException("DATA_DB_CONNECTION environment variable was not set");
20+
}
21+
1822
using var xmlReader = new M2dReader(xmlPath);
1923
using var exportedReader = new M2dReader(exportedPath);
2024

2125
DbContextOptions options = new DbContextOptionsBuilder()
22-
.UseMySql(connectionString, ServerVersion.AutoDetect(connectionString)).Options;
26+
.UseMySql(dataDbConnection, ServerVersion.AutoDetect(dataDbConnection)).Options;
2327

2428
using var metadataContext = new MetadataContext(options);
2529
metadataContext.Database.EnsureCreated();

Maple2.Server.Core/Constants/Target.cs

+2-5
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
namespace Maple2.Server.Core.Constants;
44

55
public static class Target {
6-
public const string GAME_DB_CONNECTION = "Server=localhost;Database=game-server;User=root;Password=maplestory";
7-
public const string DATA_DB_CONNECTION = "Server=localhost;Database=maple-data;User=root;Password=maplestory";
8-
96
public const string SEVER_NAME = "Paperwood";
107
public const string LOCALE = "NA";
118

@@ -17,8 +14,8 @@ public static class Target {
1714
public const ushort GAME_CHANNEL = 1;
1815

1916
public static readonly IPAddress GRPC_WORLD_IP = IPAddress.Loopback;
20-
public const ushort GRPC_WORLD_PORT = 20101;
17+
public const ushort GRPC_WORLD_PORT = 20100;
2118

2219
public static readonly IPAddress GRPC_CHANNEL_IP = IPAddress.Loopback;
23-
public const ushort GRPC_CHANNEL_PORT = 22101;
20+
public const ushort GRPC_CHANNEL_PORT = 22100;
2421
}

Maple2.Server.Core/Maple2.Server.Core.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99

1010
<ItemGroup>
1111
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="8.0.0" />
12-
<PackageReference Include="Google.Protobuf" Version="3.21.1" />
12+
<PackageReference Include="Google.Protobuf" Version="3.21.2" />
1313
<PackageReference Include="Grpc.AspNetCore.Server" Version="2.46.0" />
1414
<PackageReference Include="Grpc.Net.ClientFactory" Version="2.46.0" />
15-
<PackageReference Include="Grpc.Tools" Version="2.46.3">
15+
<PackageReference Include="Grpc.Tools" Version="2.47.0">
1616
<PrivateAssets>all</PrivateAssets>
1717
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1818
</PackageReference>

Maple2.Server.Core/Modules/DataDbModule.cs

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
using Autofac;
1+
using System;
2+
using Autofac;
23
using Maple2.Database.Context;
34
using Maple2.Database.Storage;
45
using Maple2.Model.Metadata;
5-
using Maple2.Server.Core.Constants;
66
using Microsoft.EntityFrameworkCore;
77
using Module = Autofac.Module;
88

@@ -12,8 +12,13 @@ public class DataDbModule : Module {
1212
private readonly DbContextOptions options;
1313

1414
public DataDbModule() {
15+
string? dataDbConnection = Environment.GetEnvironmentVariable("DATA_DB_CONNECTION");
16+
if (dataDbConnection == null) {
17+
throw new ArgumentException("DATA_DB_CONNECTION environment variable was not set");
18+
}
19+
1520
options = new DbContextOptionsBuilder()
16-
.UseMySql(Target.DATA_DB_CONNECTION, ServerVersion.AutoDetect(Target.DATA_DB_CONNECTION))
21+
.UseMySql(dataDbConnection, ServerVersion.AutoDetect(dataDbConnection))
1722
.Options;
1823
}
1924

Maple2.Server.Core/Modules/GameDbModule.cs

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
using System.Reflection;
1+
using System;
2+
using System.Reflection;
23
using Autofac;
34
using Maple2.Database.Storage;
4-
using Maple2.Server.Core.Constants;
55
using Microsoft.EntityFrameworkCore;
66
using Module = Autofac.Module;
77

@@ -13,8 +13,13 @@ public class GameDbModule : Module {
1313
private readonly DbContextOptions options;
1414

1515
public GameDbModule() {
16+
string? gameDbConnection = Environment.GetEnvironmentVariable("GAME_DB_CONNECTION");
17+
if (gameDbConnection == null) {
18+
throw new ArgumentException("GAME_DB_CONNECTION environment variable was not set");
19+
}
20+
1621
options = new DbContextOptionsBuilder()
17-
.UseMySql(Target.GAME_DB_CONNECTION, ServerVersion.AutoDetect(Target.GAME_DB_CONNECTION))
22+
.UseMySql(gameDbConnection, ServerVersion.AutoDetect(gameDbConnection))
1823
.Options;
1924
}
2025

Maple2.Server.Game/Dockerfile

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
2+
WORKDIR /app
3+
# Game Server
4+
EXPOSE 22001
5+
# Channel Service
6+
EXPOSE 22100
7+
8+
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
9+
WORKDIR /src
10+
COPY ["Maple2.Server.Game/Maple2.Server.Game.csproj", "Maple2.Server.Game/"]
11+
COPY ["Maple2.Tools/Maple2.Tools.csproj", "Maple2.Tools/"]
12+
COPY ["Maple2.Model/Maple2.Model.csproj", "Maple2.Model/"]
13+
COPY ["Maple2.Database/Maple2.Database.csproj", "Maple2.Database/"]
14+
COPY ["Maple2.Server.Core/Maple2.Server.Core.csproj", "Maple2.Server.Core/"]
15+
COPY ["Maple2.Script/Maple2.Script.csproj", "Maple2.Script/"]
16+
RUN dotnet restore "Maple2.Server.Game/Maple2.Server.Game.csproj"
17+
COPY . .
18+
WORKDIR "/src/Maple2.Server.Game"
19+
RUN dotnet build "Maple2.Server.Game.csproj" -c Debug -o /app/build
20+
21+
FROM build AS publish
22+
RUN dotnet publish "Maple2.Server.Game.csproj" -c Debug -o /app/publish
23+
24+
FROM base AS final
25+
WORKDIR /app
26+
COPY --from=publish /app/publish .
27+
ENTRYPOINT ["dotnet", "Maple2.Server.Game.dll"]

Maple2.Server.Game/Maple2.Server.Game.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<OutputType>Exe</OutputType>
55
<TargetFramework>net6.0</TargetFramework>
66
<Nullable>enable</Nullable>
7+
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
78
</PropertyGroup>
89

910
<ItemGroup>

Maple2.Server.Login/Dockerfile

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
2+
WORKDIR /app
3+
# Login Server
4+
EXPOSE 20001
5+
6+
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
7+
WORKDIR /src
8+
COPY ["Maple2.Server.Login/Maple2.Server.Login.csproj", "Maple2.Server.Login/"]
9+
COPY ["Maple2.Tools/Maple2.Tools.csproj", "Maple2.Tools/"]
10+
COPY ["Maple2.Model/Maple2.Model.csproj", "Maple2.Model/"]
11+
COPY ["Maple2.Database/Maple2.Database.csproj", "Maple2.Database/"]
12+
COPY ["Maple2.Server.Core/Maple2.Server.Core.csproj", "Maple2.Server.Core/"]
13+
RUN dotnet restore "Maple2.Server.Login/Maple2.Server.Login.csproj"
14+
COPY . .
15+
WORKDIR "/src/Maple2.Server.Login"
16+
RUN dotnet build "Maple2.Server.Login.csproj" -c Debug -o /app/build
17+
18+
FROM build AS publish
19+
RUN dotnet publish "Maple2.Server.Login.csproj" -c Debug -o /app/publish
20+
21+
FROM base AS final
22+
WORKDIR /app
23+
COPY --from=publish /app/publish .
24+
ENTRYPOINT ["dotnet", "Maple2.Server.Login.dll"]

Maple2.Server.Login/Maple2.Server.Login.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<OutputType>Exe</OutputType>
55
<TargetFramework>net6.0</TargetFramework>
66
<Nullable>enable</Nullable>
7+
<DockerDefaultTargetOS>Windows</DockerDefaultTargetOS>
78
</PropertyGroup>
89

910
<ItemGroup>

Maple2.Server.Tests/Maple2.Server.Tests.csproj

+7-4
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
12-
<PackageReference Include="MSTest.TestAdapter" Version="2.2.7" />
13-
<PackageReference Include="MSTest.TestFramework" Version="2.2.7" />
14-
<PackageReference Include="coverlet.collector" Version="3.1.0" />
11+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />
12+
<PackageReference Include="MSTest.TestAdapter" Version="2.2.10" />
13+
<PackageReference Include="MSTest.TestFramework" Version="2.2.10" />
14+
<PackageReference Include="coverlet.collector" Version="3.1.2">
15+
<PrivateAssets>all</PrivateAssets>
16+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
17+
</PackageReference>
1518
</ItemGroup>
1619

1720
<ItemGroup>

Maple2.Server.World/Dockerfile

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
2+
WORKDIR /app
3+
# World Service, Global Service
4+
EXPOSE 20100
5+
6+
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
7+
WORKDIR /src
8+
COPY ["Maple2.Server.World/Maple2.Server.World.csproj", "Maple2.Server.World/"]
9+
COPY ["Maple2.Tools/Maple2.Tools.csproj", "Maple2.Tools/"]
10+
COPY ["Maple2.Model/Maple2.Model.csproj", "Maple2.Model/"]
11+
COPY ["Maple2.Database/Maple2.Database.csproj", "Maple2.Database/"]
12+
COPY ["Maple2.Server.Core/Maple2.Server.Core.csproj", "Maple2.Server.Core/"]
13+
RUN dotnet restore "Maple2.Server.World/Maple2.Server.World.csproj"
14+
COPY . .
15+
WORKDIR "/src/Maple2.Server.World"
16+
RUN dotnet build "Maple2.Server.World.csproj" -c Debug -o /app/build
17+
18+
FROM build AS publish
19+
RUN dotnet publish "Maple2.Server.World.csproj" -c Debug -o /app/publish
20+
21+
FROM base AS final
22+
WORKDIR /app
23+
COPY --from=publish /app/publish .
24+
ENTRYPOINT ["dotnet", "Maple2.Server.World.dll"]

Maple2.Server.World/Maple2.Server.World.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<OutputType>Exe</OutputType>
55
<TargetFramework>net6.0</TargetFramework>
66
<Nullable>enable</Nullable>
7+
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
78
</PropertyGroup>
89

910
<ItemGroup>

Maple2.Server.World/Program.cs

+6-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System.IO;
33
using Autofac.Extensions.DependencyInjection;
44
using Maple2.Database.Context;
5-
using Maple2.Server.Core.Constants;
65
using Maple2.Server.World;
76
using Microsoft.AspNetCore.Hosting;
87
using Microsoft.EntityFrameworkCore;
@@ -19,6 +18,11 @@
1918
.ReadFrom.Configuration(configRoot)
2019
.CreateLogger();
2120

21+
string? gameDbConnection = Environment.GetEnvironmentVariable("GAME_DB_CONNECTION");
22+
if (gameDbConnection == null) {
23+
throw new ArgumentException("GAME_DB_CONNECTION environment variable was not set");
24+
}
25+
2226
IHostBuilder builder = Host.CreateDefaultBuilder()
2327
.ConfigureLogging(logging => {
2428
logging.ClearProviders();
@@ -28,7 +32,7 @@
2832
.ConfigureWebHostDefaults(builder => builder.UseStartup<Startup>());
2933

3034
DbContextOptions options = new DbContextOptionsBuilder()
31-
.UseMySql(Target.GAME_DB_CONNECTION, ServerVersion.AutoDetect(Target.GAME_DB_CONNECTION)).Options;
35+
.UseMySql(gameDbConnection, ServerVersion.AutoDetect(gameDbConnection)).Options;
3236
await using (var initContext = new InitializationContext(options)) {
3337
// Initialize database if needed
3438
if (!initContext.Initialize()) {

compose.yml

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
services:
2+
world:
3+
image: maple2-world
4+
network_mode: bridge
5+
ports:
6+
- "127.0.0.1:20100:20100"
7+
environment:
8+
GAME_DB_CONNECTION: "Server=host.docker.internal;Database=game-server;User=root;Password=maplestory"
9+
DATA_DB_CONNECTION: "Server=host.docker.internal;Database=maple-data;User=root;Password=maplestory"
10+
11+
login:
12+
image: maple2-login
13+
depends_on:
14+
- world
15+
network_mode: bridge
16+
ports:
17+
- "20001:20001"
18+
environment:
19+
GAME_DB_CONNECTION: "Server=host.docker.internal;Database=game-server;User=root;Password=maplestory"
20+
DATA_DB_CONNECTION: "Server=host.docker.internal;Database=maple-data;User=root;Password=maplestory"
21+
22+
game:
23+
image: maple2-game
24+
depends_on:
25+
- world
26+
- login
27+
network_mode: bridge
28+
ports:
29+
- "22001:22001"
30+
- "127.0.0.1:22100:22100"
31+
environment:
32+
GAME_DB_CONNECTION: "Server=host.docker.internal;Database=game-server;User=root;Password=maplestory"
33+
DATA_DB_CONNECTION: "Server=host.docker.internal;Database=maple-data;User=root;Password=maplestory"

0 commit comments

Comments
 (0)