Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added docker configuration #1481

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
**/.git
uo-client
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,5 @@

/packages/*
/Distribution/Configuration/server-access.json

uo-client/*
17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM ubuntu:22.04

WORKDIR /tmp

RUN apt-get update \
&& apt-get install -y vim wget libicu-dev libz-dev zstd libargon2-dev tzdata

RUN wget https://dot.net/v1/dotnet-install.sh -O dotnet-install.sh
RUN chmod +x ./dotnet-install.sh
RUN ./dotnet-install.sh --version 7.0.400

RUN echo 'DOTNET_ROOT=$HOME/.dotnet' >> /root/.bashrc
RUN echo 'PATH=$PATH:$DOTNET_ROOT:$DOTNET_ROOT/tools' >> /root/.bashrc

WORKDIR /app

CMD [ "tail", "-f", "/dev/null" ]
1 change: 1 addition & 0 deletions Projects/Server/Configuration/ServerConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ public static void Load(bool mocked = false)
{
updated = true;
_settings.Listeners.AddRange(ServerConfigurationPrompts.GetListeners());
_settings.Settings["serverListing.privateAddress"] = ServerConfigurationPrompts.GetPrivateAddress();
}

// We have a known, current expansion, so we can deserialize it from Configuration
Expand Down
43 changes: 43 additions & 0 deletions Projects/Server/Configuration/ServerConfigurationPrompts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,49 @@ internal static List<string> GetDataDirectories()
return directories;
}

internal static string GetPrivateAddress()
{
Console.WriteLine("If the server is running in a Docker container, specify the parent host IP:");
Console.WriteLine("- 127.0.0.1");
Console.WriteLine("- Or leave blank to skip");

string ipStr;

do
{
// IP:Port?
Console.Write("[{0}]> ", "enter to finish");
ipStr = Console.ReadLine();

IPEndPoint ip;
if (string.IsNullOrWhiteSpace(ipStr))
{
ipStr = null;
break;
}
else
{
if (!IPEndPoint.TryParse(ipStr, out ip))
{
Utility.PushColor(ConsoleColor.Red);
Console.Write(ipStr);
Utility.PopColor();
Console.WriteLine(" is not a valid IP or port.");
continue;
}
}

Console.Write("Added ");
Utility.PushColor(ConsoleColor.Green);
Console.Write(ipStr);
Utility.PopColor();
Console.WriteLine(".");
break;
} while (true);

return ipStr;
}

internal static List<IPEndPoint> GetListeners()
{
Console.WriteLine("Please enter the IP and ports to listen:");
Expand Down
9 changes: 9 additions & 0 deletions Projects/UOContent/Misc/ServerList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ namespace Server.Misc
* "serverListing.address": null,
* "serverListing.autoDetect": false
*
* If you want to run MUO inside a container, you need to setup the private address so that CUO can connect, e.g.
* "serverListing.privateAddress": "127.0.0.1"
*
* If you want players outside your LAN to be able to connect to your server and you are behind a router, you must also
* forward TCP port 2593 to your private IP address. The procedure for doing this varies by manufacturer but generally
* involves configuration of the router through your web browser.
Expand All @@ -34,13 +37,15 @@ public static class ServerList
private static readonly ILogger logger = LogFactory.GetLogger(typeof(ServerList));

private static IPAddress _publicAddress;
public static string PrivateAddress { get; private set; }
public static string Address { get; private set; }
public static string ServerName { get; private set; }

public static bool AutoDetect { get; private set; }

public static void Configure()
{
PrivateAddress = ServerConfiguration.GetOrUpdateSetting("serverListing.privateAddress", null);
Address = ServerConfiguration.GetOrUpdateSetting("serverListing.address", null);
AutoDetect = ServerConfiguration.GetOrUpdateSetting("serverListing.autoDetect", true);
ServerName = ServerConfiguration.GetOrUpdateSetting("serverListing.serverName", "ModernUO");
Expand Down Expand Up @@ -85,6 +90,10 @@ private static void EventSink_ServerList(ServerListEventArgs e)
{
localAddress = _publicAddress;
}
else if (PrivateAddress != null)
{
Resolve(PrivateAddress, out localAddress);
}
}

e.AddServer(ServerName, new IPEndPoint(localAddress, localPort));
Expand Down
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,28 @@ apt-get install -y libicu-dev libz-dev zstd libargon2-dev tzdata
- Follow the [publish](https://github.com/modernuo/ModernUO#publishing-builds) instructions
- Run `ModernUO.exe` or `dotnet ModernUO.dll` from the `Distribution` directory on the

## Running with Docker

- Download a game client: https://uo.com/client-download/
- Install the downloaded game client and run it to download the game assets
- Copy game assets into the `uo-client` directory in the project. This folder gets mounted into the Docker container under the `/app/uo-client` path.

Once that's done, run the following command to make a build

```
docker-compose run --build --rm compile [debug]
```


Finally, run the command below to start the server.
If this is your first run, you'll need to specify the game assets path, which is `/app/uo-client`.
If you plan connecting from the host machine, you'll also need to specify the private IP (e.g. `127.0.0.1`) when prompted during the first run (or change it later in the `modernuo.json`).

```
docker-compose run --service-ports --rm server
```


## Troubleshooting / FAQ
- See [FAQ](./FAQ.md)

Expand Down
23 changes: 23 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
version: "3"
services:

compile:
volumes: [".:/app:delegated"]
build: .
restart: always
entrypoint: ["/usr/bin/bash", "-i", "./publish.sh"]
profiles: ["build-compile"]

server:
volumes: [".:/app:delegated"]
build: .
restart: always
ports: ["2593:2593/udp", "2593:2593/tcp"]
entrypoint: ["/root/.dotnet/dotnet", "/app/Distribution/ModernUO.dll"]
profiles: ["run-server"]

app:
volumes: [".:/app:delegated"]
build: .
restart: always
ports: ["2593:2593/udp", "2593:2593/tcp"]