diff --git a/.github/workflows/games.yml b/.github/workflows/games.yml index 4ca3a3a..cf49457 100644 --- a/.github/workflows/games.yml +++ b/.github/workflows/games.yml @@ -18,6 +18,7 @@ jobs: game: - arma3 - source + - valheim steps: - uses: actions/checkout@v2 - uses: docker/setup-buildx-action@v1 diff --git a/README.md b/README.md index c2b666b..bbac7a6 100644 --- a/README.md +++ b/README.md @@ -79,6 +79,8 @@ is tagged correctly. * `ghcr.io/parkervcp/games:arma3` * [`source`](/games/source) * `ghcr.io/parkervcp/games:source` +* [`valheim`](/games/valheim) + * `ghcr.io/parkervcp/games:valheim` ### [Golang](/go) diff --git a/games/valheim/Dockerfile b/games/valheim/Dockerfile new file mode 100644 index 0000000..9741d85 --- /dev/null +++ b/games/valheim/Dockerfile @@ -0,0 +1,38 @@ +FROM --platform=$TARGETOS/$TARGETARCH ubuntu:22.04 + +LABEL author="Daniel Barton" maintainer="danny6167@gmail.com" + +ENV DEBIAN_FRONTEND noninteractive + +## add container user +RUN useradd -m -d /home/container -s /bin/bash container + + + +RUN dpkg --add-architecture i386 \ + && apt update \ + && apt upgrade -y \ + && apt install -y libcurl4-gnutls-dev:i386 libssl3:i386 libcurl4:i386 lib32tinfo6 libtinfo6:i386 lib32z1 lib32stdc++6 libncurses5:i386 libcurl3-gnutls:i386 libsdl2-2.0-0:i386 \ + gcc g++ libgcc1 libc++-dev gdb libc6 curl tar iproute2 net-tools libatomic1 libsdl1.2debian libsdl2-2.0-0 \ + libfontconfig locales libcurl3-gnutls libpulse-dev libpulse0 libnss-wrapper gettext + +## configure locale +RUN update-locale lang=en_US.UTF-8 \ + && dpkg-reconfigure --frontend noninteractive locales + + +ENV USER=container HOME=/home/container +WORKDIR /home/container + + + +## Prepare NSS Wrapper for the entrypoint as a workaround for Valheim requiring a valid UID +ENV NSS_WRAPPER_PASSWD=/tmp/passwd NSS_WRAPPER_GROUP=/tmp/group +RUN touch ${NSS_WRAPPER_PASSWD} ${NSS_WRAPPER_GROUP} \ + && chgrp 0 ${NSS_WRAPPER_PASSWD} ${NSS_WRAPPER_GROUP} \ + && chmod g+rw ${NSS_WRAPPER_PASSWD} ${NSS_WRAPPER_GROUP} +ADD passwd.template /passwd.template + + +COPY ./entrypoint.sh /entrypoint.sh +CMD [ "/bin/bash", "/entrypoint.sh" ] diff --git a/games/valheim/entrypoint.sh b/games/valheim/entrypoint.sh new file mode 100644 index 0000000..7a4356b --- /dev/null +++ b/games/valheim/entrypoint.sh @@ -0,0 +1,46 @@ +#!/bin/bash +cd /home/container + +# Make internal Docker IP address available to processes. +INTERNAL_IP=$(ip route get 1 | awk '{print $(NF-2);exit}') +export INTERNAL_IP + + +## just in case someone removed the defaults. +if [ "${STEAM_USER}" == "" ]; then + echo -e "steam user is not set.\n" + echo -e "Using anonymous user.\n" + STEAM_USER=anonymous + STEAM_PASS="" + STEAM_AUTH="" +else + echo -e "user set to ${STEAM_USER}" +fi + +## if auto_update is not set or to 1 update +if [ -z ${AUTO_UPDATE} ] || [ "${AUTO_UPDATE}" == "1" ]; then + # Update Source Server + if [ ! -z ${SRCDS_APPID} ]; then + ./steamcmd/steamcmd.sh +force_install_dir /home/container +login ${STEAM_USER} ${STEAM_PASS} ${STEAM_AUTH} $( [[ "${WINDOWS_INSTALL}" == "1" ]] && printf %s '+@sSteamCmdForcePlatformType windows' ) +app_update ${SRCDS_APPID} $( [[ -z ${SRCDS_BETAID} ]] || printf %s "-beta ${SRCDS_BETAID}" ) $( [[ -z ${SRCDS_BETAPASS} ]] || printf %s "-betapassword ${SRCDS_BETAPASS}" ) $( [[ -z ${HLDS_GAME} ]] || printf %s "+app_set_config 90 mod ${HLDS_GAME}" ) $( [[ -z ${VALIDATE} ]] || printf %s "validate" ) +quit + else + echo -e "No appid set. Starting Server" + fi + +else + echo -e "Not updating game server as auto update was set to 0. Starting Server" +fi + + +# Setup NSS Wrapper for use ($NSS_WRAPPER_PASSWD and $NSS_WRAPPER_GROUP have been set by the Dockerfile) +export USER_ID=$(id -u) +export GROUP_ID=$(id -g) +envsubst < /passwd.template > ${NSS_WRAPPER_PASSWD} + +export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libnss_wrapper.so + +# Replace Startup Variables +MODIFIED_STARTUP=$(echo -e ${STARTUP} | sed -e 's/{{/${/g' -e 's/}}/}/g') +echo -e ":/home/container$ ${MODIFIED_STARTUP}" + +# Run the Server +eval ${MODIFIED_STARTUP} diff --git a/games/valheim/passwd.template b/games/valheim/passwd.template new file mode 100644 index 0000000..d14bace --- /dev/null +++ b/games/valheim/passwd.template @@ -0,0 +1,26 @@ +root:x:0:0:root:/root:/bin/bash +daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin +bin:x:2:2:bin:/bin:/usr/sbin/nologin +sys:x:3:3:sys:/dev:/usr/sbin/nologin +sync:x:4:65534:sync:/bin:/bin/sync +games:x:5:60:games:/usr/games:/usr/sbin/nologin +man:x:6:12:man:/var/cache/man:/usr/sbin/nologin +lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin +mail:x:8:8:mail:/var/mail:/usr/sbin/nologin +news:x:9:9:news:/var/spool/news:/usr/sbin/nologin +uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin +proxy:x:13:13:proxy:/bin:/usr/sbin/nologin +www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin +backup:x:34:34:backup:/var/backups:/usr/sbin/nologin +list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin +irc:x:39:39:ircd:/var/run/ircd:/usr/sbin/nologin +gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologin +nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin +systemd-timesync:x:100:102:systemd Time Synchronization,,,:/run/systemd:/bin/false +systemd-network:x:101:103:systemd Network Management,,,:/run/systemd/netif:/bin/false +systemd-resolve:x:102:104:systemd Resolver,,,:/run/systemd/resolve:/bin/false +systemd-bus-proxy:x:103:105:systemd Bus Proxy,,,:/run/systemd:/bin/false +syslog:x:104:108::/home/syslog:/bin/false +messagebus:x:106:109::/var/run/dbus:/bin/false +bind:x:108:112::/var/cache/bind:/bin/false +${USER_NAME}:x:${USER_ID}:${GROUP_ID}:${USER_NAME}:${HOME}:/bin/bash