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/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` diff --git a/builder.bat b/builder.bat new file mode 100644 index 0000000..e7968e9 --- /dev/null +++ b/builder.bat @@ -0,0 +1,12 @@ +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 + +: Persistence for the application +docker volume create shorekeeper-postgres-vol \ No newline at end of file diff --git a/builder.sh b/builder.sh new file mode 100644 index 0000000..46c7e74 --- /dev/null +++ b/builder.sh @@ -0,0 +1,12 @@ +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 + +# 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 new file mode 100644 index 0000000..c88aef3 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,73 @@ +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: + - "./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: + - "./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: + - "./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: + - "./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: + - "./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: + - "./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 diff --git a/docker/configserver.toml b/docker/configserver.toml new file mode 100644 index 0000000..13a18fd --- /dev/null +++ b/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/docker/gameserver.toml b/docker/gameserver.toml new file mode 100644 index 0000000..1e8300d --- /dev/null +++ b/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/docker/gateway.toml b/docker/gateway.toml new file mode 100644 index 0000000..83c75e3 --- /dev/null +++ b/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/docker/hotpatch.toml b/docker/hotpatch.toml new file mode 100644 index 0000000..19ef770 --- /dev/null +++ b/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/docker/loginserver.toml b/docker/loginserver.toml new file mode 100644 index 0000000..d07c8c5 --- /dev/null +++ b/docker/loginserver.toml @@ -0,0 +1,12 @@ +[network] +http_addr = "0.0.0.0:5500" + +[gateway] +host = "host.docker.internal" +port = 7777 + +[database] +host = "shorekeeper-postgres:5432" +user_name = "shorekeeper_user" +password = "shorekeeper_pass" +db_name = "shorekeeper_db" diff --git a/docker/postgres/scripts/0_INIT.sql b/docker/postgres/scripts/0_INIT.sql new file mode 100644 index 0000000..99d9607 --- /dev/null +++ b/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/docker/postgres/scripts/1_PERMS.sql b/docker/postgres/scripts/1_PERMS.sql new file mode 100644 index 0000000..3b4a427 --- /dev/null +++ b/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