Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 11 additions & 20 deletions terraria/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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
2 changes: 1 addition & 1 deletion terraria/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
34 changes: 0 additions & 34 deletions terraria/data/configs/serverconfig.txt

This file was deleted.

49 changes: 0 additions & 49 deletions terraria/generate_config.sh

This file was deleted.

59 changes: 56 additions & 3 deletions terraria/run.sh
Original file line number Diff line number Diff line change
@@ -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 <<EOF >> /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"