Skip to content

General tidying, cleanup and optimisation #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
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
5 changes: 4 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
garrysmod-data
Dockerfile
README.md
.dockerignore
docker-compose.yaml
71 changes: 38 additions & 33 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,44 +1,49 @@
#####################################################################
# Dockerfile that builds a GMOD Gameserver - modified from CS Scrim #
#####################################################################
FROM cm2network/steamcmd:root
FROM steamcmd/steamcmd
MAINTAINER Ryan Smith <[email protected]>
MAINTAINER Laura Demkowicz-Duffy <[email protected]>

ENV STEAMAPPID 4020
ENV STEAMAPP garrysmod
ENV STEAMAPPDIR "${HOMEDIR}/${STEAMAPP}-dedicated"
ENV GAMETYPE "TTT"
ARG UID=999

COPY entry.sh ${HOMEDIR}/entry.sh
RUN set -x \
&& mkdir -p "${STEAMAPPDIR}" \
&& { \
echo '@ShutdownOnFailedCommand 1'; \
echo '@NoPromptForPassword 1'; \
echo 'login anonymous'; \
echo 'force_install_dir '"${STEAMAPPDIR}"''; \
echo 'app_update '"${STEAMAPPID}"''; \
echo 'quit'; \
} > "${HOMEDIR}/${STEAMAPP}_update.txt" \
&& { \
echo '"mountcfg"'; \
echo '{'; \
echo '"cstrike" "'${HOMEDIR}'/css/cstrike"'; \
echo '"tf" "'${HOMEDIR}'/tf2/tf"'; \
echo '}'; \
} > "${HOMEDIR}/mount.cfg" \
&& chmod +x "${HOMEDIR}/entry.sh" \
&& chown -R "${USER}:${USER}" "${HOMEDIR}/entry.sh" "${STEAMAPPDIR}" "${HOMEDIR}/${STEAMAPP}_update.txt" \
&& rm -rf /var/lib/apt/lists/*

ENV SRCDS_PORT=27015
# Server defaults
ENV GAMETYPE "sandbox"
ENV DEFAULT_MAP "gm_flatgrass"
ENV WORKSHOP_COLLECTION "0"
ENV RCON_PWD "changeme"
ENV SRCDS_TOKEN=0

USER ${USER}
# Directory layout
ENV CONFIG_DIR "/config"
ENV UPDATE_SCRIPT "${CONFIG_DIR}/${STEAMAPP}_update.txt"
ENV MOUNT_CONFIG "${CONFIG_DIR}/mount.cfg"
ENV HOME /home/gmoduser

VOLUME ${STEAMAPPDIR}
# Create user + directories
RUN useradd -m -s /bin/false -u ${UID} -d ${HOME} gmoduser && \
mkdir -vp ${CONFIG_DIR} /garrysmod /css /tf2 && \
chown -vR gmoduser:gmoduser \
${CONFIG_DIR} /garrysmod /css /tf2

WORKDIR ${HOMEDIR}
# Install required game content
USER gmoduser
RUN steamcmd +force_install_dir /css \
+login anonymous \
+app_update "232330" validate \
+quit
RUN steamcmd +force_install_dir /tf2 \
+login anonymous \
+app_update "232250" validate \
+quit

EXPOSE ${SRCDS_PORT}/udp ${SRCDS_PORT}/tcp
# Copy scripts/config in
COPY --chown=gmoduser entry.sh /entry.sh
COPY --chown=gmoduser mount.cfg ${MOUNT_CONFIG}
COPY --chown=gmoduser garrysmod_update.txt ${UPDATE_SCRIPT}

CMD ["bash", "entry.sh"]
# I/O
VOLUME /garrysmod
WORKDIR /garrysmod
EXPOSE 27015/udp
ENTRYPOINT ["bash", "/entry.sh"]
20 changes: 12 additions & 8 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
version: "3"

services:
gmod:
build: .
volumes:
- ./garrysmod-data/:/home/steam/garrysmod-dedicated/
network_mode: "host"
environment:
- SRCDS_PORT=27015
environment:
- SRCDS_TOKEN=0
- GAMETYPE=TTT
- RCON_PWD=changeme
- GAMETYPE=terrortown
- RCON_PWD=changeme
image: fragsoc/gmod
ports:
- "27015:27015/udp"
volumes:
- garrysmod-data:/garrysmod

volumes:
garrysmod-data:
87 changes: 17 additions & 70 deletions entry.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,73 +1,20 @@
mkdir -p "${STEAMAPPDIR}" || true
#!/usr/bin/env bash


if [[ ! -d "${HOMEDIR}/css" ]]
then
echo "CSS and TF2 not installed, installing"

# CSS
bash "${STEAMCMDDIR}/steamcmd.sh" +login anonymous \
+force_install_dir "${HOMEDIR}/css" \
+app_update "232330" \
+quit

# TF2
bash "${STEAMCMDDIR}/steamcmd.sh" +login anonymous \
+force_install_dir "${HOMEDIR}/tf2" \
+app_update "232250" \
+quit
fi

# GMOD
bash "${STEAMCMDDIR}/steamcmd.sh" +login anonymous \
+force_install_dir "${STEAMAPPDIR}" \
+app_update "${STEAMAPPID}" \
+quit
# Update/install gmod itself
bash steamcmd +runscript "${UPDATE_SCRIPT}"

# Mount CSS and TF2
cp "${HOMEDIR}/mount.cfg" "${STEAMAPPDIR}/garrysmod/cfg/"

cd ${STEAMAPPDIR}

case "$GAMETYPE" in
"TTT")
echo "Configuring TTT Server"
game_type="terrortown"
workshop_collection="2372649360"
default_map="ttt_minecraftcity_v4" ;;
"Prop")
echo "Configuring PropHunt Server"
game_type="prophunters"
workshop_collection="2372656179"
default_map="ph_lotparking" ;;
# Needs adding
"Murder")
echo "Configuring Murder Server"
game_type="murder"
workshop_collection="2120021421"
default_map="ttt_Clue_se" ;;
"Homicide")
echo "Configuring Homicide Server"
game_type="homicide"
workshop_collection="2372659912"
default_map="ttt_Clue_se" ;;
*)
echo "No gametype was set so running sandbox"
game_type="sandbox"
workshop_collection=""
default_map="gm_flatgrass" ;;
esac

# Run GMOD
bash "${STEAMAPPDIR}/srcds_run" -game "${STEAMAPP}" -console -autoupdate \
-steam_dir "${STEAMCMDDIR}" \
-steamcmd_script "${HOMEDIR}/${STEAMAPP}_update.txt" \
-usercon \
-port "${SRCDS_PORT}" \
+gamemode "$game_type" \
+map "$default_map" \
+host_workshop_collection "$workshop_collection" \
+rcon_password "${RCON_PWD}"
+sv_setsteamaccount "${SRCDS_TOKEN}"


cp -v "${MOUNT_CONFIG}" /garrysmod/garrysmod/cfg/mount.cfg

# Run GMOD, passing commands through
./srcds_run -game garrysmod -console -autoupdate \
-steam_dir "${HOME}/.steam" \
-steamcmd_script "${UPDATE_SCRIPT}" \
-usercon \
-port 27015 \
+gamemode "${GAMETYPE}" \
+map "${DEFAULT_MAP}" \
+host_workshop_collection "${WORKSHOP_COLLECTION}" \
+rcon_password "${RCON_PWD}" \
+sv_setsteamaccount "${SRCDS_TOKEN}" \
$@
6 changes: 6 additions & 0 deletions garrysmod_update.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@ShutdownOnFailedCommand 1
@NoPromptForPassword 1
login anonymous
force_install_dir /garrysmod
app_update 4020
quit
5 changes: 5 additions & 0 deletions mount.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"mountcfg"
{
"cstrike" "/steamapps/css/cstrike"
"tf" "/steamapps/tf2/tf"
}