From 9afba329c2b4d30b95cba52e5a0f4114f1cd4292 Mon Sep 17 00:00:00 2001 From: a Date: Wed, 11 Sep 2024 20:26:09 +0200 Subject: [PATCH] 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