Skip to content

Commit 4fde4c4

Browse files
authored
feat: merge valheim images (#96)
1 parent d04d4ad commit 4fde4c4

7 files changed

Lines changed: 93 additions & 72 deletions

File tree

.github/workflows/games-valheim.yml

Lines changed: 0 additions & 18 deletions
This file was deleted.

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@
8181
- [`games-wine-latest`](https://github.com/sparkedhost/images/blob/main/games/wine-latest/Dockerfile)
8282
- [`games-wine-staging`](https://github.com/sparkedhost/images/blob/main/games/wine-staging/Dockerfile)
8383
- [`games-proton`](https://github.com/sparkedhost/images/blob/main/games/proton/Dockerfile)
84-
- [`games-valheim`](https://github.com/sparkedhost/images/blob/main/games/valheim/Dockerfile)
8584
- [`games-beammp`](https://github.com/sparkedhost/images/blob/main/games/beammp/Dockerfile)
8685
- [`games-cs2`](https://github.com/sparkedhost/images/blob/main/games/cs2/Dockerfile)
8786
- [`games-core-keeper`](https://github.com/sparkedhost/images/blob/main/games/core-keeper/Dockerfile)

games/source/Dockerfile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,18 @@ ENV DEBIAN_FRONTEND noninteractive
1313
RUN dpkg --add-architecture i386 \
1414
&& apt update \
1515
&& apt upgrade -y \
16-
&& apt install -y tar curl gcc g++ lib32gcc-s1 libgcc-s1 libcurl4-gnutls-dev:i386 libssl3:i386 libcurl4:i386 lib32tinfo6 libtinfo6:i386 lib32z1 lib32stdc++6 libncurses6:i386 libcurl3-gnutls:i386 libsdl2-2.0-0:i386 gdb libsdl1.2debian libfontconfig1 telnet net-tools netcat-traditional ca-certificates gcc-multilib file \
16+
&& apt install -y tar curl gcc g++ lib32gcc-s1 libgcc-s1 libcurl4-gnutls-dev:i386 libssl3:i386 libcurl4:i386 lib32tinfo6 libtinfo6:i386 lib32z1 lib32stdc++6 libncurses6:i386 libcurl3-gnutls:i386 libsdl2-2.0-0:i386 gdb libsdl1.2debian libfontconfig1 telnet net-tools netcat-traditional ca-certificates gcc-multilib file jq unzip gettext libnss-wrapper \
1717
&& useradd -d /home/container -m container \
1818
&& cd /tmp/ \
1919
&& curl -sSL https://github.com/gorcon/rcon-cli/releases/download/v0.10.3/rcon-0.10.3-amd64_linux.tar.gz > rcon.tar.gz \
2020
&& tar xvf rcon.tar.gz \
2121
&& mv rcon-0.10.3-amd64_linux/rcon /usr/local/bin/
2222

23+
ENV NSS_WRAPPER_PASSWD=/tmp/passwd NSS_WRAPPER_GROUP=/tmp/group
24+
RUN touch ${NSS_WRAPPER_PASSWD} ${NSS_WRAPPER_GROUP} \
25+
&& chgrp 0 ${NSS_WRAPPER_PASSWD} ${NSS_WRAPPER_GROUP} \
26+
&& chmod g+rw ${NSS_WRAPPER_PASSWD} ${NSS_WRAPPER_GROUP}
27+
2328
USER container
2429
ENV USER container
2530
ENV HOME /home/container
@@ -28,5 +33,6 @@ WORKDIR /home/container
2833

2934
COPY ./source/entrypoint.sh /entrypoint.sh
3035
COPY ./spark-utils/spark-utils.sh /spark-utils.sh
36+
COPY ./source/passwd.template /passwd.template
3137

3238
CMD ["/bin/bash", "/entrypoint.sh"]

games/spark-utils/spark-utils.sh

Lines changed: 86 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ setup_nss_wrapper(){
88
# Setup NSS Wrapper for use ($NSS_WRAPPER_PASSWD and $NSS_WRAPPER_GROUP have been set by the Dockerfile)
99
export USER_ID=$(id -u)
1010
export GROUP_ID=$(id -g)
11+
export USER_NAME="${USER_NAME:-${USER:-container}}"
1112
envsubst < /passwd.template > ${NSS_WRAPPER_PASSWD}
13+
printf '%s:x:%s:\n' "${USER_NAME}" "${GROUP_ID}" > ${NSS_WRAPPER_GROUP}
1214
export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libnss_wrapper.so
1315
}
1416

@@ -50,6 +52,11 @@ install_bepinex() {
5052
local version_file=".apollo/bepinex_version"
5153
local api_response download_url version_number installed_version
5254

55+
if [[ "${SRCDS_APPID}" == "896660" && "${INSTALL_VALHEIM_PLUS:-0}" == "1" ]]; then
56+
echo "Skipping BepInEx installation; ValheimPlus provides its compatible BepInEx version."
57+
return 0
58+
fi
59+
5360
case "${SRCDS_APPID}" in
5461
896660)
5562
# Valheim
@@ -90,8 +97,13 @@ install_bepinex() {
9097
return 0
9198
fi
9299

93-
wget -O "${zip_name}" "$download_url"
94-
unzip -o "${zip_name}"
100+
if ! curl -fL --retry 3 --retry-delay 2 -o "${zip_name}" "${download_url}" \
101+
|| ! unzip -o "${zip_name}" \
102+
|| [[ ! -f "/home/container/${extracted_dir}/BepInEx/core/BepInEx.Preloader.dll" ]]; then
103+
echo "Error: could not install BepInEx"
104+
rm -f "${zip_name}"
105+
return 1
106+
fi
95107
cp -al "/home/container/${extracted_dir}/"* /home/container
96108

97109

@@ -117,6 +129,54 @@ install_bepinex() {
117129
echo "-------------------------------------------------------"
118130
}
119131

132+
install_valheim_plus() {
133+
local release_url api_response download_url version_number installed_version archive_file extract_dir
134+
local version_file=".apollo/valheim_plus_version"
135+
136+
if [[ "${VALHEIM_PLUS_VERSION:-latest}" == "latest" ]]; then
137+
release_url="https://api.github.com/repos/Grantapher/ValheimPlus/releases/latest"
138+
else
139+
release_url="https://api.github.com/repos/Grantapher/ValheimPlus/releases/tags/${VALHEIM_PLUS_VERSION}"
140+
fi
141+
142+
if ! api_response=$(curl -fsSL -H "Accept: application/vnd.github+json" -H "User-Agent: Sparked-Valheim" "${release_url}"); then
143+
echo "Error: could not retrieve ValheimPlus release information from GitHub"
144+
return 1
145+
fi
146+
147+
version_number=$(jq -r '.tag_name // empty' <<< "${api_response}")
148+
download_url=$(jq -r '.assets[] | select(.name == "UnixServer.zip") | .browser_download_url' <<< "${api_response}" | head -n 1)
149+
installed_version=$(cat "${version_file}" 2>/dev/null || true)
150+
151+
if [[ -z "${version_number}" || -z "${download_url}" ]]; then
152+
echo "Error: the selected ValheimPlus release has no UnixServer.zip asset"
153+
return 1
154+
fi
155+
156+
if [[ -f "BepInEx/plugins/ValheimPlus.dll" && "${installed_version}" == "${version_number}" ]]; then
157+
echo "ValheimPlus is up to date (${version_number})"
158+
return 0
159+
fi
160+
161+
echo "Installing ValheimPlus (${version_number})..."
162+
archive_file=$(mktemp /tmp/valheim-plus.XXXXXX.zip)
163+
extract_dir=$(mktemp -d /tmp/valheim-plus.XXXXXX)
164+
165+
if ! curl -fL --retry 3 --retry-delay 2 -o "${archive_file}" "${download_url}" \
166+
|| ! unzip -q -o "${archive_file}" -d "${extract_dir}" \
167+
|| [[ ! -f "${extract_dir}/BepInEx/plugins/ValheimPlus.dll" ]]; then
168+
echo "Error: could not install ValheimPlus"
169+
rm -rf -- "${extract_dir}" "${archive_file}"
170+
return 1
171+
fi
172+
173+
cp -a "${extract_dir}/." /home/container/
174+
rm -rf -- "${extract_dir}" "${archive_file}"
175+
mkdir -p .apollo
176+
printf '%s\n' "${version_number}" > "${version_file}"
177+
echo "ValheimPlus installation completed (${version_number})"
178+
}
179+
120180
enable_ue4ss() {
121181
local api_response download_url archive_name installed_version
122182
local api_url="https://api.github.com/repos/NullPrism/RE-UE4SS-Linux/releases?per_page=1"
@@ -878,12 +938,33 @@ startup_with_signal_forwarding(){
878938

879939
regular_startup(){
880940
MODIFIED_STARTUP=$(echo ${STARTUP} | sed -e 's/{{/${/g' -e 's/}}/}/g')
941+
MODIFIED_STARTUP="${STARTUP_ENVIRONMENT_PREFIX:-}${MODIFIED_STARTUP}"
881942

882943
echo -e "\033[1;33mcustomer@apollopanel:~\$\033[0m :/home/container$ ${MODIFIED_STARTUP}"
883944

884945
exec /bin/bash -c "${MODIFIED_STARTUP}"
885946
}
886947

948+
configure_valheim_bepinex(){
949+
[[ -f "BepInEx/core/BepInEx.Preloader.dll" ]] || return 0
950+
951+
STARTUP_ENVIRONMENT_PREFIX='DOORSTOP_ENABLED=1 DOORSTOP_TARGET_ASSEMBLY="./BepInEx/core/BepInEx.Preloader.dll" LD_LIBRARY_PATH="./doorstop_libs:${LD_LIBRARY_PATH}" LD_PRELOAD="libdoorstop_x64.so:${LD_PRELOAD}" SteamAppId=892970 '
952+
}
953+
954+
startup_valheim(){
955+
if [[ "${INSTALL_BEPINEX:-0}" == "1" ]]; then
956+
install_bepinex || return 1
957+
fi
958+
959+
if [[ "${INSTALL_VALHEIM_PLUS:-0}" == "1" ]]; then
960+
install_valheim_plus || return 1
961+
fi
962+
963+
setup_nss_wrapper
964+
configure_valheim_bepinex
965+
regular_startup
966+
}
967+
887968
startup_ue4ss(){
888969
local output_directory
889970
local output_pipe
@@ -943,6 +1024,9 @@ startup_ue4ss(){
9431024

9441025
startup_game(){
9451026
case $SRCDS_APPID in
1027+
896660)
1028+
startup_valheim
1029+
;;
9461030
376030)
9471031
startup_ark
9481032
;;

games/valheim/Dockerfile

Lines changed: 0 additions & 30 deletions
This file was deleted.

games/valheim/entrypoint.sh

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)