diff --git a/tshock/Dockerfile b/tshock/Dockerfile index 8c4db14..b6874c3 100644 --- a/tshock/Dockerfile +++ b/tshock/Dockerfile @@ -31,21 +31,21 @@ RUN set -eux; \ # do not use -slim due to mysql/tshock requirements FROM mcr.microsoft.com/dotnet/runtime:6.0 -LABEL org.opencontainers.image.authors="Logan Saso " -LABEL org.opencontainers.image.url="https://github.com/logaintech/terraria" +LABEL org.opencontainers.image.authors="Ryan Sheehan " +LABEL org.opencontainers.image.url="https://github.com/ryansheehan/terraria" LABEL org.opencontainers.image.documentation="Dockerfile for Terraria" -LABEL org.opencontainers.image.source="https://github.com/logansaso/terraria/blob/master/tshock/Dockerfile" +LABEL org.opencontainers.image.source="https://github.com/ryansheehan/terraria/blob/master/tshock/Dockerfile" # documenting ports EXPOSE 7777 7878 # env used in the bootstrap -ENV WORLD_PATH=/root/.local/share/Terraria/Worlds -ENV CONFIG_PATH=/config -ENV LOG_PATH=/tshock/logs +ENV CONFIGPATH=/root/.local/share/Terraria/Worlds +ENV LOGPATH=/tshock/logs +ENV WORLD_FILENAME="" # Allow for external data -VOLUME ["/root/.local/share/Terraria/Worlds", "/config", "/tshock/logs", "/tshock/ServerPlugins"] +VOLUME ["/root/.local/share/Terraria/Worlds", "/tshock/logs", "/tshock/ServerPlugins", "/config"] # install nuget to grab tshock dependencies RUN apt-get update -y && \ @@ -54,9 +54,11 @@ RUN apt-get update -y && \ # copy game files COPY --from=base /tshock/ /tshock/ -COPY --from=base /tshock/ServerPlugins /plugins/ +# Copy the plugin files to a place that bootstrap can copy them to the plugins folder at runtime +COPY --from=base /tshock/ServerPlugins/ /plugins # Set working directory to server WORKDIR /tshock +# run the bootstrap, which will copy the TShockAPI.dll before starting the server ENTRYPOINT [ "/bin/sh", "bootstrap.sh" ] diff --git a/tshock/bootstrap.sh b/tshock/bootstrap.sh index 3facf5b..e2ac2be 100755 --- a/tshock/bootstrap.sh +++ b/tshock/bootstrap.sh @@ -1,20 +1,53 @@ #!/bin/bash -if [ $(jq -r '.Settings.StorageType' $CONFIG_PATH/config.json) = "mysql" ]; then - DATABASE_SERVER=$(jq -r '.Settings.MySqlHost' $CONFIG_PATH/config.json | cut -f1 -d':') - DATABASE_PORT=$(jq -r '.Settings.MySqlHost' $CONFIG_PATH/config.json | cut -f2 -d':') - DATABASE_USER_NAME=$(jq -r '.Settings.MySqlUsername' $CONFIG_PATH/config.json) - DATABASE_USER_PASSWORD=$(jq -r '.Settings.MySqlPassword' $CONFIG_PATH/config.json) +echo "\nBootstrap:\nworld_file_name=$WORLD_FILENAME\nconfigpath=$CONFIGPATH\nlogpath=$LOGPATH\n" + +# Copy plugins if the folder is empty (like on first run) +if [ -z "$(ls -A /tshock/ServerPlugins)" ]; then + echo "Copying plugins..." + cp /plugins/* /tshock/ServerPlugins +fi + + +if [ $(jq -r '.Settings.StorageType' $CONFIGPATH/config.json) = "mysql" ]; then + DATABASE_SERVER=$(jq -r '.Settings.MySqlHost' $CONFIGPATH/config.json | cut -f1 -d':') + DATABASE_PORT=$(jq -r '.Settings.MySqlHost' $CONFIGPATH/config.json | cut -f2 -d':') + DATABASE_USER_NAME=$(jq -r '.Settings.MySqlUsername' $CONFIGPATH/config.json) + DATABASE_USER_PASSWORD=$(jq -r '.Settings.MySqlPassword' $CONFIGPATH/config.json) echo "Waiting for the database server." while ! mysql -h$DATABASE_SERVER -P$DATABASE_PORT -u$DATABASE_USER_NAME -p$DATABASE_USER_PASSWORD -e ";" ; do sleep 0.1; done fi -if [ -z "$(ls -A /tshock/ServerPlugins)" ]; then - echo "Copying plugins..." - cp /plugins/* /tshock/ServerPlugins -fi +WORLD_PATH="/root/.local/share/Terraria/Worlds/$WORLD_FILENAME" -echo "./TShock.Server -config \"$CONFIG_PATH/serverconfig.txt\" -configpath \"$CONFIG_PATH\" -logpath \"$LOG_PATH\" -worldpath /root/.local/share/Terraria/Worlds/ \"$@\"" -./TShock.Server -config "$CONFIG_PATH/serverconfig.txt" -configpath "$CONFIG_PATH" -logpath "$LOG_PATH" -worldpath /root/.local/share/Terraria/Worlds/ "$@" \ No newline at end of file +autocreate_flag=false +for arg in "$@"; do + if [ "$arg" = "-autocreate" ]; then + autocreate_flag=true + break + fi +done + + +if [ -z "$WORLD_FILENAME" ]; then + echo "No world file specified in environment WORLD_FILENAME." + if [ -z "$@" ]; then + echo "Running server setup..." + else + echo "Running server with command flags: $@" + fi + ./TShock.Server -configpath "$CONFIGPATH" -logpath "$LOGPATH" "$@" +else + echo "Environment WORLD_FILENAME specified" + if [ -f "$WORLD_PATH" ] || [ "$autocreate_flag" = true ]; then + echo "Loading to world $WORLD_FILENAME..." + ./TShock.Server -configpath "$CONFIGPATH" -logpath "$LOGPATH" -world "$WORLD_PATH" "$@" + else + echo "Unable to locate $WORLD_PATH and -autocreate flag is not set." + echo "Please make sure your world file is volumed into docker: -v :/root/.local/share/Terraria/Worlds" + echo "Alternatively, use the -autocreate flag to create a new world." + exit 1 + fi +fi