From 1e66be56ff4fbcada3c56146f5172aa8c7836a25 Mon Sep 17 00:00:00 2001 From: Rohanlogs Date: Wed, 8 Jan 2025 16:30:40 +0200 Subject: [PATCH 01/15] feat(infra): Remove version declarement, add MariaDb prod services --- docker-compose.yml | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index c86b3c87bd..06658252ad 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,4 +1,5 @@ -version: "3.8" +# version: "3.8" +# Compose V2 doesn't require a version anymore: `version` is obsolete" services: 2004scape: @@ -17,3 +18,41 @@ services: - 80:80 - 43594:43594 - 43595:43595 + profiles: + - dev + + db: + image: mariadb:10.5 + environment: + MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASS} + MYSQL_DATABASE: ${DB_NAME} + MYSQL_USER: ${DB_USER} + MYSQL_PASSWORD: ${DB_PASS} + volumes: + - ./mysql_data:/var/lib/mysql + ports: + - "3306:3306" + profiles: + - prod + env_file: + - .env + healthcheck: + test: ["CMD", "mariadb-admin", "ping", "-h", "localhost", "-u${DB_USER}", "-p${DB_PASS}"] + interval: 10s + retries: 5 + start_period: 10s + + db_migrate: + build: . + command: ["/bin/bash", "-c", "npm run db:migrate"] + depends_on: + db: + condition: service_healthy + profiles: + - prod + env_file: + - .env + deploy: + restart_policy: + condition: none + restart: "no" From b5e814018185840fa7fc5bd1c15de4f897501d3f Mon Sep 17 00:00:00 2001 From: Rohanlogs Date: Wed, 8 Jan 2025 16:35:29 +0200 Subject: [PATCH 02/15] feat(infra): Add composer pull for website rerpository and launch it --- docker-compose.yml | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/docker-compose.yml b/docker-compose.yml index 06658252ad..d5ab887e09 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -14,6 +14,7 @@ services: - MEMBERS_WORLD - XP_MULTIPLIER - PROD_MODE + # TODO: Env vars? ports: - 80:80 - 43594:43594 @@ -21,6 +22,7 @@ services: profiles: - dev + # MySQL Database service, uses MariaDB db: image: mariadb:10.5 environment: @@ -30,18 +32,23 @@ services: MYSQL_PASSWORD: ${DB_PASS} volumes: - ./mysql_data:/var/lib/mysql + # TODO: Env vars? ports: - "3306:3306" profiles: - prod env_file: - .env + # Migration waits till our database is up and running + # Stops if failed 5 times, 10 second intervals healthcheck: test: ["CMD", "mariadb-admin", "ping", "-h", "localhost", "-u${DB_USER}", "-p${DB_PASS}"] interval: 10s retries: 5 start_period: 10s + # Migration service (this should be deleted afterwards) + # Runs database migrations after database is setup successfully db_migrate: build: . command: ["/bin/bash", "-c", "npm run db:migrate"] @@ -56,3 +63,32 @@ services: restart_policy: condition: none restart: "no" + + # Website service, pull remote repository, and run it + website: + image: node:latest + working_dir: /usr/src/app + # Creates a default world configuration + # TODO: This is a bit hacky, make this configurable + command: ["/bin/bash", "-c", "git clone https://github.com/2004Scape/Website.git /usr/src/app && mkdir -p /usr/src/app/data/config && echo '[{\"id\": 1, \"region\": \"Local Development\", \"address\": \"http://localhost:80\", \"members\": \"false\", \"portOffset\": 0}]' > /usr/src/app/data/config/worlds.json && cd /usr/src/app && npm install && npm start"] + environment: + PUBLIC_IP: localhost + # TODO: env vars? + WEB_PORT: 3000 + SKIP_CORS: false + HTTPS_ENABLED: false + ADDRESS_SHOWPORT: false + LOGIN_HOST: localhost + LOGIN_KEY: abcdef + profiles: + - fullstack + env_file: + - .env + # TODO: Env vars? + ports: + - 3000:3000 + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost:3000"] + interval: 10s + retries: 5 + start_period: 10s From fbaaca59cb0e439c50136c283348c93a5e545c30 Mon Sep 17 00:00:00 2001 From: Rohanlogs Date: Wed, 8 Jan 2025 16:36:46 +0200 Subject: [PATCH 03/15] feat(infra): Add login, friend and logger services --- docker-compose.yml | 48 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/docker-compose.yml b/docker-compose.yml index d5ab887e09..9f7c83e56d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -92,3 +92,51 @@ services: interval: 10s retries: 5 start_period: 10s + + login: + build: . + command: ["npm", "run", "login"] + # TODO: Login key used? + environment: + - LOGIN_KEY=abcde + depends_on: + - website + profiles: + - fullstack + env_file: + - .env + # TODO: Env vars + ports: + - 43500:43500 + + logger: + build: . + command: ["npm", "run", "logger"] + # TODO: Env vars + environment: + - LOGIN_KEY=abcde + depends_on: + - login + profiles: + - fullstack + env_file: + - .env + # TODO: Env vars + ports: + - 43501:43501 + + friend: + build: . + command: ["npm", "run", "friend"] + # TODO: Env vars + environment: + - LOGIN_KEY=abcde + depends_on: + - logger + profiles: + - fullstack + env_file: + - .env + # TODO: Env vars + ports: + - 45099:45099 From c4a0a80cbf97217bae8d064424176e36b30ca2ce Mon Sep 17 00:00:00 2001 From: Rohanlogs Date: Wed, 8 Jan 2025 16:40:04 +0200 Subject: [PATCH 04/15] feat(infra): Add server composer for production build --- docker-compose.yml | 44 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 9f7c83e56d..fbdd1eeca2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -81,7 +81,7 @@ services: LOGIN_HOST: localhost LOGIN_KEY: abcdef profiles: - - fullstack + - prod env_file: - .env # TODO: Env vars? @@ -102,7 +102,7 @@ services: depends_on: - website profiles: - - fullstack + - prod env_file: - .env # TODO: Env vars @@ -118,7 +118,7 @@ services: depends_on: - login profiles: - - fullstack + - prod env_file: - .env # TODO: Env vars @@ -134,9 +134,45 @@ services: depends_on: - logger profiles: - - fullstack + - prod env_file: - .env # TODO: Env vars ports: - 45099:45099 + + # Server composer + server: + build: + context: . + dockerfile: ./Dockerfile + command: ["npm", "run", "start"] + environment: + - PUBLIC_IP + - WEB_PORT + - GAME_PORT + - LOCAL_DEV + - MEMBERS_WORLD + - XP_MULTIPLIER + - PROD_MODE + # Important, point host into its service names + # Don't change these: + - LOGGER_HOST=logger + - FRIEND_HOST=friend + - LOGIN_HOST=login + depends_on: + website: + # Wait for website to launch successfully + # This essentially waits till the entire thing is done + # Server build is quite fast, so after this is done, it should pretty much be live + condition: service_healthy + profiles: + - prod + # TODO: Env vars + ports: + - 80:80 + - 8898:8898 + - 43594:43594 + - 43595:43595 + env_file: + - .env From 60938ec1adcfbb102c3889bd6577135eba1645fb Mon Sep 17 00:00:00 2001 From: Rohanlogs Date: Wed, 8 Jan 2025 16:41:27 +0200 Subject: [PATCH 05/15] feat(infra): Create windows .bat script to launch production container --- prod_build.bat | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 prod_build.bat diff --git a/prod_build.bat b/prod_build.bat new file mode 100644 index 0000000000..1f075bc638 --- /dev/null +++ b/prod_build.bat @@ -0,0 +1,21 @@ +@echo off +echo. + +echo [INFO] Please wait.. This can take a minute.. +docker-compose --profile fullstack up -d +if %ERRORLEVEL% NEQ 0 ( + echo [!] Failed to start containers.. Something went wrong.. Stopping.. + docker-compose down + pause + exit /b %ERRORLEVEL% +) + +echo [INFO] Services started successfully! + +docker-compose rm -f db_migrate + +echo. + +echo [INFO] Done! + +pause From ff1fe87c8cc62d753eea91f8e455744345019a8b Mon Sep 17 00:00:00 2001 From: Rohanlogs Date: Wed, 8 Jan 2025 16:43:35 +0200 Subject: [PATCH 06/15] feat(infra): Create production environment file for fullstack container --- .env_prod | 84 ++++++++++++++++++++++++++++++++++++++++++++++ docker-compose.yml | 15 +++++---- 2 files changed, 92 insertions(+), 7 deletions(-) create mode 100644 .env_prod diff --git a/.env_prod b/.env_prod new file mode 100644 index 0000000000..6ebeb6bd05 --- /dev/null +++ b/.env_prod @@ -0,0 +1,84 @@ +# ----------------------------------------------------- # +# ------------------- CONFIGURABLES ------------------- # +# ----------------------------------------------------- # +# Login key +LOGIN_KEY=abcde # Unsure if this is used anywhere + +# Docker uses this to define mysql root password +DB_ROOT_PASS=rootpassword +# Used by website & server +DB_NAME=lostcity +# Used by website & server +DB_USER=user +# Used by website & server +DB_PASS=userpw +# Format: mysql://DB_USER:DB_PASS@DB_HOST:3306/DB_NAME +DATABASE_URL=mysql://user:userpw@db:3306/lostcity + +# Service ports +WEB_PORT=80 +WEB_MANAGEMENT_PORT=8898 +FRIEND_PORT=45099 +LOGGER_PORT=43501 +NODE_PORT=43594 +LOGIN_PORT=43500 + +# Default world +NODE_ID=10 +# Is the world members? +NODE_MEMBERS=false +# XP rate of this world +NODE_XPRATE=1 + +# Administrator username +# Enables administrator commands for this player +# TODO: make this a config? Currently only one admin can be set +NODE_STAFF= + + +# -------------------------------------------------------- # +# ------------- Other configurations --------------------- # +# ------------- Can be left untouched -------------------- # +# ------------- unless you know what you're doing -------- # +# -------------------------------------------------------- # +# CORS allows safe cross-domain requests when explicitly permitted +# Should be enabled in prod +WEB_CORS=true + +# World +# Enables trackers, observers, reboot timer, and other production game functions +NODE_PRODUCTION=true +NODE_KILLTIMER=50 +# We wouldn't want cheats for production +NODE_ALLOW_CHEATS=false +NODE_DEBUG=false +NODE_DEBUG_PROFILE=false +NODE_CLIENT_ROUTEFINDER=true +NODE_SOCKET_TIMEOUT=true +NODE_WALKTRIGGER_SETTING=0 + +# Login service +LOGIN_SERVER=true +LOGIN_HOST=localhost + +# Friend service +FRIEND_SERVER=true +FRIEND_HOST=localhost + +# Logger service +LOGGER_SERVER=true +LOGGER_HOST=localhost + +# Database +# Host -> docker service name +# Don't change this, unless you change compose.yml +DB_HOST=db + +# Build +BUILD_JAVA_PATH=java +BUILD_STARTUP=true +BUILD_STARTUP_UPDATE=true +BUILD_VERIFY=true +BUILD_VERIFY_FOLDER=true +BUILD_VERIFY_PACK=true +BUILD_SRC_DIR=data/src diff --git a/docker-compose.yml b/docker-compose.yml index fbdd1eeca2..b26e425fe9 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -15,6 +15,7 @@ services: - XP_MULTIPLIER - PROD_MODE # TODO: Env vars? + # TODO: Env file ports: - 80:80 - 43594:43594 @@ -38,7 +39,7 @@ services: profiles: - prod env_file: - - .env + - .env_prod # Migration waits till our database is up and running # Stops if failed 5 times, 10 second intervals healthcheck: @@ -58,7 +59,7 @@ services: profiles: - prod env_file: - - .env + - .env_prod deploy: restart_policy: condition: none @@ -83,7 +84,7 @@ services: profiles: - prod env_file: - - .env + - .env_prod # TODO: Env vars? ports: - 3000:3000 @@ -104,7 +105,7 @@ services: profiles: - prod env_file: - - .env + - .env_prod # TODO: Env vars ports: - 43500:43500 @@ -120,7 +121,7 @@ services: profiles: - prod env_file: - - .env + - .env_prod # TODO: Env vars ports: - 43501:43501 @@ -136,7 +137,7 @@ services: profiles: - prod env_file: - - .env + - .env_prod # TODO: Env vars ports: - 45099:45099 @@ -175,4 +176,4 @@ services: - 43594:43594 - 43595:43595 env_file: - - .env + - .env_prod From 5c6441ef03b593c549f2e6d1ab4e94426363329f Mon Sep 17 00:00:00 2001 From: Rohanlogs Date: Wed, 8 Jan 2025 16:48:46 +0200 Subject: [PATCH 07/15] feat(infra): Add prod database files into gitignore --- .gitignore | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index f27d58c70b..e4d8a80354 100644 --- a/.gitignore +++ b/.gitignore @@ -26,9 +26,11 @@ data/config/login.json data/config/friend.json dump/ - node_modules/ +# prod build mysql database +mysql_data/ + # keep these precompiled files out of the repo bz2.dll JagCompress.jar From c89df28367268f95d4ea8cc7b2cd4e42e09cba4e Mon Sep 17 00:00:00 2001 From: Rohanlogs Date: Wed, 8 Jan 2025 17:05:37 +0200 Subject: [PATCH 08/15] feat(infra): Use proper env variables in composer --- .env_prod | 15 ++++++---- docker-compose.yml | 69 ++++++++++++++++------------------------------ 2 files changed, 32 insertions(+), 52 deletions(-) diff --git a/.env_prod b/.env_prod index 6ebeb6bd05..87d5c33f11 100644 --- a/.env_prod +++ b/.env_prod @@ -1,10 +1,12 @@ +# This is an example of production build environment vars + # ----------------------------------------------------- # # ------------------- CONFIGURABLES ------------------- # # ----------------------------------------------------- # -# Login key -LOGIN_KEY=abcde # Unsure if this is used anywhere +# Login key, unsure if used anywhere +LOGIN_KEY=abcde -# Docker uses this to define mysql root password +# Configure these: DB_ROOT_PASS=rootpassword # Used by website & server DB_NAME=lostcity @@ -15,15 +17,16 @@ DB_PASS=userpw # Format: mysql://DB_USER:DB_PASS@DB_HOST:3306/DB_NAME DATABASE_URL=mysql://user:userpw@db:3306/lostcity -# Service ports -WEB_PORT=80 +# Service ports, change these optionally +WEB_PORT=3000 WEB_MANAGEMENT_PORT=8898 FRIEND_PORT=45099 LOGGER_PORT=43501 NODE_PORT=43594 LOGIN_PORT=43500 +MYSQL_PORT=3306 -# Default world +# Default world, change these optionally NODE_ID=10 # Is the world members? NODE_MEMBERS=false diff --git a/docker-compose.yml b/docker-compose.yml index b26e425fe9..22c6a11f3c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,27 +2,27 @@ # Compose V2 doesn't require a version anymore: `version` is obsolete" services: + # --------------- Dev --------------- # + # + # This launches the development server (no auth/db, only the game) + # Uses .env for environment variables 2004scape: build: context: . dockerfile: ./Dockerfile - environment: - - PUBLIC_IP - - WEB_PORT - - GAME_PORT - - LOCAL_DEV - - MEMBERS_WORLD - - XP_MULTIPLIER - - PROD_MODE - # TODO: Env vars? - # TODO: Env file ports: - - 80:80 - - 43594:43594 - - 43595:43595 + - "${WEB_PORT}:80" + - "${NODE_PORT}:43594" + # Unsure what this is? Is this leftover? + - 43595:43595 profiles: - dev - + env_file: + - .env + + # --------------- Production --------------- # + # Everything below is for production build + # # MySQL Database service, uses MariaDB db: image: mariadb:10.5 @@ -33,9 +33,8 @@ services: MYSQL_PASSWORD: ${DB_PASS} volumes: - ./mysql_data:/var/lib/mysql - # TODO: Env vars? ports: - - "3306:3306" + - "${MYSQL_PORT}:3306" profiles: - prod env_file: @@ -72,22 +71,12 @@ services: # Creates a default world configuration # TODO: This is a bit hacky, make this configurable command: ["/bin/bash", "-c", "git clone https://github.com/2004Scape/Website.git /usr/src/app && mkdir -p /usr/src/app/data/config && echo '[{\"id\": 1, \"region\": \"Local Development\", \"address\": \"http://localhost:80\", \"members\": \"false\", \"portOffset\": 0}]' > /usr/src/app/data/config/worlds.json && cd /usr/src/app && npm install && npm start"] - environment: - PUBLIC_IP: localhost - # TODO: env vars? - WEB_PORT: 3000 - SKIP_CORS: false - HTTPS_ENABLED: false - ADDRESS_SHOWPORT: false - LOGIN_HOST: localhost - LOGIN_KEY: abcdef profiles: - prod env_file: - .env_prod - # TODO: Env vars? ports: - - 3000:3000 + - "${WEB_PORT}:3000" healthcheck: test: ["CMD", "curl", "-f", "http://localhost:3000"] interval: 10s @@ -97,9 +86,6 @@ services: login: build: . command: ["npm", "run", "login"] - # TODO: Login key used? - environment: - - LOGIN_KEY=abcde depends_on: - website profiles: @@ -108,7 +94,7 @@ services: - .env_prod # TODO: Env vars ports: - - 43500:43500 + - "${LOGIN_PORT}:43500" logger: build: . @@ -122,9 +108,8 @@ services: - prod env_file: - .env_prod - # TODO: Env vars ports: - - 43501:43501 + - "${LOGGER_PORT}:43501" friend: build: . @@ -138,9 +123,8 @@ services: - prod env_file: - .env_prod - # TODO: Env vars ports: - - 45099:45099 + - "${FRIEND_PORT}:45099" # Server composer server: @@ -149,13 +133,6 @@ services: dockerfile: ./Dockerfile command: ["npm", "run", "start"] environment: - - PUBLIC_IP - - WEB_PORT - - GAME_PORT - - LOCAL_DEV - - MEMBERS_WORLD - - XP_MULTIPLIER - - PROD_MODE # Important, point host into its service names # Don't change these: - LOGGER_HOST=logger @@ -169,11 +146,11 @@ services: condition: service_healthy profiles: - prod - # TODO: Env vars ports: - - 80:80 - - 8898:8898 - - 43594:43594 + - "${WEB_PORT}:3000" + - "${NODE_PORT}:43594" + - "${WEB_MANAGEMENT_PORT}:8898" + # Still don't know what this is - 43595:43595 env_file: - .env_prod From b1d297b3ba6b3b2742641f0f2f38cc878f2063fa Mon Sep 17 00:00:00 2001 From: Rohanlogs Date: Wed, 8 Jan 2025 19:54:20 +0200 Subject: [PATCH 09/15] feat(infra): Fix profile, port, add MYSQL_PORT to examples --- .env.example | 2 ++ .env_prod | 31 ++++++++++++++++++++++++++----- docker-compose.yml | 17 ++++++----------- prod_build.bat | 2 +- 4 files changed, 35 insertions(+), 17 deletions(-) diff --git a/.env.example b/.env.example index 5af54d1eb4..ce8004e1c8 100644 --- a/.env.example +++ b/.env.example @@ -4,6 +4,8 @@ ## web server # WEB_PORT=80 # WEB_CORS=false +# Used only in prod, so this can be left blank (otherwise docker composer throws a warning) +# MYSQL_PORT= ## management server # WEB_MANAGEMENT_PORT=8898 diff --git a/.env_prod b/.env_prod index 87d5c33f11..ee85d70494 100644 --- a/.env_prod +++ b/.env_prod @@ -6,6 +6,29 @@ # Login key, unsure if used anywhere LOGIN_KEY=abcde +# Set to true if you're using https +HTTPS_ENABLED=false +# Set your domain here, if you're using domain +PUBLIC_IP=localhost + +# CORS allows safe cross-domain requests when explicitly permitted +# Should be enabled in prod IF HTTPS is enabled +# If not using HTTPS, can be disabled, otherwise auto-redirect will forward you to https: +WEB_CORS=false +SKIP_CORS=false +ADDRESS_SHOWPORT=true +ADMIN_IP=localhost + +DB_HOST=localhost +DB_NAME=lostcity +DB_USER=user +DB_PASS=userpw + +LOGIN_HOST=localhost +LOGIN_PORT=43500 +LOGIN_KEY=abcde + + # Configure these: DB_ROOT_PASS=rootpassword # Used by website & server @@ -14,11 +37,12 @@ DB_NAME=lostcity DB_USER=user # Used by website & server DB_PASS=userpw -# Format: mysql://DB_USER:DB_PASS@DB_HOST:3306/DB_NAME +# Format: mysql://DB_USER:DB_PASS@DB_HOST:MYSQL_PORT/DB_NAME DATABASE_URL=mysql://user:userpw@db:3306/lostcity # Service ports, change these optionally -WEB_PORT=3000 +# WEB_PORT recommended to be 80, change if you know what you're doing +WEB_PORT=80 WEB_MANAGEMENT_PORT=8898 FRIEND_PORT=45099 LOGGER_PORT=43501 @@ -44,9 +68,6 @@ NODE_STAFF= # ------------- Can be left untouched -------------------- # # ------------- unless you know what you're doing -------- # # -------------------------------------------------------- # -# CORS allows safe cross-domain requests when explicitly permitted -# Should be enabled in prod -WEB_CORS=true # World # Enables trackers, observers, reboot timer, and other production game functions diff --git a/docker-compose.yml b/docker-compose.yml index 22c6a11f3c..b501af7a65 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -13,8 +13,6 @@ services: ports: - "${WEB_PORT}:80" - "${NODE_PORT}:43594" - # Unsure what this is? Is this leftover? - - 43595:43595 profiles: - dev env_file: @@ -70,15 +68,16 @@ services: working_dir: /usr/src/app # Creates a default world configuration # TODO: This is a bit hacky, make this configurable - command: ["/bin/bash", "-c", "git clone https://github.com/2004Scape/Website.git /usr/src/app && mkdir -p /usr/src/app/data/config && echo '[{\"id\": 1, \"region\": \"Local Development\", \"address\": \"http://localhost:80\", \"members\": \"false\", \"portOffset\": 0}]' > /usr/src/app/data/config/worlds.json && cd /usr/src/app && npm install && npm start"] + # TODO: Forces http + command: ["/bin/bash", "-c", "git clone https://github.com/2004Scape/Website.git /usr/src/app && mkdir -p /usr/src/app/data/config && echo '[{\"id\": 10, \"region\": \"Local Development\", \"address\": \"http://localhost:${WEB_PORT}\", \"members\": \"false\", \"portOffset\": 0}]' > /usr/src/app/data/config/worlds.json && cd /usr/src/app && npm install && npm start"] profiles: - prod env_file: - .env_prod ports: - - "${WEB_PORT}:3000" + - "${WEB_PORT}:80" healthcheck: - test: ["CMD", "curl", "-f", "http://localhost:3000"] + test: ["CMD", "curl", "-f", "http://localhost:${WEB_PORT}"] interval: 10s retries: 5 start_period: 10s @@ -92,7 +91,6 @@ services: - prod env_file: - .env_prod - # TODO: Env vars ports: - "${LOGIN_PORT}:43500" @@ -133,8 +131,8 @@ services: dockerfile: ./Dockerfile command: ["npm", "run", "start"] environment: - # Important, point host into its service names - # Don't change these: + # Important: point host into its docker service names + # Don't change these, unless you know what you're doing: - LOGGER_HOST=logger - FRIEND_HOST=friend - LOGIN_HOST=login @@ -147,10 +145,7 @@ services: profiles: - prod ports: - - "${WEB_PORT}:3000" - "${NODE_PORT}:43594" - "${WEB_MANAGEMENT_PORT}:8898" - # Still don't know what this is - - 43595:43595 env_file: - .env_prod diff --git a/prod_build.bat b/prod_build.bat index 1f075bc638..e012157432 100644 --- a/prod_build.bat +++ b/prod_build.bat @@ -2,7 +2,7 @@ echo. echo [INFO] Please wait.. This can take a minute.. -docker-compose --profile fullstack up -d +docker-compose --profile prod up -d if %ERRORLEVEL% NEQ 0 ( echo [!] Failed to start containers.. Something went wrong.. Stopping.. docker-compose down From eed1cbfd872220a6a93cb36677f5d30dcdb2962d Mon Sep 17 00:00:00 2001 From: Rohanlogs Date: Thu, 9 Jan 2025 21:46:53 +0200 Subject: [PATCH 10/15] feat(infra): Fix web service port to work with game service --- .env_prod | 8 ++------ docker-compose.yml | 18 ++++++++++++------ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/.env_prod b/.env_prod index ee85d70494..00bc0c0759 100644 --- a/.env_prod +++ b/.env_prod @@ -24,10 +24,6 @@ DB_NAME=lostcity DB_USER=user DB_PASS=userpw -LOGIN_HOST=localhost -LOGIN_PORT=43500 -LOGIN_KEY=abcde - # Configure these: DB_ROOT_PASS=rootpassword @@ -41,19 +37,19 @@ DB_PASS=userpw DATABASE_URL=mysql://user:userpw@db:3306/lostcity # Service ports, change these optionally -# WEB_PORT recommended to be 80, change if you know what you're doing WEB_PORT=80 WEB_MANAGEMENT_PORT=8898 FRIEND_PORT=45099 LOGGER_PORT=43501 NODE_PORT=43594 LOGIN_PORT=43500 +# Recommended to keep at 3006 MYSQL_PORT=3306 # Default world, change these optionally NODE_ID=10 # Is the world members? -NODE_MEMBERS=false +NODE_MEMBERS=true # XP rate of this world NODE_XPRATE=1 diff --git a/docker-compose.yml b/docker-compose.yml index b501af7a65..790b8d545a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -69,15 +69,21 @@ services: # Creates a default world configuration # TODO: This is a bit hacky, make this configurable # TODO: Forces http - command: ["/bin/bash", "-c", "git clone https://github.com/2004Scape/Website.git /usr/src/app && mkdir -p /usr/src/app/data/config && echo '[{\"id\": 10, \"region\": \"Local Development\", \"address\": \"http://localhost:${WEB_PORT}\", \"members\": \"false\", \"portOffset\": 0}]' > /usr/src/app/data/config/worlds.json && cd /usr/src/app && npm install && npm start"] + # TODO: Currently uses custom branch (where https redirect is fixed) + # git clone https://github.com/2004Scape/Website.git + # git clone -b fix/https_env_var https://github.com/Rohanlogs/2004Scape-Website.git + command: ["/bin/bash", "-c", "git clone -b fix/https_env_var https://github.com/Rohanlogs/2004Scape-Website.git /usr/src/app && mkdir -p /usr/src/app/data/config && echo '[{\"id\": 10, \"region\": \"Local Development\", \"address\": \"http://localhost:${WEB_PORT}\", \"members\": \"true\", \"portOffset\": 0}]' > /usr/src/app/data/config/worlds.json && cd /usr/src/app && npm install && npm start"] profiles: - prod env_file: - .env_prod + # Important, we have to keep separate ports with web service & game + environment: + WEB_PORT: 3000 ports: - - "${WEB_PORT}:80" + - "3000:3000" healthcheck: - test: ["CMD", "curl", "-f", "http://localhost:${WEB_PORT}"] + test: ["CMD", "curl", "-f", "http://localhost:3000"] interval: 10s retries: 5 start_period: 10s @@ -112,9 +118,6 @@ services: friend: build: . command: ["npm", "run", "friend"] - # TODO: Env vars - environment: - - LOGIN_KEY=abcde depends_on: - logger profiles: @@ -136,6 +139,7 @@ services: - LOGGER_HOST=logger - FRIEND_HOST=friend - LOGIN_HOST=login + - DB_HOST=db depends_on: website: # Wait for website to launch successfully @@ -145,7 +149,9 @@ services: profiles: - prod ports: + - "${WEB_PORT}:80" - "${NODE_PORT}:43594" - "${WEB_MANAGEMENT_PORT}:8898" + - 43595:43595 env_file: - .env_prod From d0129e383014a7dea66b1244db40623586cd5979 Mon Sep 17 00:00:00 2001 From: Rohanlogs Date: Thu, 9 Jan 2025 22:10:30 +0200 Subject: [PATCH 11/15] feat(infra): Remove redundant line --- docker-compose.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 790b8d545a..3f13fd7cc0 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,5 +1,5 @@ # version: "3.8" -# Compose V2 doesn't require a version anymore: `version` is obsolete" +# Compose V2 doesn't require a version anymore: `version` is obsolete services: # --------------- Dev --------------- # @@ -103,9 +103,6 @@ services: logger: build: . command: ["npm", "run", "logger"] - # TODO: Env vars - environment: - - LOGIN_KEY=abcde depends_on: - login profiles: From d6617d9eb2bf4f562efabe6cee604a71c39ac199 Mon Sep 17 00:00:00 2001 From: Rohanlogs Date: Fri, 10 Jan 2025 17:39:16 +0200 Subject: [PATCH 12/15] feat(infra): Add world script & dynamic configuration --- docker-compose.yml | 14 ++++++++------ src/prodWorldsConf.js | 16 ++++++++++++++++ 2 files changed, 24 insertions(+), 6 deletions(-) create mode 100644 src/prodWorldsConf.js diff --git a/docker-compose.yml b/docker-compose.yml index 3f13fd7cc0..1feba36dff 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -66,13 +66,11 @@ services: website: image: node:latest working_dir: /usr/src/app - # Creates a default world configuration - # TODO: This is a bit hacky, make this configurable - # TODO: Forces http - # TODO: Currently uses custom branch (where https redirect is fixed) + # Creates world configuration + # TODO: Fix repo # git clone https://github.com/2004Scape/Website.git - # git clone -b fix/https_env_var https://github.com/Rohanlogs/2004Scape-Website.git - command: ["/bin/bash", "-c", "git clone -b fix/https_env_var https://github.com/Rohanlogs/2004Scape-Website.git /usr/src/app && mkdir -p /usr/src/app/data/config && echo '[{\"id\": 10, \"region\": \"Local Development\", \"address\": \"http://localhost:${WEB_PORT}\", \"members\": \"true\", \"portOffset\": 0}]' > /usr/src/app/data/config/worlds.json && cd /usr/src/app && npm install && npm start"] + # git clone -b infra/world_generation https://github.com/Rohanlogs/2004Scape-Website.git + command: ["/bin/bash", "-c", "git clone -b infra/world_generation https://github.com/Rohanlogs/2004Scape-Website.git /usr/src/app && cd /usr/src/app && node src/lostcity/util/dockerWorldsConf.js && npm install && npm start"] profiles: - prod env_file: @@ -80,6 +78,10 @@ services: # Important, we have to keep separate ports with web service & game environment: WEB_PORT: 3000 + WORLD_CONFIG_PATH: /usr/src/app/prodWorldsConf.js + # Add this file so website service can access it + volumes: + - ./src/prodWorldsConf.js:/usr/src/prodWorldsConf.js ports: - "3000:3000" healthcheck: diff --git a/src/prodWorldsConf.js b/src/prodWorldsConf.js new file mode 100644 index 0000000000..2ebbbd49ad --- /dev/null +++ b/src/prodWorldsConf.js @@ -0,0 +1,16 @@ +export default [ + { + id: 10, + region: process.env.REGION || 'Docker Test #1', + address: `http://localhost:${process.env.WEB_PORT || 3000}`, + members: process.env.MEMBERS_WORLD === 'true', + portOffset: 0 + }, + { + id: 11, + region: process.env.REGION || 'Another Region #2', + address: `http://localhost:${process.env.WEB_PORT || 3000}`, + members: process.env.MEMBERS_WORLD === 'true', + portOffset: 0 + } +]; From 3ceca0afa218a37e8b27dc5d6c73574542b65f3c Mon Sep 17 00:00:00 2001 From: Rohanlogs Date: Fri, 10 Jan 2025 18:12:08 +0200 Subject: [PATCH 13/15] feat(infra): Add worlds conf, phpMyAdmin service for MySQL interface --- .env.example | 1 + .env_prod | 8 ++++++-- docker-compose.yml | 24 +++++++++++++++++++++++- src/prodWorldsConf.js | 4 ++-- 4 files changed, 32 insertions(+), 5 deletions(-) diff --git a/.env.example b/.env.example index ce8004e1c8..099592bd7f 100644 --- a/.env.example +++ b/.env.example @@ -6,6 +6,7 @@ # WEB_CORS=false # Used only in prod, so this can be left blank (otherwise docker composer throws a warning) # MYSQL_PORT= +# DB_UPLOAD_LIMIT= ## management server # WEB_MANAGEMENT_PORT=8898 diff --git a/.env_prod b/.env_prod index 00bc0c0759..5e238b1f83 100644 --- a/.env_prod +++ b/.env_prod @@ -3,8 +3,9 @@ # ----------------------------------------------------- # # ------------------- CONFIGURABLES ------------------- # # ----------------------------------------------------- # -# Login key, unsure if used anywhere -LOGIN_KEY=abcde + +# Database dump upload limit (not actual db limit) +DB_UPLOAD_LIMIT=2G # Set to true if you're using https HTTPS_ENABLED=false @@ -94,6 +95,9 @@ LOGGER_HOST=localhost # Don't change this, unless you change compose.yml DB_HOST=db +# Login key, unsure if used anywhere +LOGIN_KEY=abcde + # Build BUILD_JAVA_PATH=java BUILD_STARTUP=true diff --git a/docker-compose.yml b/docker-compose.yml index 1feba36dff..4250cf70c1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -62,6 +62,27 @@ services: condition: none restart: "no" + # Database interface with basic authentication + phpmyadmin: + image: phpmyadmin/phpmyadmin + environment: + PMA_HOST: db + PMA_PORT: 3306 + MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASS} + UPLOAD_LIMIT: ${DB_UPLOAD_LIMIT} + # Optional basic auth for minimal protection + MYSQL_USER: ${DB_USER} + MYSQL_PASSWORD: ${DB_PASS} + ports: + - "8080:80" + depends_on: + db: + condition: service_healthy + env_file: + - .env_prod + profiles: + - prod + # Website service, pull remote repository, and run it website: image: node:latest @@ -75,8 +96,9 @@ services: - prod env_file: - .env_prod - # Important, we have to keep separate ports with web service & game environment: + # Important, we have to keep separate ports with web service & game + WORLD_REDIRECT: ${WEB_PORT} WEB_PORT: 3000 WORLD_CONFIG_PATH: /usr/src/app/prodWorldsConf.js # Add this file so website service can access it diff --git a/src/prodWorldsConf.js b/src/prodWorldsConf.js index 2ebbbd49ad..f4da751e57 100644 --- a/src/prodWorldsConf.js +++ b/src/prodWorldsConf.js @@ -2,14 +2,14 @@ export default [ { id: 10, region: process.env.REGION || 'Docker Test #1', - address: `http://localhost:${process.env.WEB_PORT || 3000}`, + address: `http://localhost:${process.env.WORLD_REDIRECT || 80}`, members: process.env.MEMBERS_WORLD === 'true', portOffset: 0 }, { id: 11, region: process.env.REGION || 'Another Region #2', - address: `http://localhost:${process.env.WEB_PORT || 3000}`, + address: `http://localhost:${process.env.WORLD_REDIRECT || 80}`, members: process.env.MEMBERS_WORLD === 'true', portOffset: 0 } From 8e9e828e9a541321488508d5f6facf85dc22c8cd Mon Sep 17 00:00:00 2001 From: Rohanlogs Date: Fri, 10 Jan 2025 20:22:54 +0200 Subject: [PATCH 14/15] feat(infra): Add Linux build script, refactor compose var orders --- .env.example | 7 ++-- .env_prod | 8 ++-- docker-compose.yml | 97 +++++++++++++++++++++------------------------- prod_build.sh | 22 +++++++++++ 4 files changed, 75 insertions(+), 59 deletions(-) create mode 100644 prod_build.sh diff --git a/.env.example b/.env.example index 099592bd7f..dfd29dee5e 100644 --- a/.env.example +++ b/.env.example @@ -4,9 +4,10 @@ ## web server # WEB_PORT=80 # WEB_CORS=false -# Used only in prod, so this can be left blank (otherwise docker composer throws a warning) -# MYSQL_PORT= -# DB_UPLOAD_LIMIT= + +# Prod build +# MYSQL_PORT=3306 +# DB_UPLOAD_LIMIT=2G ## management server # WEB_MANAGEMENT_PORT=8898 diff --git a/.env_prod b/.env_prod index 5e238b1f83..902d6cfba6 100644 --- a/.env_prod +++ b/.env_prod @@ -41,7 +41,7 @@ DATABASE_URL=mysql://user:userpw@db:3306/lostcity WEB_PORT=80 WEB_MANAGEMENT_PORT=8898 FRIEND_PORT=45099 -LOGGER_PORT=43501 +LOGGER_PORT=43501 NODE_PORT=43594 LOGIN_PORT=43500 # Recommended to keep at 3006 @@ -57,7 +57,7 @@ NODE_XPRATE=1 # Administrator username # Enables administrator commands for this player # TODO: make this a config? Currently only one admin can be set -NODE_STAFF= +NODE_STAFF= # -------------------------------------------------------- # @@ -69,11 +69,11 @@ NODE_STAFF= # World # Enables trackers, observers, reboot timer, and other production game functions NODE_PRODUCTION=true -NODE_KILLTIMER=50 +NODE_KILLTIMER=50 # We wouldn't want cheats for production NODE_ALLOW_CHEATS=false NODE_DEBUG=false -NODE_DEBUG_PROFILE=false +NODE_DEBUG_PROFILE=false NODE_CLIENT_ROUTEFINDER=true NODE_SOCKET_TIMEOUT=true NODE_WALKTRIGGER_SETTING=0 diff --git a/docker-compose.yml b/docker-compose.yml index 4250cf70c1..b85ccc89df 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,27 +2,11 @@ # Compose V2 doesn't require a version anymore: `version` is obsolete services: - # --------------- Dev --------------- # - # - # This launches the development server (no auth/db, only the game) - # Uses .env for environment variables - 2004scape: - build: - context: . - dockerfile: ./Dockerfile - ports: - - "${WEB_PORT}:80" - - "${NODE_PORT}:43594" - profiles: - - dev - env_file: - - .env - - # --------------- Production --------------- # - # Everything below is for production build - # - # MySQL Database service, uses MariaDB db: + profiles: + - prod + env_file: + - .env_prod image: mariadb:10.5 environment: MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASS} @@ -33,10 +17,6 @@ services: - ./mysql_data:/var/lib/mysql ports: - "${MYSQL_PORT}:3306" - profiles: - - prod - env_file: - - .env_prod # Migration waits till our database is up and running # Stops if failed 5 times, 10 second intervals healthcheck: @@ -48,15 +28,15 @@ services: # Migration service (this should be deleted afterwards) # Runs database migrations after database is setup successfully db_migrate: + profiles: + - prod + env_file: + - .env_prod build: . command: ["/bin/bash", "-c", "npm run db:migrate"] depends_on: db: condition: service_healthy - profiles: - - prod - env_file: - - .env_prod deploy: restart_policy: condition: none @@ -64,6 +44,10 @@ services: # Database interface with basic authentication phpmyadmin: + profiles: + - prod + env_file: + - .env_prod image: phpmyadmin/phpmyadmin environment: PMA_HOST: db @@ -78,13 +62,13 @@ services: depends_on: db: condition: service_healthy - env_file: - - .env_prod - profiles: - - prod # Website service, pull remote repository, and run it website: + profiles: + - prod + env_file: + - .env_prod image: node:latest working_dir: /usr/src/app # Creates world configuration @@ -92,10 +76,6 @@ services: # git clone https://github.com/2004Scape/Website.git # git clone -b infra/world_generation https://github.com/Rohanlogs/2004Scape-Website.git command: ["/bin/bash", "-c", "git clone -b infra/world_generation https://github.com/Rohanlogs/2004Scape-Website.git /usr/src/app && cd /usr/src/app && node src/lostcity/util/dockerWorldsConf.js && npm install && npm start"] - profiles: - - prod - env_file: - - .env_prod environment: # Important, we have to keep separate ports with web service & game WORLD_REDIRECT: ${WEB_PORT} @@ -113,43 +93,47 @@ services: start_period: 10s login: + profiles: + - prod + env_file: + - .env_prod build: . command: ["npm", "run", "login"] depends_on: - website - profiles: - - prod - env_file: - - .env_prod ports: - "${LOGIN_PORT}:43500" logger: + profiles: + - prod + env_file: + - .env_prod build: . command: ["npm", "run", "logger"] depends_on: - login - profiles: - - prod - env_file: - - .env_prod ports: - "${LOGGER_PORT}:43501" friend: + profiles: + - prod + env_file: + - .env_prod build: . command: ["npm", "run", "friend"] depends_on: - logger - profiles: - - prod - env_file: - - .env_prod ports: - "${FRIEND_PORT}:45099" # Server composer server: + profiles: + - prod + env_file: + - .env_prod build: context: . dockerfile: ./Dockerfile @@ -167,12 +151,21 @@ services: # This essentially waits till the entire thing is done # Server build is quite fast, so after this is done, it should pretty much be live condition: service_healthy - profiles: - - prod ports: - "${WEB_PORT}:80" - "${NODE_PORT}:43594" - "${WEB_MANAGEMENT_PORT}:8898" - - 43595:43595 + - "43595:43595" + + # --------------- Dev --------------- # + 2004scape: + profiles: + - dev env_file: - - .env_prod + - .env + build: + context: . + dockerfile: ./Dockerfile + ports: + - "${WEB_PORT}:80" + - "${NODE_PORT}:43594" diff --git a/prod_build.sh b/prod_build.sh new file mode 100644 index 0000000000..06d679791a --- /dev/null +++ b/prod_build.sh @@ -0,0 +1,22 @@ +#!/bin/bash +clear +echo "" +echo "[INFO] Please wait.. This can take a minute.." + +docker-compose --profile prod up -d + +if [ $? -ne 0 ]; then + echo "[!] Failed to start containers.. Something went wrong.. Stopping.." + docker-compose down + read -p "Press Enter to exit..." + exit $? +fi + +echo "[INFO] Services started successfully!" + +docker-compose rm -f db_migrate + +echo "" +echo "[INFO] Done!" + +read -p "Press Enter to exit..." From 8589b8c511f633674da15e5e75a3c940a7a2d3cd Mon Sep 17 00:00:00 2001 From: Rohanlogs Date: Fri, 10 Jan 2025 20:28:41 +0200 Subject: [PATCH 15/15] feat(infra): Fix worlds config to support ip & https vars --- src/prodWorldsConf.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/prodWorldsConf.js b/src/prodWorldsConf.js index f4da751e57..84f93765f9 100644 --- a/src/prodWorldsConf.js +++ b/src/prodWorldsConf.js @@ -1,15 +1,18 @@ +const protocol = process.env.HTTPS_ENABLED === 'true' ? 'https' : 'http'; +const ip = process.env.PUBLIC_IP || 'localhost'; + export default [ { id: 10, region: process.env.REGION || 'Docker Test #1', - address: `http://localhost:${process.env.WORLD_REDIRECT || 80}`, + address: `${protocol}://${ip}:${process.env.WORLD_REDIRECT || 80}`, members: process.env.MEMBERS_WORLD === 'true', portOffset: 0 }, { id: 11, region: process.env.REGION || 'Another Region #2', - address: `http://localhost:${process.env.WORLD_REDIRECT || 80}`, + address: `${protocol}://${ip}:${process.env.WORLD_REDIRECT || 80}`, members: process.env.MEMBERS_WORLD === 'true', portOffset: 0 }