From 71a6dd8f47f8df37bcbc111aff078fb67f334c67 Mon Sep 17 00:00:00 2001 From: Laura Demkowicz-Duffy Date: Mon, 15 Feb 2021 15:09:47 +0000 Subject: [PATCH 01/11] Hardcode update and mount scripts --- garrysmod_update.txt | 6 ++++++ mount.cfg | 5 +++++ 2 files changed, 11 insertions(+) create mode 100644 garrysmod_update.txt create mode 100644 mount.cfg diff --git a/garrysmod_update.txt b/garrysmod_update.txt new file mode 100644 index 0000000..35b2ca4 --- /dev/null +++ b/garrysmod_update.txt @@ -0,0 +1,6 @@ +@ShutdownOnFailedCommand 1 +@NoPromptForPassword 1 +login anonymous +force_install_dir /steamapps/garrysmod +app_update 4020 +quit diff --git a/mount.cfg b/mount.cfg new file mode 100644 index 0000000..87d330d --- /dev/null +++ b/mount.cfg @@ -0,0 +1,5 @@ +"mountcfg" +{ +"cstrike" "/steamapps/css/cstrike" +"tf" "/steamapps/tf2/tf" +} From 29cf9021f04e0295ca3e68dc7538b06f4740b0e1 Mon Sep 17 00:00:00 2001 From: Laura Demkowicz-Duffy Date: Mon, 15 Feb 2021 15:16:24 +0000 Subject: [PATCH 02/11] Overhaul dockerfile and entrypoint script Lots of changes here: - Hardcode several variables since they can't really be changed anyway - Add maintainer tags - Use hardcoded scripts instead of generating dynamically, mostly for the sake of readability - Allow more fine grained control over the map and gamemode by the end user - Fix whitespacing - Create a non-privileged user which we have control over - Install CSS and TF2 during the build to try to optimise first-time start performance and to make image size at least slightly more predictable, we weren't updating these anyway - Overhaul directory layout, removing everything from the home directory --- Dockerfile | 68 +++++++++++++++++++++-------------------- entry.sh | 90 ++++++++++++------------------------------------------ 2 files changed, 55 insertions(+), 103 deletions(-) diff --git a/Dockerfile b/Dockerfile index bf78ca2..4e42225 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,43 +2,45 @@ # Dockerfile that builds a GMOD Gameserver - modified from CS Scrim # ##################################################################### FROM cm2network/steamcmd:root +MAINTAINER Ryan Smith +MAINTAINER Laura Demkowicz-Duffy -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 STEAMAPP "garrysmod" ENV SRCDS_TOKEN=0 -USER ${USER} +# Directory layout +ENV STEAMAPPDIR "/${STEAMAPP}" +ENV CONFIG_DIR "/config" +ENV UPDATE_SCRIPT "${CONFIG_DIR}/${STEAMAPP}_update.txt" +ENV MOUNT_CONFIG "${CONFIG_DIR}/mount.cfg" -VOLUME ${STEAMAPPDIR} - -WORKDIR ${HOMEDIR} +# Create user, directories and required game content +RUN useradd -s /bin/false -u ${UID} gmoduser && \ + mkdir -p ${CONFIG_DIR} ${STEAMAPPDIR} /css /tf2 && \ + steamcmd +login anonymous \ + +force_install_dir /css \ + +app_update "232330" validate \ + +force_install_dir /tf2 \ + +app_update "232250" validate \ + +quit && \ + chown -R gmoduser:gmoduser \ + ${CONFIG_DIR} ${STEAMAPPDIR} /css /tf2 -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"] \ No newline at end of file +# I/O +USER gmoduser +VOLUME ${STEAMAPPDIR} +WORKDIR ${STEAMAPPDIR} +EXPOSE 27015/udp +ENTRYPOINT ["bash", "/entry.sh"] diff --git a/entry.sh b/entry.sh index 2a47305..f4fd798 100644 --- a/entry.sh +++ b/entry.sh @@ -1,73 +1,23 @@ -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 +login anonymous \ + +force_install_dir "${STEAMAPPDIR}" \ + +app_update 4020 validate \ + +quit # 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}" - - +ln -s "${MOUNT_CONFIG}" "${STEAMAPPDIR}/cfg/mount.cfg" + +# Run GMOD, passing commands through +./srcds_run -game "${STEAMAPP}" -console -autoupdate \ + -steam_dir "${STEAMCMDDIR}" \ + -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}" \ + $@ From d121aa712c03b77a92fa41ed86dbb0193cd6c9ff Mon Sep 17 00:00:00 2001 From: Laura Demkowicz-Duffy Date: Mon, 15 Feb 2021 15:24:10 +0000 Subject: [PATCH 03/11] Update dockerignore --- .dockerignore | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.dockerignore b/.dockerignore index ccbdbb3..7e184f8 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1 +1,4 @@ -garrysmod-data \ No newline at end of file +Dockerfile +README.md +.dockerignore +docker-compose.yaml From 59bf047ceb56566493c99af0082abc5f1ea259b7 Mon Sep 17 00:00:00 2001 From: Laura Demkowicz-Duffy Date: Mon, 15 Feb 2021 15:25:59 +0000 Subject: [PATCH 04/11] Switch to steamcmd/steamcmd base image --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 4e42225..2e86a27 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ ##################################################################### # Dockerfile that builds a GMOD Gameserver - modified from CS Scrim # ##################################################################### -FROM cm2network/steamcmd:root +FROM steamcmd/steamcmd MAINTAINER Ryan Smith MAINTAINER Laura Demkowicz-Duffy From b09c59506ce8d0da76a63f294ed69b5f285a529d Mon Sep 17 00:00:00 2001 From: Laura Demkowicz-Duffy Date: Mon, 15 Feb 2021 15:37:13 +0000 Subject: [PATCH 05/11] Hardcode gmod directory --- Dockerfile | 12 +++++------- entry.sh | 6 +++--- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/Dockerfile b/Dockerfile index 2e86a27..85c5471 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,26 +12,24 @@ ENV GAMETYPE "sandbox" ENV DEFAULT_MAP "gm_flatgrass" ENV WORKSHOP_COLLECTION "0" ENV RCON_PWD "changeme" -ENV STEAMAPP "garrysmod" ENV SRCDS_TOKEN=0 # Directory layout -ENV STEAMAPPDIR "/${STEAMAPP}" ENV CONFIG_DIR "/config" ENV UPDATE_SCRIPT "${CONFIG_DIR}/${STEAMAPP}_update.txt" ENV MOUNT_CONFIG "${CONFIG_DIR}/mount.cfg" # Create user, directories and required game content RUN useradd -s /bin/false -u ${UID} gmoduser && \ - mkdir -p ${CONFIG_DIR} ${STEAMAPPDIR} /css /tf2 && \ + mkdir -vp ${CONFIG_DIR} /garrysmod /css /tf2 && \ steamcmd +login anonymous \ +force_install_dir /css \ +app_update "232330" validate \ +force_install_dir /tf2 \ +app_update "232250" validate \ +quit && \ - chown -R gmoduser:gmoduser \ - ${CONFIG_DIR} ${STEAMAPPDIR} /css /tf2 + chown -Rv gmoduser:gmoduser \ + ${CONFIG_DIR} /garrysmod /css /tf2 # Copy scripts/config in COPY --chown=gmoduser entry.sh /entry.sh @@ -40,7 +38,7 @@ COPY --chown=gmoduser garrysmod_update.txt ${UPDATE_SCRIPT} # I/O USER gmoduser -VOLUME ${STEAMAPPDIR} -WORKDIR ${STEAMAPPDIR} +VOLUME /garrysmod +WORKDIR /garrysmod EXPOSE 27015/udp ENTRYPOINT ["bash", "/entry.sh"] diff --git a/entry.sh b/entry.sh index f4fd798..7b61f15 100644 --- a/entry.sh +++ b/entry.sh @@ -2,15 +2,15 @@ # Update/install gmod itself bash steamcmd +login anonymous \ - +force_install_dir "${STEAMAPPDIR}" \ + +force_install_dir /garrysmod \ +app_update 4020 validate \ +quit # Mount CSS and TF2 -ln -s "${MOUNT_CONFIG}" "${STEAMAPPDIR}/cfg/mount.cfg" +ln -s "${MOUNT_CONFIG}" /garrysmod/cfg/mount.cfg # Run GMOD, passing commands through -./srcds_run -game "${STEAMAPP}" -console -autoupdate \ +./srcds_run -game garrysmod -console -autoupdate \ -steam_dir "${STEAMCMDDIR}" \ -steamcmd_script "${UPDATE_SCRIPT}" \ -usercon \ From 9301e2708fb51be99be6e9d03e50c973a8172475 Mon Sep 17 00:00:00 2001 From: Laura Demkowicz-Duffy Date: Mon, 15 Feb 2021 15:38:57 +0000 Subject: [PATCH 06/11] Reorder dockerfile steps to avoid chown'ing loads of files Make entrypoint executable Add home directory for gmod user so steamcmd works Remove errant && Fix path in update script --- Dockerfile | 17 ++++++++++------- entry.sh | 0 garrysmod_update.txt | 2 +- 3 files changed, 11 insertions(+), 8 deletions(-) mode change 100644 => 100755 entry.sh diff --git a/Dockerfile b/Dockerfile index 85c5471..6592485 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,18 +18,22 @@ ENV SRCDS_TOKEN=0 ENV CONFIG_DIR "/config" ENV UPDATE_SCRIPT "${CONFIG_DIR}/${STEAMAPP}_update.txt" ENV MOUNT_CONFIG "${CONFIG_DIR}/mount.cfg" +ENV HOME /home/gmoduser -# Create user, directories and required game content -RUN useradd -s /bin/false -u ${UID} gmoduser && \ +# Create user + directories +RUN useradd -m -s /bin/false -u ${UID} gmoduser && \ mkdir -vp ${CONFIG_DIR} /garrysmod /css /tf2 && \ - steamcmd +login anonymous \ + chown -vR gmoduser:gmoduser \ + ${CONFIG_DIR} /garrysmod /css /tf2 + +# Install required game content +USER gmoduser +RUN steamcmd +login anonymous \ +force_install_dir /css \ +app_update "232330" validate \ +force_install_dir /tf2 \ +app_update "232250" validate \ - +quit && \ - chown -Rv gmoduser:gmoduser \ - ${CONFIG_DIR} /garrysmod /css /tf2 + +quit # Copy scripts/config in COPY --chown=gmoduser entry.sh /entry.sh @@ -37,7 +41,6 @@ COPY --chown=gmoduser mount.cfg ${MOUNT_CONFIG} COPY --chown=gmoduser garrysmod_update.txt ${UPDATE_SCRIPT} # I/O -USER gmoduser VOLUME /garrysmod WORKDIR /garrysmod EXPOSE 27015/udp diff --git a/entry.sh b/entry.sh old mode 100644 new mode 100755 diff --git a/garrysmod_update.txt b/garrysmod_update.txt index 35b2ca4..bf78043 100644 --- a/garrysmod_update.txt +++ b/garrysmod_update.txt @@ -1,6 +1,6 @@ @ShutdownOnFailedCommand 1 @NoPromptForPassword 1 login anonymous -force_install_dir /steamapps/garrysmod +force_install_dir /garrysmod app_update 4020 quit From 1949d606c1c41a3347234f068e010d8b37bfd838 Mon Sep 17 00:00:00 2001 From: Laura Demkowicz-Duffy Date: Mon, 15 Feb 2021 15:51:18 +0000 Subject: [PATCH 07/11] Rewrite docker-compose to use a named volume instead of a bind mount and reflect changes to the image Correct docker-compose volume placement --- docker-compose.yaml | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/docker-compose.yaml b/docker-compose.yaml index 58a87b3..b83d3a3 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,13 +1,16 @@ 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 \ No newline at end of file + - GAMETYPE=terrortown + - RCON_PWD=changeme + ports: + - "27015:27015/udp" + volumes: + - garrysmod-data:/garrysmod + +volumes: + garrysmod-data: From aff1cff4f73c24af8dccbc5ce0c39872d2b59b8f Mon Sep 17 00:00:00 2001 From: Laura Demkowicz-Duffy Date: Mon, 15 Feb 2021 16:01:13 +0000 Subject: [PATCH 08/11] Use update script in entrypoint Fix cfg path and steam path Fix ~ expansion since it doesn't seem to work Make sure the home directory created for the user corresponds to what we want --- Dockerfile | 2 +- entry.sh | 9 +++------ 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index 6592485..e672288 100644 --- a/Dockerfile +++ b/Dockerfile @@ -21,7 +21,7 @@ ENV MOUNT_CONFIG "${CONFIG_DIR}/mount.cfg" ENV HOME /home/gmoduser # Create user + directories -RUN useradd -m -s /bin/false -u ${UID} gmoduser && \ +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 diff --git a/entry.sh b/entry.sh index 7b61f15..47dd5ca 100755 --- a/entry.sh +++ b/entry.sh @@ -1,17 +1,14 @@ #!/usr/bin/env bash # Update/install gmod itself -bash steamcmd +login anonymous \ - +force_install_dir /garrysmod \ - +app_update 4020 validate \ - +quit +bash steamcmd +runscript "${UPDATE_SCRIPT}" # Mount CSS and TF2 -ln -s "${MOUNT_CONFIG}" /garrysmod/cfg/mount.cfg +ln -s "${MOUNT_CONFIG}" /garrysmod/garrysmod/cfg/mount.cfg # Run GMOD, passing commands through ./srcds_run -game garrysmod -console -autoupdate \ - -steam_dir "${STEAMCMDDIR}" \ + -steam_dir "${HOME}/.steam" \ -steamcmd_script "${UPDATE_SCRIPT}" \ -usercon \ -port 27015 \ From 5b0075cfbb8929fe4d44078161bd248d4dd4e72f Mon Sep 17 00:00:00 2001 From: Laura Demkowicz-Duffy Date: Mon, 15 Feb 2021 16:31:12 +0000 Subject: [PATCH 09/11] cp instead of ln with mount cfg to ensure it gets across --- entry.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entry.sh b/entry.sh index 47dd5ca..6e22fc4 100755 --- a/entry.sh +++ b/entry.sh @@ -4,7 +4,7 @@ bash steamcmd +runscript "${UPDATE_SCRIPT}" # Mount CSS and TF2 -ln -s "${MOUNT_CONFIG}" /garrysmod/garrysmod/cfg/mount.cfg +cp -v "${MOUNT_CONFIG}" /garrysmod/garrysmod/cfg/mount.cfg # Run GMOD, passing commands through ./srcds_run -game garrysmod -console -autoupdate \ From 64bd4c43bd035d9d0d3cf2bfdbd16608c5133681 Mon Sep 17 00:00:00 2001 From: Laura Demkowicz-Duffy Date: Mon, 15 Feb 2021 16:32:43 +0000 Subject: [PATCH 10/11] Name image in docker compose for ease of debugging --- docker-compose.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/docker-compose.yaml b/docker-compose.yaml index b83d3a3..98cf397 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -7,6 +7,7 @@ services: - SRCDS_TOKEN=0 - GAMETYPE=terrortown - RCON_PWD=changeme + image: fragsoc/gmod ports: - "27015:27015/udp" volumes: From c7c2bc60dfaed6c26b49025c8ba6ff0de9355f88 Mon Sep 17 00:00:00 2001 From: Laura Demkowicz-Duffy Date: Thu, 27 Oct 2022 21:12:07 +0100 Subject: [PATCH 11/11] refactor: split steamcmd commands up --- Dockerfile | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index e672288..cef3fca 100644 --- a/Dockerfile +++ b/Dockerfile @@ -28,10 +28,12 @@ RUN useradd -m -s /bin/false -u ${UID} -d ${HOME} gmoduser && \ # Install required game content USER gmoduser -RUN steamcmd +login anonymous \ - +force_install_dir /css \ +RUN steamcmd +force_install_dir /css \ + +login anonymous \ +app_update "232330" validate \ - +force_install_dir /tf2 \ + +quit +RUN steamcmd +force_install_dir /tf2 \ + +login anonymous \ +app_update "232250" validate \ +quit