Skip to content

Commit

Permalink
Improve for new servers
Browse files Browse the repository at this point in the history
  • Loading branch information
Ethorbit committed Dec 27, 2023
1 parent 2cba042 commit 26b0c08
Show file tree
Hide file tree
Showing 23 changed files with 186 additions and 50 deletions.
23 changes: 16 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,42 @@ FROM cm2network/steamcmd
USER root
ARG PUID=1000
ARG PGID=1000

# Some games will require a login which can only be done interactively thanks to things like 2FA codes.
# If a username is needed, you will need to start the image interactively the first time to login for the install.
ENV STEAMCMD_LOGIN_USERNAME="anonymous"

# Umask for files created by steamcmd during server installs
# It will NOT cover files that are created by server executables!
ENV UMASK=027
ENV HOME_DIR=${HOMEDIR}
ENV STEAMCMD_DIR=${STEAMCMDDIR}
ENV SERVER_DIR="${HOMEDIR}/server"
# IMAGE_DIR are files that are moved into SERVER_DIR at runtime
ENV SERVERS_DIR="${HOMEDIR}/Steam/steamapps/common"
# IMAGE_DIR are files that are moved into SERVERS_DIR at runtime
# The purpose of it is for baking custom start/update scripts into your
# images and having them still appear in the server/ volume.
ENV IMAGE_DIR="/image"
# For referencing inside server scripts in conjunction with IMAGE_DIR / SERVER_DIR.
# For referencing inside server scripts in conjunction with IMAGE_DIR / SERVERS_DIR.
# This just allows us to give them different names in the future.
ENV STEAMCMD_UPDATE_SCRIPT="steam_update.txt"
ENV STEAMCMD_APPEND_SCRIPT="steam_update_append.txt"
ENV UPDATE_SCRIPT="update.sh"
ENV START_SCRIPT="start.sh"
# You need to integrate these in your server images
ENV APP_ID=
ENV SERVER_DIR=
ENV START_ARGS=
COPY /start.sh /start.sh
RUN usermod -u ${PUID} ${USER} &&\
groupmod -g ${PGID} ${USER} &&\
chown ${USER}:${USER} /start.sh &&\
chmod +x /start.sh &&\
mkdir "${IMAGE_DIR}" &&\
mkdir "${SERVER_DIR}" &&\
chown ${USER}:${USER} "${IMAGE_DIR}" &&\
chown ${USER}:${USER} "${SERVER_DIR}"
WORKDIR "${SERVER_DIR}"
mkdir -p "${SERVERS_DIR}" &&\
chown -R ${USER}:${USER} "${HOME_DIR}/" &&\
chown ${USER}:${USER} "${IMAGE_DIR}"
WORKDIR "${SERVERS_DIR}"
VOLUME "${SERVERS_DIR}"
VOLUME /server
USER ${USER}
CMD ["/start.sh"]
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ git_hash := $(shell git rev-parse --short HEAD)

build:
docker build -t steamcmd-server ./
find $(files) -maxdepth 1 -type d -exec \
find $(files) -maxdepth 0 -type d -exec \
/bin/sh -c 'dirname=$$(basename {}) &&\
docker build -t $$dirname -t $(docker_user)/$$dirname:latest -t $(docker_user)/$$dirname:$(git_hash) {} &&\
docker volume rm -f $$dirname' \;

test:
docker run -it --rm -p 27015/udp $(options) -v $(image):/home/steam/server --name $(image) $(image) $(command)
docker run -it --rm -p 27015/udp -p 27015/tcp $(options) -v $(image):/server --name $(image) $(image) $(command)

push:
find $(files) -maxdepth 1 -type d -exec \
Expand Down
24 changes: 15 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ See the [existing implementations](servers)
## Creating container from [existing server image](servers)
`make build`

`docker run -it --rm -e START_ARGS="" -p 27015:27015/udp -v myserver:/home/steam/server <server image>`
`docker run -it --rm -e START_ARGS="" -p 27015:27015/tcp -p 27015:27015/udp -v myserver:/home/steam/Steam/steamapps/common <server image>`

Add `-e STEAMCMD_LOGIN_USERNAME=username-here` and interactively login on first run if you get a susbcription or owner error.

