From 9afba329c2b4d30b95cba52e5a0f4114f1cd4292 Mon Sep 17 00:00:00 2001 From: a Date: Wed, 11 Sep 2024 20:26:09 +0200 Subject: [PATCH 1/4] Initial docker test Signed-off-by: xavo95 --- .dockerignore | 12 ++++ Dockerfile-builder | 6 ++ Dockerfile-service | 6 ++ assets/docker/configserver.toml | 6 ++ assets/docker/gameserver.toml | 13 ++++ assets/docker/gateway.toml | 20 +++++++ assets/docker/hotpatch.toml | 6 ++ assets/docker/loginserver.toml | 12 ++++ assets/docker/postgres/scripts/0_INIT.sql | 3 + assets/docker/postgres/scripts/1_PERMS.sql | 2 + builder.bat | 9 +++ builder.sh | 9 +++ docker-compose.yml | 70 ++++++++++++++++++++++ 13 files changed, 174 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile-builder create mode 100644 Dockerfile-service create mode 100644 assets/docker/configserver.toml create mode 100644 assets/docker/gameserver.toml create mode 100644 assets/docker/gateway.toml create mode 100644 assets/docker/hotpatch.toml create mode 100644 assets/docker/loginserver.toml create mode 100644 assets/docker/postgres/scripts/0_INIT.sql create mode 100644 assets/docker/postgres/scripts/1_PERMS.sql create mode 100644 builder.bat create mode 100644 builder.sh create mode 100644 docker-compose.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..67cbc83 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,12 @@ +.git +assets +postgres +**/target +.gitignore +docker-compose.yml +Dockerfile-builder +Dockerfile-service +LICENSE +*.md +*.zip +*.png \ No newline at end of file diff --git a/Dockerfile-builder b/Dockerfile-builder new file mode 100644 index 0000000..485dff5 --- /dev/null +++ b/Dockerfile-builder @@ -0,0 +1,6 @@ +FROM rust:1.81-alpine3.20 + +WORKDIR /app +COPY . . +# No need to manually strip symbols(strip target/release/$MICROSERVICE) since workspace its already prepared for that +RUN apk add musl-dev protoc && cargo build --release diff --git a/Dockerfile-service b/Dockerfile-service new file mode 100644 index 0000000..9234785 --- /dev/null +++ b/Dockerfile-service @@ -0,0 +1,6 @@ +FROM alpine:3.20 as release +ARG MICROSERVICE + +WORKDIR /app +COPY --from=shorekeeper-builder:1.3.0-SNAPSHOT /app/target/release/$MICROSERVICE ./service +CMD ["./service"] \ No newline at end of file diff --git a/assets/docker/configserver.toml b/assets/docker/configserver.toml new file mode 100644 index 0000000..13a18fd --- /dev/null +++ b/assets/docker/configserver.toml @@ -0,0 +1,6 @@ +[network] +http_addr = "0.0.0.0:10001" + +[encryption] +key = "t+AEu5SGdpz06tomonajLMau9AJgmyTvVhz9VtGf1+0=" +iv = "fprc5lBWADQB7tim0R2JxQ==" diff --git a/assets/docker/gameserver.toml b/assets/docker/gameserver.toml new file mode 100644 index 0000000..1e8300d --- /dev/null +++ b/assets/docker/gameserver.toml @@ -0,0 +1,13 @@ +service_id = 2 + +[database] +host = "shorekeeper-postgres:5432" +user_name = "shorekeeper_user" +password = "shorekeeper_pass" +db_name = "shorekeeper_db" + +[service_end_point] +addr = "tcp://0.0.0.0:10004" + +[gateway_end_point] +addr = "tcp://shorekeeper-gateway-server:10003" diff --git a/assets/docker/gateway.toml b/assets/docker/gateway.toml new file mode 100644 index 0000000..83c75e3 --- /dev/null +++ b/assets/docker/gateway.toml @@ -0,0 +1,20 @@ +service_id = 1 + +[network] +kcp_port = 7777 + +[protokey] +builtin_encryption_msg_id = [111, 112] +use_client_key = true + +[service_end_point] +addr = "tcp://0.0.0.0:10003" + +[game_server_end_point] +addr = "tcp://shorekeeper-game-server:10004" + +[database] +host = "shorekeeper-postgres:5432" +user_name = "shorekeeper_user" +password = "shorekeeper_pass" +db_name = "shorekeeper_db" diff --git a/assets/docker/hotpatch.toml b/assets/docker/hotpatch.toml new file mode 100644 index 0000000..19ef770 --- /dev/null +++ b/assets/docker/hotpatch.toml @@ -0,0 +1,6 @@ +[network] +http_addr = "0.0.0.0:10002" + +[encryption] +key = "t+AEu5SGdpz06tomonajLMau9AJgmyTvVhz9VtGf1+0=" +iv = "fprc5lBWADQB7tim0R2JxQ==" diff --git a/assets/docker/loginserver.toml b/assets/docker/loginserver.toml new file mode 100644 index 0000000..65f1dbb --- /dev/null +++ b/assets/docker/loginserver.toml @@ -0,0 +1,12 @@ +[network] +http_addr = "0.0.0.0:5500" + +[gateway] +host = "shorekeeper-gateway-server" +port = 7777 + +[database] +host = "shorekeeper-postgres:5432" +user_name = "shorekeeper_user" +password = "shorekeeper_pass" +db_name = "shorekeeper_db" diff --git a/assets/docker/postgres/scripts/0_INIT.sql b/assets/docker/postgres/scripts/0_INIT.sql new file mode 100644 index 0000000..99d9607 --- /dev/null +++ b/assets/docker/postgres/scripts/0_INIT.sql @@ -0,0 +1,3 @@ +CREATE DATABASE shorekeeper_db; +CREATE USER shorekeeper_user WITH encrypted password 'shorekeeper_pass'; +GRANT ALL PRIVILEGES ON DATABASE shorekeeper_db to shorekeeper_user; \ No newline at end of file diff --git a/assets/docker/postgres/scripts/1_PERMS.sql b/assets/docker/postgres/scripts/1_PERMS.sql new file mode 100644 index 0000000..3b4a427 --- /dev/null +++ b/assets/docker/postgres/scripts/1_PERMS.sql @@ -0,0 +1,2 @@ +\c shorekeeper_db; +GRANT ALL ON SCHEMA public TO shorekeeper_user; \ No newline at end of file diff --git a/builder.bat b/builder.bat new file mode 100644 index 0000000..1392676 --- /dev/null +++ b/builder.bat @@ -0,0 +1,9 @@ +docker build -t shorekeeper-builder:1.3.0-SNAPSHOT -f Dockerfile-builder . + +docker build -t shorekeeper-config-server:1.3.0-SNAPSHOT --build-arg MICROSERVICE=config-server -f Dockerfile-service . +docker build -t shorekeeper-hotpatch-server:1.3.0-SNAPSHOT --build-arg MICROSERVICE=hotpatch-server -f Dockerfile-service . +docker build -t shorekeeper-login-server:1.3.0-SNAPSHOT --build-arg MICROSERVICE=login-server -f Dockerfile-service . +docker build -t shorekeeper-gateway-server:1.3.0-SNAPSHOT --build-arg MICROSERVICE=gateway-server -f Dockerfile-service . +docker build -t shorekeeper-game-server:1.3.0-SNAPSHOT --build-arg MICROSERVICE=game-server -f Dockerfile-service . + +docker rmi shorekeeper-builder:1.3.0-SNAPSHOT diff --git a/builder.sh b/builder.sh new file mode 100644 index 0000000..1392676 --- /dev/null +++ b/builder.sh @@ -0,0 +1,9 @@ +docker build -t shorekeeper-builder:1.3.0-SNAPSHOT -f Dockerfile-builder . + +docker build -t shorekeeper-config-server:1.3.0-SNAPSHOT --build-arg MICROSERVICE=config-server -f Dockerfile-service . +docker build -t shorekeeper-hotpatch-server:1.3.0-SNAPSHOT --build-arg MICROSERVICE=hotpatch-server -f Dockerfile-service . +docker build -t shorekeeper-login-server:1.3.0-SNAPSHOT --build-arg MICROSERVICE=login-server -f Dockerfile-service . +docker build -t shorekeeper-gateway-server:1.3.0-SNAPSHOT --build-arg MICROSERVICE=gateway-server -f Dockerfile-service . +docker build -t shorekeeper-game-server:1.3.0-SNAPSHOT --build-arg MICROSERVICE=game-server -f Dockerfile-service . + +docker rmi shorekeeper-builder:1.3.0-SNAPSHOT diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..e2fae07 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,70 @@ +name: shorekeeper-ps + +services: + shorekeeper-config-server: + image: shorekeeper-config-server:1.3.0-SNAPSHOT + depends_on: + shorekeeper-postgres: + condition: service_healthy + ports: + - '10001:10001' + volumes: + - "./assets/docker/configserver.toml:/app/configserver.toml" + - "./assets/config:/app/assets/config" + shorekeeper-hotpatch-server: + image: shorekeeper-hotpatch-server:1.3.0-SNAPSHOT + depends_on: + shorekeeper-postgres: + condition: service_healthy + ports: + - '10002:10002' + volumes: + - "./assets/docker/hotpatch.toml:/app/hotpatch.toml" + - "./assets/hotpatch:/app/assets/hotpatch" + shorekeeper-login-server: + image: shorekeeper-login-server:1.3.0-SNAPSHOT + depends_on: + shorekeeper-postgres: + condition: service_healthy + ports: + - '5500:5500' + volumes: + - "./assets/docker/loginserver.toml:/app/loginserver.toml" + shorekeeper-gateway-server: + image: shorekeeper-gateway-server:1.3.0-SNAPSHOT + depends_on: + shorekeeper-postgres: + condition: service_healthy + ports: + # Uncomment this if you want to have manual access + # - '10003:10003' + - '7777:7777/udp' + volumes: + - "./assets/docker/gateway.toml:/app/gateway.toml" + shorekeeper-game-server: + image: shorekeeper-game-server:1.3.0-SNAPSHOT + depends_on: + shorekeeper-postgres: + condition: service_healthy + # Uncomment this if you want to have manual access +# ports: +# - '10004:10004' + volumes: + - "./assets/docker/gameserver.toml:/app/gameserver.toml" + - "./assets/logic:/app/assets/logic" + shorekeeper-postgres: + image: postgres:16.4-alpine3.20 + user: postgres + # Uncomment this if you want to have manual access +# ports: +# - '5432:5432' + healthcheck: + test: ["CMD-SHELL", "pg_isready"] + interval: 10s + timeout: 5s + retries: 5 + environment: + - "POSTGRES_PASSWORD=toor" + volumes: + # If you want to have persistence, mount postgres data folder + - "./assets/docker/postgres/scripts:/docker-entrypoint-initdb.d" \ No newline at end of file -- 2.34.1 From f1e3ce88879006a5b45d19f803bfbcc74d22ba5d Mon Sep 17 00:00:00 2001 From: xavo95 Date: Wed, 11 Sep 2024 20:38:55 +0200 Subject: [PATCH 2/4] Update README.md --- README.md | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7cf6231..d744d20 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,22 @@ cargo run --bin gateway-server cargo run --bin game-server ``` -##### b) using pre-built binaries +##### b) building from sources(docker edition) +If you are to wheelchair'd for option A, you can fallback to option b. +In this case you will need [Docker Desktop](https://www.docker.com/products/docker-desktop/) + +Once installed, to build the images, run: +```sh +# or builder.bat if you run it on windows +./builder.sh +``` + +And to run the containers: +```sh +docker compose up -d +``` + +##### c) using pre-built binaries Navigate to the [Releases](https://git.xeondev.com/Shorekeeper/Shorekeeper/releases) page and download the latest release for your platform.
Launch all servers: `config-server`, `hotpatch-server`, `login-server`, `gateway-server`, `game-server` -- 2.34.1 From deb86efff35762d996bd1f0847edd85884dd05b0 Mon Sep 17 00:00:00 2001 From: xavo95 Date: Thu, 12 Sep 2024 17:05:16 +0200 Subject: [PATCH 3/4] Tested setup --- assets/docker/loginserver.toml | 2 +- builder.bat | 3 +++ builder.sh | 3 +++ docker-compose.yml | 7 +++++-- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/assets/docker/loginserver.toml b/assets/docker/loginserver.toml index 65f1dbb..d07c8c5 100644 --- a/assets/docker/loginserver.toml +++ b/assets/docker/loginserver.toml @@ -2,7 +2,7 @@ http_addr = "0.0.0.0:5500" [gateway] -host = "shorekeeper-gateway-server" +host = "host.docker.internal" port = 7777 [database] diff --git a/builder.bat b/builder.bat index 1392676..e7968e9 100644 --- a/builder.bat +++ b/builder.bat @@ -7,3 +7,6 @@ docker build -t shorekeeper-gateway-server:1.3.0-SNAPSHOT --build-arg MICROSERVI docker build -t shorekeeper-game-server:1.3.0-SNAPSHOT --build-arg MICROSERVICE=game-server -f Dockerfile-service . docker rmi shorekeeper-builder:1.3.0-SNAPSHOT + +: Persistence for the application +docker volume create shorekeeper-postgres-vol \ No newline at end of file diff --git a/builder.sh b/builder.sh index 1392676..46c7e74 100644 --- a/builder.sh +++ b/builder.sh @@ -7,3 +7,6 @@ docker build -t shorekeeper-gateway-server:1.3.0-SNAPSHOT --build-arg MICROSERVI docker build -t shorekeeper-game-server:1.3.0-SNAPSHOT --build-arg MICROSERVICE=game-server -f Dockerfile-service . docker rmi shorekeeper-builder:1.3.0-SNAPSHOT + +# Persistence for the application +docker volume create shorekeeper-postgres-vol \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index e2fae07..c7e07f0 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -66,5 +66,8 @@ services: environment: - "POSTGRES_PASSWORD=toor" volumes: - # If you want to have persistence, mount postgres data folder - - "./assets/docker/postgres/scripts:/docker-entrypoint-initdb.d" \ No newline at end of file + - "./assets/docker/postgres/scripts:/docker-entrypoint-initdb.d" + - shorekeeper-postgres-vol:/var/lib/postgresql/data +volumes: + shorekeeper-postgres-vol: + external: true \ No newline at end of file -- 2.34.1 From db0516a105a290ceaee2d58d38fdf45886befa7d Mon Sep 17 00:00:00 2001 From: xavo95 Date: Thu, 12 Sep 2024 23:19:15 +0200 Subject: [PATCH 4/4] Tested setup --- docker-compose.yml | 12 ++++++------ {assets/docker => docker}/configserver.toml | 0 {assets/docker => docker}/gameserver.toml | 0 {assets/docker => docker}/gateway.toml | 0 {assets/docker => docker}/hotpatch.toml | 0 {assets/docker => docker}/loginserver.toml | 0 .../docker => docker}/postgres/scripts/0_INIT.sql | 0 .../docker => docker}/postgres/scripts/1_PERMS.sql | 0 8 files changed, 6 insertions(+), 6 deletions(-) rename {assets/docker => docker}/configserver.toml (100%) rename {assets/docker => docker}/gameserver.toml (100%) rename {assets/docker => docker}/gateway.toml (100%) rename {assets/docker => docker}/hotpatch.toml (100%) rename {assets/docker => docker}/loginserver.toml (100%) rename {assets/docker => docker}/postgres/scripts/0_INIT.sql (100%) rename {assets/docker => docker}/postgres/scripts/1_PERMS.sql (100%) diff --git a/docker-compose.yml b/docker-compose.yml index c7e07f0..c88aef3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -9,7 +9,7 @@ services: ports: - '10001:10001' volumes: - - "./assets/docker/configserver.toml:/app/configserver.toml" + - "./docker/configserver.toml:/app/configserver.toml" - "./assets/config:/app/assets/config" shorekeeper-hotpatch-server: image: shorekeeper-hotpatch-server:1.3.0-SNAPSHOT @@ -19,7 +19,7 @@ services: ports: - '10002:10002' volumes: - - "./assets/docker/hotpatch.toml:/app/hotpatch.toml" + - "./docker/hotpatch.toml:/app/hotpatch.toml" - "./assets/hotpatch:/app/assets/hotpatch" shorekeeper-login-server: image: shorekeeper-login-server:1.3.0-SNAPSHOT @@ -29,7 +29,7 @@ services: ports: - '5500:5500' volumes: - - "./assets/docker/loginserver.toml:/app/loginserver.toml" + - "./docker/loginserver.toml:/app/loginserver.toml" shorekeeper-gateway-server: image: shorekeeper-gateway-server:1.3.0-SNAPSHOT depends_on: @@ -40,7 +40,7 @@ services: # - '10003:10003' - '7777:7777/udp' volumes: - - "./assets/docker/gateway.toml:/app/gateway.toml" + - "./docker/gateway.toml:/app/gateway.toml" shorekeeper-game-server: image: shorekeeper-game-server:1.3.0-SNAPSHOT depends_on: @@ -50,7 +50,7 @@ services: # ports: # - '10004:10004' volumes: - - "./assets/docker/gameserver.toml:/app/gameserver.toml" + - "./docker/gameserver.toml:/app/gameserver.toml" - "./assets/logic:/app/assets/logic" shorekeeper-postgres: image: postgres:16.4-alpine3.20 @@ -66,7 +66,7 @@ services: environment: - "POSTGRES_PASSWORD=toor" volumes: - - "./assets/docker/postgres/scripts:/docker-entrypoint-initdb.d" + - "./docker/postgres/scripts:/docker-entrypoint-initdb.d" - shorekeeper-postgres-vol:/var/lib/postgresql/data volumes: shorekeeper-postgres-vol: diff --git a/assets/docker/configserver.toml b/docker/configserver.toml similarity index 100% rename from assets/docker/configserver.toml rename to docker/configserver.toml diff --git a/assets/docker/gameserver.toml b/docker/gameserver.toml similarity index 100% rename from assets/docker/gameserver.toml rename to docker/gameserver.toml diff --git a/assets/docker/gateway.toml b/docker/gateway.toml similarity index 100% rename from assets/docker/gateway.toml rename to docker/gateway.toml diff --git a/assets/docker/hotpatch.toml b/docker/hotpatch.toml similarity index 100% rename from assets/docker/hotpatch.toml rename to docker/hotpatch.toml diff --git a/assets/docker/loginserver.toml b/docker/loginserver.toml similarity index 100% rename from assets/docker/loginserver.toml rename to docker/loginserver.toml diff --git a/assets/docker/postgres/scripts/0_INIT.sql b/docker/postgres/scripts/0_INIT.sql similarity index 100% rename from assets/docker/postgres/scripts/0_INIT.sql rename to docker/postgres/scripts/0_INIT.sql diff --git a/assets/docker/postgres/scripts/1_PERMS.sql b/docker/postgres/scripts/1_PERMS.sql similarity index 100% rename from assets/docker/postgres/scripts/1_PERMS.sql rename to docker/postgres/scripts/1_PERMS.sql -- 2.34.1