Skip to content

Commit

Permalink
Merge pull request #34 from mattlorimor/NonRoot
Browse files Browse the repository at this point in the history
Run container as terraria user
  • Loading branch information
ryansheehan authored May 20, 2020
2 parents 2f04f8f + a34f9b0 commit 73b514e
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ RUN unzip TShock_4.4.0_226_Pre3_Terraria1.4.0.2.zip -d /tshock && \
rm TShock_4.4.0_226_Pre3_Terraria1.4.0.2.zip && \
chmod +x /tshock/tshock/TerrariaServer.exe

# Add bootstrap.sh and make sure it's executable.
# This will be pulled into the final stage.
ADD bootstrap.sh .
RUN chmod +x bootstrap.sh

FROM mono:6.8.0.96-slim

LABEL maintainer="Ryan Sheehan <[email protected]>"
Expand All @@ -20,27 +25,33 @@ ENV WORLDPATH=/world
ENV CONFIGPATH=/world
ENV LOGPATH=/tshock/logs

# copy in bootstrap
COPY bootstrap.sh /tshock/bootstrap.sh

# copy game files
COPY --from=base /tshock/* /tshock

# install nuget to grab tshock dependencies
RUN apt-get update -y && \
# add terraria user to run as
RUN groupadd -r terraria && \
useradd -m -r -g terraria terraria && \
# install nuget to grab tshock dependencies
apt-get update -y && \
apt-get install -y nuget && \
rm -rf /var/lib/apt/lists/* /tmp/* && \
# create directories
mkdir /tshock && \
mkdir /world && \
mkdir /plugins && \
mkdir -p /tshock/logs && \
chmod +x /tshock/bootstrap.sh
chown -R terraria:terraria /tshock /world /plugins

# copy in bootstrap
COPY --chown=terraria:terraria --from=base bootstrap.sh /tshock/bootstrap.sh

# copy game files
COPY --chown=terraria:terraria --from=base /tshock/* /tshock

# Allow for external data
VOLUME ["/world", "/tshock/logs", "/plugins"]

# Set working directory to server
WORKDIR /tshock

USER terraria

# run the bootstrap, which will copy the TShockAPI.dll before starting the server
ENTRYPOINT [ "/bin/sh", "bootstrap.sh" ]

0 comments on commit 73b514e

Please sign in to comment.