You can also look for pre-built images [here](https://hub.docker.com/u/ethorbit).

Expand All @@ -19,18 +21,22 @@ You can also look for pre-built images [here](https://hub.docker.com/u/ethorbit)
* Create a new game directory inside servers/ (this doubles as the image name)
* Build everything: `make build`
* Test it: `image=<name here> make test`
* If a login error is received during testing, test using a Steam account that owns the content: `image=<name here> options='-e STEAMCMD_LOGIN_USERNAME=yoursteamname' make test`
* Upload changes by changing the Makefile's docker\_user to match your DockerHub username and running: `make push`
* [Create a pull request](https://github.com/Ethorbit/steamcmd-server-docker/pulls) to add the image to this repo.

### Environment variables
These variables should be used whereever possible.
* `USER`
* `HOME_DIR`
* `STEAMCMD_DIR` - where steamcmd binaries are
* `SERVER_DIR` - where the server installs
* `IMAGE_DIR` - where files baked into the server image are (like a start or update script), they are copied to SERVER\_DIR on container start
* `STEAMCMD_UPDATE_SCRIPT` - txt update file using steamcmd update syntax
* `UPDATE_SCRIPT` - shell script that executes STEAMCMD\_UPDATE\_SCRIPT
* `START_SCRIPT` - shell script to start the game server
* `START_ARGS` - arguments of the server executable which would be read in START\_SCRIPT
* `APP_ID` - game server's appid
* `STEAMCMD_DIR` - where steamcmd binaries are
* `SERVERS_DIR` - where the server(s) that are installed go
* `SERVER_DIR` - the server that is going to run
* `IMAGE_DIR` - where files baked into the server image are (like a start or update script), they are copied to SERVER\_DIR on container start
* `STEAMCMD_LOGIN_USERNAME` - the steam username of the account that owns the game
* `STEAMCMD_UPDATE_SCRIPT` - txt update file using steamcmd update syntax
* `STEAMCMD_APPEND_SCRIPT` - txt update file that is appended to the default txt file (instructions are run after login)
* `UPDATE_SCRIPT` - shell script that executes STEAMCMD\_UPDATE\_SCRIPT
* `START_SCRIPT` - shell script to start the game server
* `START_ARGS` - arguments of the server executable which would be read in START\_SCRIPT
* `APP_ID` - game server's appid
2 changes: 1 addition & 1 deletion servers/gmod-server/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
FROM steamcmd-server
USER root
ENV APP_ID=4020
ENV SERVER_DIR="${SERVERS_DIR}/GarrysModDS"
COPY ./start.sh "${IMAGE_DIR}/${START_SCRIPT}"
RUN chown ${USER}:${USER} "${IMAGE_DIR}/${START_SCRIPT}" &&\
chmod +x "${IMAGE_DIR}/${START_SCRIPT}" &&\
Expand All @@ -11,5 +12,4 @@ RUN chown ${USER}:${USER} "${IMAGE_DIR}/${START_SCRIPT}" &&\
libncurses5:i386 &&\
apt-get remove --purge --auto-remove -y &&\
rm -rf /var/lib/apt/lists/*
VOLUME "${SERVER_DIR}"
USER ${USER}
4 changes: 2 additions & 2 deletions servers/gmod-server/start.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash
"${SERVER_DIR}/srcds_run" -autoupdate -steam_dir "${STEAMCMD_DIR}" -steamcmd_script "${SERVER_DIR}/${STEAMCMD_UPDATE_SCRIPT}" "${START_ARGS}"
#!/bin/bash
"${SERVER_DIR}/srcds_run" -autoupdate -steam_dir "${STEAMCMD_DIR}" -steamcmd_script "${SERVERS_DIR}/${STEAMCMD_UPDATE_SCRIPT}" "${START_ARGS}"

9 changes: 3 additions & 6 deletions servers/hldm-server/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
FROM steamcmd-server
USER root
ENV APP_ID=90
ENV SERVER_DIR="${SERVERS_DIR}/Half-Life"
COPY ./start.sh "${IMAGE_DIR}/${START_SCRIPT}"
COPY ./steam_update_append.txt "${IMAGE_DIR}/${STEAMCMD_APPEND_SCRIPT}"
RUN chown ${USER}:${USER} "${IMAGE_DIR}/${START_SCRIPT}" &&\
chmod +x "${IMAGE_DIR}/${START_SCRIPT}" &&\
echo "Like with all Valve products, HLDS is broken! (It will not download all the files.)" &&\
echo "We will now override the default install script with one that does literally the same thing, except multiple times, to ensure that ALL files are (hopefully) downloaded!" &&\
printf '@NoPromptForPassword 1\nforce_install_dir "%s"\nlogin anonymous\napp_update %i\napp_update %i validate\napp_update %i validate\nquit' \
"$SERVER_DIR" "$APP_ID" "$APP_ID" "$APP_ID" >> "$IMAGE_DIR/$STEAMCMD_UPDATE_SCRIPT"
VOLUME "${SERVER_DIR}"
chmod +x "${IMAGE_DIR}/${START_SCRIPT}"
USER ${USER}
2 changes: 1 addition & 1 deletion servers/hldm-server/start.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/bash
"${SERVER_DIR}/hlds_run" -autoupdate -steam_dir "${STEAMCMD_DIR}" -steamcmd_script "${SERVER_DIR}/${STEAMCMD_UPDATE_SCRIPT}" "${START_ARGS}"
"${SERVER_DIR}/hlds_run" -autoupdate -steam_dir "${STEAMCMD_DIR}" -steamcmd_script "${SERVERS_DIR}/${STEAMCMD_UPDATE_SCRIPT}" +map crossfire "${START_ARGS}"
7 changes: 7 additions & 0 deletions servers/hldm-server/steam_update_append.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
app_update 90
app_update 90
app_update 90
app_update validate 90
app_update validate 90
app_update validate 90
quit
22 changes: 22 additions & 0 deletions servers/svencoop-server-with-dlc/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM steamcmd-server
USER root
ENV APP_ID=276060
ENV SERVER_DIR="${SERVERS_DIR}/Sven Co-op Dedicated Server"
ENV PAID_SCRIPT="paid.sh"
COPY ./paid.sh "${IMAGE_DIR}/${PAID_SCRIPT}"
COPY ./start.sh "${IMAGE_DIR}/${START_SCRIPT}"
COPY ./steam_update_append.txt "${IMAGE_DIR}/${STEAMCMD_APPEND_SCRIPT}"
RUN chown ${USER}:${USER} "${IMAGE_DIR}/${START_SCRIPT}" &&\
chmod +x "${IMAGE_DIR}/${START_SCRIPT}" &&\
chmod +x "${IMAGE_DIR}/${PAID_SCRIPT}" &&\
export DEBIAN_FRONTEND=noninteractive &&\
dpkg --add-architecture i386 &&\
apt update &&\
apt-get install -y --no-install-recommends --no-install-suggests \
wget \
libssl-dev libssl-dev:i386 \
zlib1g:i386 \
unzip &&\
apt-get remove --purge --auto-remove -y &&\
rm -rf /var/lib/apt/lists/*
USER ${USER}
23 changes: 23 additions & 0 deletions servers/svencoop-server-with-dlc/paid.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

if [ ! -f "${SERVERS_DIR}/.server_installed_dlc_successfully.txt" ]; then
echo "Installing DLC..."
cd "${SERVER_DIR}/svencoop"

install_opposing_force()
{
echo "Installing Opposing Force.."
./Install_OpFor_Support.sh
}

install_blueshift()
{
echo "Installing Blue Shift.."
./Install_bshift_Support.sh
}

install_opposing_force
install_blueshift
touch "${SERVERS_DIR}/.server_installed_dlc_successfully.txt"
cd "${SERVER_DIR}"
fi
3 changes: 3 additions & 0 deletions servers/svencoop-server-with-dlc/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
"${SERVERS_DIR}/${PAID_SCRIPT}"
"${SERVER_DIR}/svends_run" -autoupdate -steam_dir "${STEAMCMD_DIR}" -steamcmd_script "${SERVERS_DIR}/${STEAMCMD_UPDATE_SCRIPT}" "${START_ARGS}"
7 changes: 7 additions & 0 deletions servers/svencoop-server-with-dlc/steam_update_append.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
app_update 276060
app_update 50
app_update 130
app_update validate 276060
app_update validate 50
app_update validate 130
quit
2 changes: 1 addition & 1 deletion servers/svencoop-server/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
FROM steamcmd-server
USER root
ENV APP_ID=276060
ENV SERVER_DIR="${SERVERS_DIR}/Sven Co-op Dedicated Server"
COPY ./start.sh "${IMAGE_DIR}/${START_SCRIPT}"
RUN chown ${USER}:${USER} "${IMAGE_DIR}/${START_SCRIPT}" &&\
chmod +x "${IMAGE_DIR}/${START_SCRIPT}" &&\
Expand All @@ -13,5 +14,4 @@ RUN chown ${USER}:${USER} "${IMAGE_DIR}/${START_SCRIPT}" &&\
zlib1g:i386 &&\
apt-get remove --purge --auto-remove -y &&\
rm -rf /var/lib/apt/lists/*
VOLUME "${SERVER_DIR}"
USER ${USER}
3 changes: 1 addition & 2 deletions servers/svencoop-server/start.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
#!/bin/bash
"${SERVER_DIR}/svends_run" -autoupdate -steam_dir "${STEAMCMD_DIR}" -steamcmd_script "${SERVER_DIR}/${STEAMCMD_UPDATE_SCRIPT}" "${START_ARGS}"

"${SERVER_DIR}/svends_run" -autoupdate -steam_dir "${STEAMCMD_DIR}" -steamcmd_script "${SERVERS_DIR}/${STEAMCMD_UPDATE_SCRIPT}" "${START_ARGS}"
16 changes: 16 additions & 0 deletions servers/synergy-server-with-dlc/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM steamcmd-server
USER root
ENV APP_ID=17520
ENV SERVER_DIR="${SERVERS_DIR}/synergy"
COPY ./synergy "${IMAGE_DIR}/synergy"
COPY ./start.sh "${IMAGE_DIR}/${START_SCRIPT}"
COPY ./steam_update_append.txt "${IMAGE_DIR}/${STEAMCMD_APPEND_SCRIPT}"
RUN chown ${USER}:${USER} "${IMAGE_DIR}/${START_SCRIPT}" &&\
chmod +x "${IMAGE_DIR}/${START_SCRIPT}" &&\
dpkg --add-architecture i386 &&\
apt update &&\
apt-get install -y --no-install-suggests --no-install-recommends \
libtinfo5:i386 &&\
apt-get remove --purge --auto-remove -y &&\
rm -rf /var/lib/apt/lists/*
USER ${USER}
2 changes: 2 additions & 0 deletions servers/synergy-server-with-dlc/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
"${SERVER_DIR}/srcds_run" -game synergy -autoupdate -steam_dir "${STEAMCMD_DIR}" -steamcmd_script "${SERVERS_DIR}/${STEAMCMD_UPDATE_SCRIPT}" +map d1_trainstation_01 "${START_ARGS}"
11 changes: 11 additions & 0 deletions servers/synergy-server-with-dlc/steam_update_append.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
app_update 17520
app_update 220
app_update 380
app_update 420
app_update 340
app_update 17520 validate
app_update 220 validate
app_update 380 validate
app_update 420 validate
app_update 340 validate
quit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sv_content_optional "hl2 ep1 ep2 lost"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hl2 ep1 ep2 lost
15 changes: 15 additions & 0 deletions servers/synergy-server/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM steamcmd-server
USER root
ENV APP_ID=17520
ENV SERVER_DIR="${SERVERS_DIR}/Synergy"
COPY ./start.sh "${IMAGE_DIR}/${START_SCRIPT}"
COPY ./steam_update_append.txt "${IMAGE_DIR}/${STEAMCMD_APPEND_SCRIPT}"
RUN chown ${USER}:${USER} "${IMAGE_DIR}/${START_SCRIPT}" &&\
chmod +x "${IMAGE_DIR}/${START_SCRIPT}" &&\
dpkg --add-architecture i386 &&\
apt update &&\
apt-get install -y --no-install-suggests --no-install-recommends \
libtinfo5:i386 &&\
apt-get remove --purge --auto-remove -y &&\
rm -rf /var/lib/apt/lists/*
USER ${USER}
2 changes: 2 additions & 0 deletions servers/synergy-server/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
"${SERVER_DIR}/srcds_run" -game synergy -autoupdate -steam_dir "${STEAMCMD_DIR}" -steamcmd_script "${SERVERS_DIR}/${STEAMCMD_UPDATE_SCRIPT}" +map d1_trainstation_01 "${START_ARGS}"
5 changes: 5 additions & 0 deletions servers/synergy-server/steam_update_append.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
app_update 17520
app_update 220
app_update 17520 validate
app_update 220 validate
quit
48 changes: 29 additions & 19 deletions start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,50 +3,60 @@ umask "$UMASK"

# Copy all files/dirs baked inside the server image into the server volume
# If the file/dir already exists, it won't make its way to the volume.
find "$IMAGE_DIR/" -mindepth 1 -maxdepth 1 -exec /bin/bash -c "cp -nar {} '$SERVER_DIR/'" \;
find "$IMAGE_DIR/" -mindepth 1 -maxdepth 1 -exec /bin/bash -c "cp -nar {} '$SERVERS_DIR/'" \;

# Create defaults for scripts that are not baked into the server image
if [[ ! -f "$SERVER_DIR/$STEAMCMD_UPDATE_SCRIPT" ]]; then
if [[ -z "$APP_ID" ]]; then
if [ ! -f "$SERVERS_DIR/$STEAMCMD_UPDATE_SCRIPT" ]; then
if [ -z "$APP_ID" ]; then
echo "Can't install! No App ID specified!"
exit
fi

printf '@NoPromptForPassword 1\nforce_install_dir "%s"\nlogin anonymous\napp_update %i validate\nquit' \
"$SERVER_DIR" "$APP_ID" >> "$SERVER_DIR/$STEAMCMD_UPDATE_SCRIPT"
chmod +x "$SERVER_DIR/$STEAMCMD_UPDATE_SCRIPT"
if [ -z "$STEAMCMD_LOGIN_USERNAME" ] || [ "$STEAMCMD_LOGIN_USERNAME" = "anonymous" ]; then
printf '@NoPromptForPassword\nlogin anonymous\n' >> "$SERVERS_DIR/$STEAMCMD_UPDATE_SCRIPT"
else
printf 'login %s\n' "$STEAMCMD_LOGIN_USERNAME" >> "$SERVERS_DIR/$STEAMCMD_UPDATE_SCRIPT"
fi

if [ ! -f "$STEAMCMD_APPEND_SCRIPT" ]; then
printf 'app_update %i\napp_update %i validate\nquit' "$APP_ID" "$APP_ID" >> "$SERVERS_DIR/$STEAMCMD_UPDATE_SCRIPT"
else
cat "$STEAMCMD_APPEND_SCRIPT" >> "$SERVERS_DIR/$STEAMCMD_UPDATE_SCRIPT"
rm "$STEAMCMD_APPEND_SCRIPT" # Not needed anymore, users will edit steam_update.txt if they wanna make changes
fi

chmod +x "$SERVERS_DIR/$STEAMCMD_UPDATE_SCRIPT"
fi

if [[ ! -f "$SERVER_DIR/$UPDATE_SCRIPT" ]]; then
if [ ! -f "$SERVERS_DIR/$UPDATE_SCRIPT" ]; then
printf '#!/bin/bash\n"%s" +runscript "%s"' \
"$STEAMCMD_DIR/steamcmd.sh" "$SERVER_DIR/$STEAMCMD_UPDATE_SCRIPT" >> "$SERVER_DIR/$UPDATE_SCRIPT"
chmod +x "$SERVER_DIR/$UPDATE_SCRIPT"
"$STEAMCMD_DIR/steamcmd.sh" "$SERVERS_DIR/$STEAMCMD_UPDATE_SCRIPT" >> "$SERVERS_DIR/$UPDATE_SCRIPT"
chmod +x "$SERVERS_DIR/$UPDATE_SCRIPT"
fi

if [[ ! -f "$SERVER_DIR/$START_SCRIPT" ]]; then
printf '#!/bin/bash\n# Your server start command here' >> "$SERVER_DIR/$START_SCRIPT"
chmod +x "$SERVER_DIR/$START_SCRIPT"
if [ ! -f "$SERVERS_DIR/$START_SCRIPT" ]; then
printf '#!/bin/bash\n# Your server start command here' >> "$SERVERS_DIR/$START_SCRIPT"
chmod +x "$SERVERS_DIR/$START_SCRIPT"
fi

function start_server {
cd "$SERVER_DIR/"
echo "Starting server..."
"$SERVER_DIR/$START_SCRIPT"
"$SERVERS_DIR/$START_SCRIPT"
}

function install_server {
echo "Installing server..."
"$SERVER_DIR/$UPDATE_SCRIPT"
"$SERVERS_DIR/$UPDATE_SCRIPT"
}

cd "$SERVER_DIR/"

# There's probably a MUCH better way to check if a server installed successfully.
# Feel free to improve this.
if [[ ! -f "${SERVER_DIR}/.server_installed_successfully" ]]; then
if [ ! -f "${SERVERS_DIR}/.server_installed_successfully" ]; then
install_server

if [[ $? -eq 0 ]]; then
touch "${SERVER_DIR}/.server_installed_successfully"
if [ $? -eq 0 ]; then
touch "${SERVERS_DIR}/.server_installed_successfully"
else
echo "Server failed to install ($?)"
exit $?
Expand Down

0 comments on commit 26b0c08

Please sign in to comment.