mirror of
https://github.com/AsgardEternal/SquadDocker.git
synced 2024-09-28 09:24:22 -05:00
feat: fully working container
This commit is contained in:
parent
76d2bbdd75
commit
3995b3c64c
92
Dockerfile
92
Dockerfile
@ -2,13 +2,14 @@
|
||||
FROM asgard.orion-technologies.io/steamcmd:1.0 AS build
|
||||
LABEL maintainer="price@orion-technologies.io"
|
||||
|
||||
ARG steam_app_id=403240
|
||||
ARG steam_beta_app_id=774961
|
||||
ARG workshop_id=393380
|
||||
ARG steam_beta_password=""
|
||||
ARG steam_beta_branch=""
|
||||
ARG use_squad_beta=0
|
||||
ARG squad_mods="()"
|
||||
ENV STEAM_APP_ID=403240
|
||||
ENV STEAM_BETA_APP_ID=774961
|
||||
ENV WORKSHOP_ID=393380
|
||||
ENV STEAM_BETA_PASSWORD=""
|
||||
ENV STEAM_BETA_BRANCH=""
|
||||
ENV USE_SQUAD_BETA=0
|
||||
ENV MODS=""
|
||||
ENV UPDATE_SQUAD=0
|
||||
|
||||
ENV RCON_PASSWORD=""
|
||||
ENV SQUAD_SERVER_DIR="${USER_HOME}/Squad-Server"
|
||||
@ -20,77 +21,16 @@ ENV GAMEPORT=7787 \
|
||||
FIXEDMAXTICKRATE=40 \
|
||||
RANDOM=NONE
|
||||
|
||||
COPY --chown=${USER} ./scripts/entry.sh "${USER_HOME}/entry.sh"
|
||||
|
||||
SHELL [ "/bin/bash", "-c" ]
|
||||
|
||||
RUN <<__EOR__
|
||||
|
||||
chmod 0744 "${USER_HOME}/entry.sh"
|
||||
|
||||
if (( use_squad_beta == 1 )); then
|
||||
# Install Squad from the Beta branch
|
||||
"${STEAM_CMD_INSTALL_DIR}/steamcmd.sh" \
|
||||
+force_install_dir "${SQUAD_SERVER_DIR}" \
|
||||
+login anonymous \
|
||||
+app_update ${steam_app_id} validate \
|
||||
-beta "${steam_beta_branch}" \
|
||||
-betapassword "${steam_beta_password}" \
|
||||
+quit
|
||||
else
|
||||
# Install Squad from the release version
|
||||
"${STEAM_CMD_INSTALL_DIR}/steamcmd.sh" \
|
||||
+force_install_dir "${SQUAD_SERVER_DIR}" \
|
||||
+login anonymous \
|
||||
+app_update ${steam_app_id} validate \
|
||||
+quit
|
||||
fi
|
||||
|
||||
# Install mods as part of image
|
||||
|
||||
printf "Provided mods list: %s\n" "${squad_mods}"
|
||||
IFS="," read -ra squad_mods <<< "${squad_mods}"
|
||||
for mod in "${squad_mods[@]}"; do
|
||||
printf "\n\n######\nAdding mod: %s\n######\n\n" "${mod}"
|
||||
"${STEAM_CMD_INSTALL_DIR}/steamcmd.sh" \
|
||||
+force_install_dir "${SQUAD_SERVER_DIR}/steamapps/workshop/content/${workshop_id}/${mod}" \
|
||||
+login anonymous \
|
||||
+workshop_download_item "${workshop_id}" "${mod}" \
|
||||
+quit
|
||||
|
||||
# Link the mod instead of moving it into place, this allows steamcmd to update the mod in place if for whatever
|
||||
# reason that becomes necessary. In reality nightly builds/builds via CI should update these mods. More of a nicety
|
||||
# than something necessary.
|
||||
|
||||
for dir in \
|
||||
"${SQUAD_SERVER_DIR}/steamapps/workshop/content/${workshop_id}/${mod}/steamapps/workshop/"{content,downloads}"/${workshop_id}/${mod}"/*
|
||||
do
|
||||
if [[ "${dir}" != *'*'* ]]; then
|
||||
ln -s "${dir}" "${SQUAD_SERVER_DIR}/SquadGame/Plugins/Mods/"
|
||||
fi
|
||||
done
|
||||
# Remove star glob link
|
||||
rm "${SQUAD_SERVER_DIR}/SquadGame/Plugins/Mods/\*"
|
||||
done
|
||||
|
||||
mkdir -p /ServerConfig
|
||||
mv "${SQUAD_SERVER_DIR}/SquadGame/ServerConfig" /ServerConfig
|
||||
ln -s /ServerConfig "${SQUAD_SERVER_DIR}/SquadGame/ServerConfig"
|
||||
chown -R "${USER}:${USER}" /ServerConfig
|
||||
chmod -R 0744 /ServerConfig
|
||||
|
||||
|
||||
__EOR__
|
||||
|
||||
|
||||
COPY --chown=${USER} ./scripts/entry.bash "${USER_HOME}/entry.bash"
|
||||
|
||||
FROM build AS prod
|
||||
SHELL [ "/bin/bash" ]
|
||||
WORKDIR "${USER_HOME}"
|
||||
|
||||
EXPOSE ${GAMEPORT}/udp \
|
||||
${QUERYPORT}/tcp \
|
||||
${QUERYPORT}/udp \
|
||||
${RCONPORT}/tcp \
|
||||
${RCONPORT}/udp
|
||||
EXPOSE 7787/udp \
|
||||
27165/tcp \
|
||||
27165/udp \
|
||||
21114/tcp \
|
||||
21114/udp
|
||||
|
||||
ENTRYPOINT [ "/bin/bash", "entry.sh" ]
|
||||
ENTRYPOINT [ "/bin/bash", "entry.bash" ]
|
||||
|
77
scripts/entry.bash
Executable file
77
scripts/entry.bash
Executable file
@ -0,0 +1,77 @@
|
||||
#!/bin/bash
|
||||
|
||||
# If we want to persist the containter and we don't want to update then we can save a whole lot of time if we mount this
|
||||
# on a volume
|
||||
|
||||
main() {
|
||||
chown -R "${USER}:${USER}" "${USER_HOME}" || exit 1
|
||||
|
||||
if [[ -d "${USER_HOME}/ServerConfig" ]]; then
|
||||
chown -R "${USER}:${USER}" "${USER_HOME}/ServerConfig"
|
||||
fi
|
||||
|
||||
local steam_cmd_base_str="${STEAM_CMD_INSTALL_DIR}/steamcmd.sh +force_install_dir ${SQUAD_SERVER_DIR} +login anonymous"
|
||||
local steam_cmd_str="${steam_cmd_base_str} +app_update ${STEAM_APP_ID}"
|
||||
if (( USE_SQUAD_BETA == 1 )); then
|
||||
steam_cmd_str="${steam_cmd_str} -beta ${STEAM_BETA_BRANCH} -betapassword ${STEAM_BETA_PASSWORD}"
|
||||
fi
|
||||
steam_cmd_str="${steam_cmd_str} validate +quit"
|
||||
printf "\e[35m> Issuing SteamCMD Command:\e[0m %s\n" "${steam_cmd_str}"
|
||||
eval "${steam_cmd_str}"
|
||||
|
||||
|
||||
# Remove existing non-default symlinks in mod dir
|
||||
for mod in "${SQUAD_SERVER_DIR}/SquadGame/Plugins/Mods"/[0-9]*; do
|
||||
rm "${mod}"
|
||||
done
|
||||
|
||||
printf "\e[96m> Provided mods list:\e[0m %s\n" "${MODS}"
|
||||
# shellcheck disable=2153
|
||||
IFS="," read -ra squad_mods <<< "${MODS}"
|
||||
for mod in "${squad_mods[@]}"; do
|
||||
steam_cmd_str="${steam_cmd_base_str}"
|
||||
steam_cmd_str="${steam_cmd_str} +workshop_download_item ${WORKSHOP_ID} ${mod} validate +quit"
|
||||
printf "\e[92m> Adding mod:\e[0m %s\n" "${mod}"
|
||||
printf "\e[35m> Issuing SteamCMD Command:\e[0m %s\n" "${steam_cmd_str}"
|
||||
local counter=0
|
||||
until eval "${steam_cmd_str}"; do
|
||||
printf "\nDid Not Fully Download %s, making another attempt.\n" "${mod}"
|
||||
(( counter++ ))
|
||||
if (( counter > 5 )); then
|
||||
printf "Critical failure, could not download the mod: %s\n" "${mod}"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
ln -s "${SQUAD_SERVER_DIR}/steamapps/workshop/content/${WORKSHOP_ID}/${mod}" "${SQUAD_SERVER_DIR}/SquadGame/Plugins/Mods/${mod}"
|
||||
done
|
||||
|
||||
local mounted_files
|
||||
mounted_files="$(shopt -s nullglob dotglob; echo "${USER_HOME}/ServerConfig/")"
|
||||
if (( ${#mounted_files} )); then
|
||||
rsync -r "${USER_HOME}/ServerConfig/" "${SQUAD_SERVER_DIR}/SquadGame/ServerConfig/"
|
||||
fi
|
||||
|
||||
|
||||
# Update RCON configuration based on the fed in environment value
|
||||
while read -r line; do
|
||||
if [[ "${line}" == Password=* ]]; then
|
||||
# Overwrites the password
|
||||
echo "${line//Password=*/Password="${RCON_PASSWORD}"}"
|
||||
elif [[ "${line}" == Port=* ]]; then
|
||||
# Overwrites the rcon port
|
||||
echo "${line//Port=*/Port="${RCONPORT}"}"
|
||||
else
|
||||
echo "${line}"
|
||||
fi
|
||||
done < "${SQUAD_SERVER_DIR}/SquadGame/ServerConfig/Rcon.cfg" > "rcon.temp" && mv "rcon.temp" "${SQUAD_SERVER_DIR}/SquadGame/ServerConfig/Rcon.cfg"
|
||||
|
||||
|
||||
chown -R "${USER}:${USER}" "${USER_HOME}"
|
||||
su "${USER}" - "${SQUAD_SERVER_DIR}/SquadGameServer.sh" \
|
||||
Port="${GAMEPORT}" \
|
||||
QueryPort="${QUERYPORT}" \
|
||||
FIXEDMAXTICKRATE="${FIXEDMAXTICKRATE}" \
|
||||
FIXEDMAXPLAYERS="${FIXEDMAXPLAYERS}"
|
||||
}
|
||||
|
||||
main
|
@ -1,23 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
while read -r line; do
|
||||
if [[ "${line}" == Password=* ]]; then
|
||||
# Overwrites the password
|
||||
echo "${line//Password=*/Password="${RCON_PASSWORD}"}"
|
||||
elif [[ "${line}" == Port=* ]]; then
|
||||
# Overwrites the rcon port
|
||||
echo "${line//Port=*/Port="${RCONPORT}"}"
|
||||
else
|
||||
echo "${line}"
|
||||
fi
|
||||
done < "${SQUAD_SERVER_DIR}/SquadGame/ServerConfig/Rcon.cfg" > "rcon.temp" && mv "rcon.temp" "${SQUAD_SERVER_DIR}/SquadGame/ServerConfig/Rcon.cfg"
|
||||
|
||||
chown -R "${USER}:${USER}" /ServerConfig
|
||||
chmod -R 0744 /ServerConfig
|
||||
|
||||
|
||||
su - "${USER}" -- "${SQUAD_SERVER_DIR}/SquadGameServer.sh" \
|
||||
Port="${GAMEPORT}" \
|
||||
QueryPort="${QUERYPORT}" \
|
||||
FIXEDMAXTICKRATE="${FIXEDMAXTICKRATE}" \
|
||||
FIXEDMAXPLAYERS="${FIXEDMAXPLAYERS}"
|
Loading…
Reference in New Issue
Block a user