diff --git a/terraria/Dockerfile b/terraria/Dockerfile index 2a7f340..867077d 100644 --- a/terraria/Dockerfile +++ b/terraria/Dockerfile @@ -1,31 +1,19 @@ -FROM debian:9.6-slim +FROM ubuntu:latest as builder ARG VERSION=1423 -ENV VERSION=${VERSION} - WORKDIR /games/terraria - -ADD https://terraria.org/api/download/pc-dedicated-server/terraria-server-${VERSION}.zip /games/terraria.zip -COPY ./data /data -COPY ./run.sh /games/terraria/run.sh -COPY ./generate_config.sh /games/terraria/generate_config.sh +ADD https://terraria.org/api/download/pc-dedicated-server/terraria-server-${VERSION}.zip /games/terraria.zip RUN apt-get update \ && apt-get install -y unzip \ && apt-get clean RUN unzip ../terraria.zip \ - && cp -R ${VERSION}/Linux/* /games/terraria \ - && rm -rf ${VERSION} terraria.zip + && cp -R ${VERSION}/Linux/* /games/terraria -RUN groupadd terraria \ - && useradd -d /games/terraria -g terraria -u 1000 -o -s /bin/bash terraria \ - && mkdir -p /games/terraria /data/configs /data/saves \ - && chmod +x /games/terraria/run.sh /games/terraria/TerrariaServer.bin.* \ - && chown -cR terraria:terraria /games /data/ \ - && chmod -R u=rwx,g=rwx,o=rx /data/ +FROM ubuntu:latest as server #Sets the name of the world when using autocreate ENV T_WORLD_NAME "MobyWorld" @@ -51,11 +39,14 @@ ENV T_SECURE 1 #Sets the server language from its language code. en/US = English de/DE = German it/IT = Italian fr/FR = French es/ES = Spanish ru/RU = Russian zh/Hans = Chinese pt/BR = Portuguese pl/PL = Polish ENV T_LANG "en/US" -USER terraria +ENV PUID 1000 +ENV PGID 1000 + +COPY --from=builder /games/ /games/ +COPY ./run.sh /games/terraria/run.sh -VOLUME ["/data/saves", "/data/configs"] +VOLUME "/data" EXPOSE 7777 -ENTRYPOINT ["/games/terraria/run.sh"] -CMD ["-config /data/configs/serverconfig.txt"] +ENTRYPOINT /games/terraria/run.sh diff --git a/terraria/README.md b/terraria/README.md index d21ef12..7dd355b 100644 --- a/terraria/README.md +++ b/terraria/README.md @@ -21,4 +21,4 @@ Dedicated server for Terraria ## Volumes - `/data/saves`: game saves -- `/data/configs/serverconfig.txt`: https://terraria.fandom.com/wiki/Server#Server_config_file +- `/configs/serverconfig.txt`: https://terraria.fandom.com/wiki/Server#Server_config_file diff --git a/terraria/data/configs/serverconfig.txt b/terraria/data/configs/serverconfig.txt deleted file mode 100644 index d05ff82..0000000 --- a/terraria/data/configs/serverconfig.txt +++ /dev/null @@ -1,34 +0,0 @@ -#Sets the max number of players allowed on a server. Value must be between 1 and 255 -maxplayers=8 - -#Set the port number -port=7777 - -#Set the server password -password= -#Set the message of the day -motd=Please don’t cut the purple trees! - -#Sets the folder where world files will be stored -worldpath=/data/saves/worlds/ - -#Load a world and automatically start the server. -world=/data/saves/worlds/world1.wld - -#Creates a new world if none is found. World size is specified by: 1(small), 2(medium), and 3(large). -autocreate=2 - -#Sets world difficulty when using -autocreate. Options: 0(normal), 1(expert) -difficulty=0 - -#Sets the name of the world when using autocreate -worldname=World - -#The location of the banlist. Defaults to "banlist.txt" in the working directory. -banlist=/data/configs/banlist.txt - -#Adds additional cheat protection. -secure=1 - -#Sets the server language from its language code. en/US = English de/DE = German it/IT = Italian fr/FR = French es/ES = Spanish ru/RU = Russian zh/Hans = Chinese pt/BR = Portuguese pl/PL = Polish -language=en/US diff --git a/terraria/generate_config.sh b/terraria/generate_config.sh deleted file mode 100755 index c5ecf34..0000000 --- a/terraria/generate_config.sh +++ /dev/null @@ -1,49 +0,0 @@ -#!/bin/bash - -if [ -z "${T_WORLD_NAME}" ]; then export T_WORLD_NAME="MobyWorld"; fi -if [ -z "${T_MAX_PLAYERS}" ]; then export T_MAX_PLAYERS=8; fi -if [ -z "${T_PORT}" ]; then export T_PORT=7777; fi -if [ -z "${T_PASSWORD}" ]; then export T_WORLD_NAME=""; fi -if [ -z "${T_MOTD}" ]; then export T_MOTD="Please don't cut the purple trees! Save the whales!"; fi -if [ -z "${T_WORLD_SIZE}" ]; then export T_WORLD_SIZE=2; fi -if [ -z "${T_DIFFICULTY}" ]; then export T_DIFFICULTY=0; fi -if [ -z "${T_SECURE}" ]; then export T_SECURE=1; fi -if [ -z "${T_LANG}" ]; then export T_SECURE="en/US"; fi - -cat <> /data/configs/serverconfig.txt -#Sets the name of the world when using autocreate -worldname=${T_WORLD_NAME} - -#Sets the max number of players allowed on a server. Value must be between 1 and 255 -maxplayers=${T_MAX_PLAYERS} - -#Set the port number -port=${T_PORT} - -#Set the server password -password=${T_PASSWORD} - -#Set the message of the day -motd=${T_MOTD} - -#Sets the folder where world files will be stored -worldpath=/data/saves/worlds/ - -#Load a world and automatically start the server. -world=/data/saves/worlds/world1.wld - -#Creates a new world if none is found. World size is specified by: 1(small), 2(medium), and 3(large). -autocreate=${T_WORLD_SIZE} - -#Sets world difficulty when using -autocreate. Options: 0(normal), 1(expert) -difficulty=${T_DIFFICULTY} - -#The location of the banlist. Defaults to "banlist.txt" in the working directory. -banlist=/data/configs/banlist.txt - -#Adds additional cheat protection. -secure=${T_SECURE} - -#Sets the server language from its language code. en/US = English de/DE = German it/IT = Italian fr/FR = French es/ES = Spanish ru/RU = Russian zh/Hans = Chinese pt/BR = Portuguese pl/PL = Polish -language=${T_LANG} -EOF diff --git a/terraria/run.sh b/terraria/run.sh index 9701d99..20fa223 100755 --- a/terraria/run.sh +++ b/terraria/run.sh @@ -1,10 +1,63 @@ #!/bin/bash -if [ -f /data/configs/serverconfig.txt ]; then +if [ -f /configs/serverconfig.txt ]; then echo "using existing config" else echo "generating config based on env" - ./generate_config.sh +cat <> /configs/serverconfig.txt +#Sets the name of the world when using autocreate +worldname=${T_WORLD_NAME:-MobyWorld} + +#Sets the max number of players allowed on a server. Value must be between 1 and 255 +maxplayers=${T_MAX_PLAYERS:-8} + +#Set the port number +port=${T_PORT:-7777} + +#Set the server password +password=${T_PASSWORD} + +#Set the message of the day +motd=${T_MOTD:-"Please don't cut the purple trees! Save the whales!"} + +#Sets the folder where world files will be stored +worldpath=/data/saves/worlds/ + +#Load a world and automatically start the server. +world=/data/saves/worlds/world1.wld + +#Creates a new world if none is found. World size is specified by: 1(small), 2(medium), and 3(large). +autocreate=${T_WORLD_SIZE:-2} + +#Sets world difficulty when using -autocreate. Options: 0(normal), 1(expert) +difficulty=${T_DIFFICULTY:-0} + +#The location of the banlist. Defaults to "banlist.txt" in the working directory. +banlist=/configs/banlist.txt + +#Adds additional cheat protection. +secure=${T_SECURE:-1} + +#Sets the server language from its language code. en/US = English de/DE = German it/IT = Italian fr/FR = French es/ES = Spanish ru/RU = Russian zh/Hans = Chinese pt/BR = Portuguese pl/PL = Polish +language=${T_LANG:-"en/US"} +EOF + +fi + +mkdir -p "/data/saves"; + +PUSER=terraria; +if [ -z "$(cat /etc/group | grep ${PGID})" ]; then + addgroup -q --gecos "" --gid ${PGID} ${PUSER}; fi -exec /games/terraria/TerrariaServer.bin.x86_64 $@ +if [ -z "$(cat /etc/passwd | grep ${PUID})" ]; then + adduser -q --gecos "" --uid ${PUID} --gid ${PGID} --disabled-password --disabled-login --no-create-home ${PUSER}; +fi + +chown -R ${PUID}:${PGID} /data; +chown -R ${PUID}:${PGID} /configs; +chown -R ${PUID}:${PGID} /games; + + +exec su ${PUSER} -c "/games/terraria/TerrariaServer.bin.x86_64 -config /configs/serverconfig.txt"