From 1c5ee42f5c33a26fb3b5c74e7e0a1154639f3219 Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Fri, 8 Jun 2018 12:34:37 +0200 Subject: [PATCH] Improve image, add command wrapper Signed-off-by: Knut Ahlers --- Dockerfile | 30 +++++++++++++++++------------- README.md | 15 +++++++++++---- config.ini | 2 +- start.sh | 11 ++++++++--- terraria_cmd.sh | 4 ++++ 5 files changed, 41 insertions(+), 21 deletions(-) create mode 100755 terraria_cmd.sh diff --git a/Dockerfile b/Dockerfile index c8623da..fb74198 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,11 @@ FROM debian:stretch ENV TERRARIA_VERISON=1353 \ - DUMB_INIT_VERSION=1.2.1 + DUMB_INIT_VERSION=1.2.1 \ + GOSU_VERSION=1.10 \ + TERRARIA_DOCKER_VERSION=v0.1.0 \ + HOME=/home/gameserver \ + SERVER=/home/gameserver/terraria RUN set -ex \ && apt-get update \ @@ -12,22 +16,22 @@ RUN set -ex \ unzip \ && useradd -m gameserver \ && mkdir /data && chown gameserver: /data \ - && curl -sSfLo /usr/local/bin/dumb-init https://github.com/Yelp/dumb-init/releases/download/v${DUMB_INIT_VERSION}/dumb-init_${DUMB_INIT_VERSION}_amd64 \ - && chmod +x /usr/local/bin/dumb-init \ - && rm -rf /var/cache/apk/* - -USER gameserver -ENV HOME /home/gameserver -ENV SERVER $HOME/terraria - -RUN set -ex \ + && curl -sSfLo /usr/local/bin/dumb-init "https://github.com/Yelp/dumb-init/releases/download/v${DUMB_INIT_VERSION}/dumb-init_${DUMB_INIT_VERSION}_amd64" \ + && curl -sSfLo /usr/local/bin/gosu https://github.com/tianon/gosu/releases/download/${GOSU_VERSION}/gosu-amd64 \ + && curl -sSfL "https://github.com/Luzifer/terraria-docker/releases/download/${TERRARIA_DOCKER_VERSION}/terraria-docker_linux_amd64.tar.gz" | tar -xz -C /usr/local/bin \ + && chmod +x \ + /usr/local/bin/dumb-init \ + /usr/local/bin/gosu \ && mkdir -p ${SERVER} \ - && curl -sSLo /tmp/terraria.zip http://terraria.org/server/terraria-server-${TERRARIA_VERISON}.zip && unzip -d ${SERVER} /tmp/terraria.zip \ - && ln -s ${SERVER}/terraria-server-* ${SERVER}/server \ - && rm /tmp/terraria.zip + && curl -sSfLo /tmp/terraria.zip "http://terraria.org/server/terraria-server-${TERRARIA_VERISON}.zip" \ + && unzip -d ${SERVER} /tmp/terraria.zip \ + && chown -R gameserver:gameserver ${SERVER} \ + && rm /tmp/terraria.zip \ + && rm -rf /var/lib/apt/lists/* COPY config.ini ${SERVER}/config.ini.default COPY start.sh ${SERVER}/start.sh +COPY terraria_cmd.sh /usr/local/bin/terraria_cmd VOLUME /data EXPOSE 7777/udp 7777 diff --git a/README.md b/README.md index 4bc40c2..61b205e 100644 --- a/README.md +++ b/README.md @@ -6,13 +6,20 @@ This image contains a [Terraria](http://terraria.org/) 1.3.5.3 server with autom You can simply run the image with the default settings: -``` -docker run -d -p 7777:7777 luzifer/terraria +```console +$ docker run -d --name=terraria -p 7777:7777 luzifer/terraria ``` If you want the world to persist you can mount a volume into the container: -``` -docker run -d -p 7777:7777 -v ~/terraria:/data luzifer/terraria +```console +$ docker run -d --name=terraria -p 7777:7777 -v ~/terraria:/data luzifer/terraria ``` +### Interacting with the server command line + +In case you want to use the [console commands](https://terraria.gamepedia.com/Server#List_of_console_commands) on the Terraria server this image has a helper for you: + +```console +$ docker exec terraria terraria_cmd save +``` diff --git a/config.ini b/config.ini index d23ffbd..0eeec19 100644 --- a/config.ini +++ b/config.ini @@ -30,7 +30,7 @@ world=/data/world/Terraria.wld #Creates a new world if none is found. World size is specified by: 1(small), 2(medium), and 3(large). #autocreate=1 -autocreate=3 +autocreate=1 #Sets the world seed when using autocreate #seed=AwesomeSeed diff --git a/start.sh b/start.sh index f45a7e8..d8bf2c4 100755 --- a/start.sh +++ b/start.sh @@ -1,8 +1,8 @@ -#!/bin/bash +#!/usr/local/bin/dumb-init /bin/bash set -euxo pipefail if ! [ -e /data/config.ini ]; then - cp ${SERVER}/config.ini.default /data/config.ini + cp ${SERVER}/config.ini.default /data/config.ini fi SERVER_BINARY=$(find /home/gameserver -name 'TerrariaServer.bin.x86_64') @@ -10,4 +10,9 @@ SERVER_BINARY=$(find /home/gameserver -name 'TerrariaServer.bin.x86_64') # FIX: The ZIP archive does not have correct permissions chmod +x "${SERVER_BINARY}" -exec tail -f /dev/null | "${SERVER_BINARY}" -config /data/config.ini "$@" +# Force data path to be writable +chown -R gameserver:gameserver /data + +exec terraria-docker_linux_amd64 | /usr/local/bin/gosu \ + gameserver \ + ${SERVER_BINARY} -config /data/config.ini "$@" diff --git a/terraria_cmd.sh b/terraria_cmd.sh new file mode 100755 index 0000000..5be9a45 --- /dev/null +++ b/terraria_cmd.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -euo pipefail + +echo "$@" >/home/gameserver/terraria_cmd