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

feat: basic Docker support #2040

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Distribution Files
/Distribution/ModernUO
/Distribution/ModernUO.*
/Distribution/Server
/Distribution/Server.*
/Distribution/Assemblies
/Distribution/bsdtar
/Distribution/Configuration/antimacro.json
/Distribution/Configuration/assistants.json
/Distribution/Configuration/expansion.json
/Distribution/Configuration/modernuo.json
/Distribution/Configuration/email-settings.json
/Distribution/Configuration/throttles.json
/Distribution/Configuration/tot.json
/Distribution/Logs
/Distribution/Archives
/Distribution/Backups
/Distribution/Saves
/Distribution/docs
/Distribution/temp
/Distribution/*.dylib
/Distribution/*.so
/Distribution/*.dll
/Distribution/*.exe
/Distribution/runtimes
/Distribution/nohup.out
/Distribution/ref
/Distribution/web

/Projects/*/obj
/Projects/*/bin
/Projects/*/Generated

*.swp
*.log
*.user
/.idea
/.vs
/.vscode

.DS_Store

/packages/*
/Distribution/Configuration/server-access.json
58 changes: 58 additions & 0 deletions DOCKER.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
## Getting Started

Disclaimer: This document assumes familiarity with running containerized workloads.

### Build

```shell
# linux/amd64
docker build -t modernuo/modernuo .

# linux/arm64
docker build --build-arg ARCH=arm64 -t modernuo/modernuo .
```

Note: `docker buildx` is capable of building for `amd64` on `arm64` machines (and other combinations), but that beyond the scope of this document.

### Run

In order to run the image as a container you need to provide three volume mounts:
1. Save files, or an empty directory in which to save the game server.
1. Configuration files, or an empty directory in which to save the configurations.
1. Data files, from the Data directory in the repository
1. UO files.

In the following example we make three assumptions:
1. UO files are located on the host machine at the path `/some/UO/place`.
1. The `dataDirectories` array in `Configuration/modernuo.json` includes `/bin/UO`.
1. The `docker run` command is being executed in the root of the repository.

```shell
docker run \
--volume $(pwd)/Distribution/Configuration:/bin/modernuo/Configuration \
--volume $(pwd)/Distribution/Data:/bin/modernuo/Data \
--volume $(pwd)/Distribution/Saves:/bin/modernuo/Saves \
--volume /some/UO/place:/bin/UO \
--expose 2593 \
modernuo/modernuo:latest
```

#### Empty `Configuration` Directory

If mounting an empty directory to the `Configuration` directory, use the following command instead. This variation will allow user input. This is required for initial configuration with an empty directory. In subsequent runs the above command should suffice.

```shell
docker run \
-it \
--volume $(pwd)/Distribution/Configuration:/bin/modernuo/Configuration \
--volume $(pwd)/Distribution/Data:/bin/modernuo/Data \
--volume $(pwd)/Distribution/Saves:/bin/modernuo/Saves \
--volume /some/UO/place:/bin/UO \
--expose 2593 \
modernuo/modernuo:latest
```
Note: the volume is still required for the game data directory, the configuration affects the component that is `/bin/UO` in the example.

### Connect

Connect to the shard at `127.0.0.1:2593`.
44 changes: 44 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# syntax=docker.io/docker/dockerfile:1.7-labs
ARG DOTNET_VERSION=9.0.101
ARG OS=linux
ARG ARCH=x64

FROM ubuntu:24.10 AS dependencies
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

arbitrary base image

ARG DOTNET_VERSION
ARG ARCH
ARG OS

RUN apt-get update -y \
&& apt-get install -y libicu-dev curl

RUN curl -L https://dotnet.microsoft.com/download/dotnet/scripts/v1/dotnet-install.sh -o dotnet-install.sh && \
chmod +x dotnet-install.sh && \
./dotnet-install.sh --version ${DOTNET_VERSION} --architecture ${ARCH} --os ${OS}

ENV PATH $PATH:/root/.dotnet
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have to update the PATH here so the publish stage can run the dotnet commands it needs to run


FROM dependencies AS publish
ARG OS
ARG ARCH

WORKDIR /bin/modernuo

COPY . .

RUN ./publish.sh release ${OS} ${ARCH}

FROM dependencies AS deploy
ARG DOTNET_VERSION
ARG ARCH

ENV DOTNET_ROOT=/root/.dotnet
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updating the PATH in the dependencies stage above doesn't enable the ModernUO binary to find that installation

instead, we have to set DOTNET_ROOT before we run the binary


RUN apt-get update -y \
&& apt-get install -y \
libdeflate-dev zstd libargon2-dev

WORKDIR /bin/modernuo

COPY --from=publish /bin/modernuo/Distribution /bin/modernuo

CMD '/bin/modernuo/ModernUO'
18 changes: 18 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
services:
modernuo:
build:
context: .
args:
OS: "${OS:-linux}"
ARCH: "${ARCH:-amd64}"
environment:
UO_DIRECTORY: ${UO_DIRECTORY:-/bin/UO}
ports:
- "2593:2593"
- "12000:12000"
volumes:
- "./Distribution/Configuration:/bin/modernuo/Configuration"
- "./Distribution/Data:/bin/modernuo/Data"
- "./Distribution/Saves:/bin/modernuo/Saves"
# see the example in the DOCKER.md file to understand this volume
- "$UO_DIRECTORY:/bin/UO"
Loading