Skip to content

Commit 8d37b57

Browse files
committed
build: Add Docker support
1 parent 522a1af commit 8d37b57

File tree

2 files changed

+44
-9
lines changed

2 files changed

+44
-9
lines changed

Dockerfile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
ARG APP_NAME=multiplayer-game-demo-rust
2+
3+
FROM rust:1.81-bullseye as builder
4+
WORKDIR /usr/src/${APP_NAME}
5+
COPY . .
6+
RUN cargo install --path .
7+
8+
FROM debian:bullseye-slim
9+
COPY --from=builder /usr/local/cargo/bin/${APP_NAME} /usr/local/bin/${APP_NAME}
10+
ENTRYPOINT ["multiplayer-game-demo-rust", "--server-only", "--trace"]
11+

README.md

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,30 +29,37 @@ efficient application using real-time multiplayer game techniques. The project
2929
showcases confident understanding of networking and concurrency concepts as
3030
well as the use of Tokio async runtime.
3131

32+
This application was tested under `tc-netem` network emulator simulating
33+
harsh network environment and packet loss, as well as live being deployed on a
34+
remote [Amazon EC2](https://aws.amazon.com/ec2/) virtual machine instance.
35+
3236
Using conventional threads for concurrency and parallelism can be expensive due
3337
to the cost of requesting threads from the operating system and additional heap
3438
allocations (although thread pools mitigate this). Rust has language support
3539
for asynchronous programming, but does not ship with built-in implementation of
3640
an async runtime due to increase in compiled binary size. Instead it is opt-in
3741
with the inclusion of crates like [async-std](https://async.rs/),
38-
[Tokio](https://tokio.rs/) and [smol](https://github.com/smol-rs/smol). Tokio
39-
utilizes the concept of *green-threading* (concept similar to goroutines in the
40-
Go programming language) and the asynchronous I/O capabilities of the operating
41-
system (`epoll` on Linux, `IOCP` on Windows and `kqueue` on macOS).
42+
[Tokio](https://tokio.rs/), [mio](https://github.com/tokio-rs/mio) and
43+
[smol](https://github.com/smol-rs/smol). Tokio utilizes the concept of
44+
*green-threading* (concept similar to goroutines in the Go programming
45+
language) and the asynchronous I/O capabilities of the operating system
46+
(`epoll` on Linux, `IOCP` on Windows and `kqueue` on macOS).
4247

4348
Game programming provides a challenging environment to put these concepts into
4449
practice due to them being classified as *soft real-time systems*, requiring
4550
response within a time of generating a frame in 16.666 milliseconds (60
4651
frames/second). Although TCP network protocol is used in conventional software
47-
systems, the `SYN/ACK` handshake procedure introduces additional latency. Real-time
48-
multiplayer game developers utilize UDP protocol for faster responses and make
49-
their own custom-tailored reliability protocol on top of it.
52+
systems, the `SYN/ACK` handshake procedure introduces additional latency.
53+
Real-time multiplayer game developers utilize the UDP protocol for faster
54+
responses at the cost of guaranteed packet delivery, and they create their own
55+
custom-tailored reliability protocols on top of it.
5056

5157
## Features
5258

5359
- Client-server architecture for multiplayer networking. UDP socket
5460
communication for low-latency networking.
5561
- Health-check mechanism to detect lost network connections.
62+
- Reliability patterns to mitigate harsh network environments like UDP packet losses.
5663
- Real-time multiplayer gameplay with smooth synchronization.
5764
- Graphical client application with GUI menu
5865
- Hardware-accelerated OpenGL rendering for 2D top-down perspective graphics.
@@ -74,19 +81,36 @@ Dependencies are automatically downloaded by `cargo`.
7481
1. Make sure you have the latest stable version of Rust and `cargo` installed, following the instructions on
7582
https://www.rust-lang.org/tools/install
7683

77-
2. Clone the repository
84+
2. Clone the repository:
7885

7986
```sh
8087
git clone https://github.com/balintkissdev/multiplayer-game-demo-rust.git
8188
cd multiplayer-game-demo-rust
8289
```
8390

84-
3. Compile and execute the release build
91+
3. Compile and execute the release build:
8592

8693
```sh
8794
cargo run --release
8895
```
8996

97+
### Docker
98+
99+
The application can also be deployed as a Docker container, which will run in server-only mode.
100+
101+
1. Build the Docker image:
102+
103+
```sh
104+
docker build -t multiplayer-game-demo-rust .
105+
```
106+
107+
2. Launch the Docker container. This starts with `--server-only` and `--trace` options by
108+
default. See [Command line options](#command-line-options) for more info.
109+
110+
```sh
111+
docker run -d -p 8080:8080 multiplayer-game-demo-rust
112+
```
113+
90114
## Usage
91115

92116
You can test out the application on your local machine by executing multiple

0 commit comments

Comments
 (0)