Skip to content

Commit

Permalink
Merge pull request #162 from loganintech/logan/revert-to-only-upstrea…
Browse files Browse the repository at this point in the history
…m-changes

Fix breaking changes in #161
  • Loading branch information
ryansheehan authored Jan 1, 2024
2 parents 78d3b93 + dfce550 commit dbeef9a
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 19 deletions.
18 changes: 10 additions & 8 deletions tshock/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 <logansaso+tech@gmail.com>"
LABEL org.opencontainers.image.url="https://github.com/logaintech/terraria"
LABEL org.opencontainers.image.authors="Ryan Sheehan <rsheehan@gmail.com>"
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 && \
Expand All @@ -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" ]
55 changes: 44 additions & 11 deletions tshock/bootstrap.sh
Original file line number Diff line number Diff line change
@@ -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/ "$@"
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 <path_to_world_file>:/root/.local/share/Terraria/Worlds"
echo "Alternatively, use the -autocreate flag to create a new world."
exit 1
fi
fi

0 comments on commit dbeef9a

Please sign in to comment.