diff --git a/tools/DockerTestServer/.gitignore b/tools/DockerTestServer/.gitignore new file mode 100644 index 00000000000..4c49bd78f1d --- /dev/null +++ b/tools/DockerTestServer/.gitignore @@ -0,0 +1 @@ +.env diff --git a/tools/DockerTestServer/.gitkeep b/tools/DockerTestServer/.gitkeep new file mode 100644 index 00000000000..8b137891791 --- /dev/null +++ b/tools/DockerTestServer/.gitkeep @@ -0,0 +1 @@ + diff --git a/tools/DockerTestServer/README.md b/tools/DockerTestServer/README.md new file mode 100644 index 00000000000..5f52591dc23 --- /dev/null +++ b/tools/DockerTestServer/README.md @@ -0,0 +1,36 @@ +# Docker-Compose Test Server + +This is a directory made for easily spinning up a /tg/station server using Docker-Compose. +Also with some tweaks done to read environment variables, like database config and ranks. + +# How to use this? + +## Prerequisites: +- Docker and `docker-compose` installed +- Text editor +- Basic knowledge about the CLI and containers + +## Quickstart: + +1) Open a terminal (bash,powershell,cmd,whatever) +2) Clone [the /tg/station repository](https://github.com/tgstation/tgstation) ( CLI: `git clone https://github.com/tgstation/tgstation`) +3) Enter this directory (`cd tgstation/tools/DockerTestServer`) +4) Make a copy of the `example.env` file and call it `.env` (`cp example.env .env`) +5) Edit the values in `.env` (the content and commented out sections, seriously, read it) +6) When all and dandy, start the server by doing `docker-compose up` + +After this, you should be able to connect over to your server by opening BYOND and joining your game with an URL that looks like this `byond://localhost:1337` or if you are hosting this on another device `byond://192.168.1.25:1337` or whatever that device's IP or domain is. + +## Turning off the server: + +Same directory as before in the terminal, try `docker-compose down` + +This should turn it off until the next time you turn it on using `docker-compose up` + +# Overriding configuration files + +Since you might need to tweak `game_options.txt` or any other file in the [/config](/config/) folder. + +This setup allows you to slap those files right into the `./gamecfg` folder for overriding files. Just copy the file you want to override into this directory and the `entrypoint.sh` should apply it during start-up! + +Remember to properly take down the container ( `docker-compose down` ) if you have issues with recent changes not syncronizing after restart. \ No newline at end of file diff --git a/tools/DockerTestServer/docker-compose.yml b/tools/DockerTestServer/docker-compose.yml new file mode 100644 index 00000000000..6b85b583770 --- /dev/null +++ b/tools/DockerTestServer/docker-compose.yml @@ -0,0 +1,56 @@ +version: '3.9' + +services: + # /tg/ DM server + dreammaker: + image: tgstation:latest + restart: unless-stopped + build: + context: ../../ + dockerfile: Dockerfile + entrypoint: bash /entrypoint.sh + env_file: + - .env + ports: + - "1337:1337" + depends_on: + - db + volumes: + - ./entrypoint.sh:/entrypoint.sh:ro # + - ../../config:/gamecfg_ro:ro # Contains the default configuration, as defined in config/ + - ./gamecfg:/gamecfg:ro # Contains the override config files, entrypoint.sh overrides using these + - gamedata:/tgstation/data # Contains the game data, contained nicely in a volume + + # MariaDB/MySQL database: game + # (if you don't really need this, feel free to remove this section.) + db: + image: mariadb + restart: unless-stopped + environment: + - MYSQL_RANDOM_ROOT_PASSWORD=yes + - MYSQL_DATABASE=tgstation + - MYSQL_USER=gamelord + - MYSQL_PASSWORD=gamelord + volumes: + - ../../SQL/tgstation_schema.sql:/docker-entrypoint-initdb.d/tgstation_schema.sql:ro + - database:/var/lib/mysql + + # Adminer, for managing the DB, has the 'donotstart' profile attached by default. Remove this line if this is needed + adminer: + image: wodby/adminer + depends_on: + - db + environment: + ADMINER_DEFAULT_DB_DRIVER: mysql + ADMINER_DEFAULT_DB_HOST: db + ADMINER_DEFAULT_DB_NAME: tgstation + ADMINER_DESIGN: nette + ADMINER_PLUGINS: tables-filter tinymce + ports: + - 9000:9000 + profiles: + - donotstart # <--- Remove this line if this service is needed. + +volumes: + gamedata: + database: diff --git a/tools/DockerTestServer/entrypoint.sh b/tools/DockerTestServer/entrypoint.sh new file mode 100644 index 00000000000..a3fa30e7653 --- /dev/null +++ b/tools/DockerTestServer/entrypoint.sh @@ -0,0 +1,85 @@ +#!/bin/bash +RS='\033[0m' +RED='\033[00;31m' +GREEN='\033[00;32m' +YELLOW='\033[00;33m' +BLUE='\033[00;34m' +PURPLE='\033[00;35m' +# Docker entrypoint +# ================= +# What this will do: +# 1) Copy the default config/ files from the read-only volume to /tgstation/config/ +# 2) Override files under /tgstation/config/ with files present in /gamecfg/ +# 3) Process environment variables passed to the container into /tgstation/config/ +# 4) Finally start the DreamDaemon + +# Override game config files +echo -e "${PURPLE}[${YELLOW}---${PURPLE}]${RS} Copying default configuration files..." +cp -frv /gamecfg_ro/* /tgstation/config +echo -e "${PURPLE}[${GREEN}---${PURPLE}]${RS} ${GREEN}Copy complete!${RS}" + +# Override game config files +echo -e "${PURPLE}[${YELLOW}---${PURPLE}]${RS} Overriding config files" +cp -frv /gamecfg/* /tgstation/config +echo -e "${PURPLE}[${GREEN}---${PURPLE}]${RS} ${GREEN}Override complete!${RS}" + +# Override common game options using variables +# +echo -e "${PURPLE}[${YELLOW}---${PURPLE}]${RS} Overriding environment options..." +# Set DB settings +DB_HOST="${DB_HOST:-db}" +DB_USER="${DB_USER:-gamelord}" +DB_PASS="${DB_PASS:-gamelord}" + +sed -i -r 's/(#|^)ADDRESS .*/ADDRESS '"$DB_HOST"'/' /tgstation/config/dbconfig.txt +sed -i -r 's/(#|^)FEEDBACK_LOGIN .*/FEEDBACK_LOGIN '"$DB_USER"'/' /tgstation/config/dbconfig.txt +sed -i -r 's/(#|^)FEEDBACK_PASSWORD .*/FEEDBACK_PASSWORD '"$DB_PASS"'/' /tgstation/config/dbconfig.txt + +function envvar_override () { + ### FUNCTION for overriding options in a file using the exported environment variables + # Syntax: + # envvar_override """ "" + + # Overriding options + PREFIX=$1 + FILENAME=$2 + + env | grep "$PREFIX"| while read p + do + OPTION=`echo $p | cut -d "=" -f 1 | sed s/"$PREFIX"//` + VALUE=`echo $p | cut -d "=" -f 2` + # Comment out logic, comments line out if value is # + if [[ "${VALUE}" == "#" ]]; then + echo "Commenting out option \"$OPTION\" in $FILENAME" + sed -i -r 's/^'"$OPTION"'.*/#&/' "$FILENAME" + else + echo "Injecting option \"$OPTION\" with value \"$VALUE\" in $FILENAME" + sed -i -r 's/(#|^)'"$OPTION"'.*/'"$OPTION"' '"$VALUE"'/' "$FILENAME" + fi + done +} +# Overriding game options +envvar_override "TG_GAME_" "/tgstation/config/game_options.txt" + + +# Setting ranks +export IFS="," +if [[ ! -z "${CKEYRANKS}" ]]; then + echo -e "${PURPLE}[${YELLOW}---${PURPLE}]${RS} Inserting ranks..." + echo "" > /tgstation/config/admins.txt + echo -e "${RED}admins.txt has been reset!${RS}" + for RANK in $CKEYRANKS; do + echo "$( echo $RANK | cut -d '=' -f 1 )is now$( echo $RANK | cut -d '=' -f 2 )" + printf "${RANK}\n" >> /tgstation/config/admins.txt + done + echo -e "${PURPLE}[${GREEN}---${PURPLE}]${RS} ${GREEN}CKEY Ranks set.${RS}" +fi + +echo -e "${PURPLE}[${GREEN}---${PURPLE}]${RS} ${GREEN}Override complete!${RS}" + + +# Start DreamDaemon +echo -e "${PURPLE}[${GREEN}---${PURPLE}]${RS} ${GREEN}Starting DreamDaemon ...${RS}" +echo -e "${PURPLE}[${GREEN}---${PURPLE}]${RS} ${YELLOW}Enjoy! <3${RS}" +cd /tgstation +DreamDaemon tgstation.dmb -port 1337 -trusted -close -verbose \ No newline at end of file diff --git a/tools/DockerTestServer/example.env b/tools/DockerTestServer/example.env new file mode 100644 index 00000000000..5ed3b3a1814 --- /dev/null +++ b/tools/DockerTestServer/example.env @@ -0,0 +1,40 @@ +# Environment file +# ================ + +######## Ranks ######## +# CKEY Rank definition, here is the place to define your rank as a host +# or multiple CKEYS with a rank! +# Incase you want to define multiple CKEYS, split using a comma (,) +# Note: List users here to be made admins with the format: +# ckey = rank name. + +# Example given: +#CKEYRANKS="StackerRobot = Host,Hyeanid = Game Master" + +CKEYRANKS="SomeUsername = Host" + +######## Database setup ######## +# No need to uncomment this unless you have an external database running, +# the defaults for this should be set within the entrypoint.sh +#DB_HOST=db +#DB_USER=gamelord +#DB_PASS=gamelord + +######## Dynamic Options ######## + +### Game options +# Here is where the /config/game_options.txt overrides happen +# this is done dynamically, meaning that you can take any of the Options +# in game_options.txt, prefix it with 'TG_GAME_' and it should override +# or comment out the options in that file during runtime + +# How to use: +# To comment out an option do 'TG_GAME_