- bootstrap script streamlined, removed useless functions

- added defaults to all environment variables, now they are all optional for the user
- added a docker composer file
- easier instructions for the free oracle cloud installation
This commit is contained in:
Nosk Lo Github 2022-02-26 17:37:26 +00:00
parent d836ad936a
commit a66fb3a3fb
5 changed files with 110 additions and 161 deletions

View File

@ -1,73 +1,34 @@
# pi4valheim # Varmheim
Experimental Docker file to run a Valheim server in a Raspberry Pi4. #### Valheim in Arm!
The valheim.Dockerfile is based on the stardart repositories of box86 and box64. Experimental Docker file to run a Valheim server in aarch64
It was tested on ubuntu 20.04 aarch64 running in Oracle Cloud Always Free Tier
valheim.Dockerfile is based on the stardard repositories of box86 and box64.
## Compiled image: ## Compiled image:
You can find in the docker hub the image to run directly: https://hub.docker.com/repository/docker/tranko/pi4valheim You can find in the docker hub the image to run directly: https://hub.docker.com/repository/docker/nosklo/varmheim
## Requeriments: ## Requeriments:
Raspberry Pi4: I only tested on a 8GB of RAM with the next requirements: Install oracle cloud always free tier VM.Standard.A1.Flex instance
- [RaspianOs 64 Bits](https://downloads.raspberrypi.org/raspios_arm64/images/raspios_arm64-2020-05-28/) updated. Install docker and docker-composer
- Upgrade the distribution to Debian BullsEye (change the repositories to):
``` run it:
deb http://deb.debian.org/debian bullseye main contrib non-free
deb http://deb.debian.org/debian-security/ bullseye-security main contrib non-free
deb http://deb.debian.org/debian bullseye-updates main contrib non-free
```
Then run the typical upgrade of Debian: $ docker-compose up -d --no-build
```
sudo apt update & sudo apt upgrade & sudo apt dist-upgrade
```
- Install [Podman](https://podman.io/getting-started/installation) v3.3.1 (The version that is in the Debian repository is old (3.0.1) and it does not work correctly in my case). you can use environment variables to change the defaults:
- Install [Docker](https://docs.docker.com/engine/install/debian/) (Tested on version 20.10.9)
## Create the image (it will take around 1-2 hours) PUBLIC=0 # 0 private / 1 public
PORT=2456 # The port that you want valheim server to listen
NAME="Docker Valheim" # Your amazing name of your server.
WORLD=Docker # Your unique name of your world.
SAVEDIR=/vhsave # Where to save your data.
PASSWORD=nopassword
If you use podman:
podman build -f valheim.Dockerfile ## Thanks to those projects for making it possible:
podman image tag c44a18e4e67d valheim-base:v1
If you use docker:
docker build --no-cache --tag valheim-base -f Valheim.dockerfile .
## Execute the container
### First step configure the env.world file:
This values don't be changed. Only if they change in the future:
STEAMAPPID=892970
BOX64_LD_LIBRARY_PATH=./linux64:/root/steam/linux32:$BOX64_LD_LIBRARY_PATH
BOX64_LOG=1
BOX64_TRACE_FILE=/root/valheim_data/output.log
BOX64_TRACE=1
This values are the real ones for yoru server:
PUBLIC=0 # 0 private / 1 public
PORT=2456 # Don't change if don't know what are you doing.
NAME=YourServerName # Your amazing name of your server.
WORLD=YourWorldName # Your unique name of your world.
SAVEDIR=/root/valheim_data # Where to save your data.
PASSWORD=YourUniquePassw0rd # You can leave blank and it will not have password
# NOT recommended for public servers.
### Second step, run the container (example with Docker):
docker run --rm --name valheim -p 2456-2457:2456-2457/udp -v /home/pi/ssd/valheim_data:/root/valheim_data:rw --env-file env.tardis valheim-base
## Considerations:
Pi4 has a limited hardware, it this is emulating x86_64 over arm64, so don't expect so high performance. It works, I didn't have any problems playing some hours.
When the game saves it freeze all connections during some seconds, take it into account!!!!! Several times it does not start correctly and fail (the emulator is not yet finished and it does not work all the times). In that cases, you need to stop the process killing the process.
## This experiment can be done for the next projects:
- [box86](https://github.com/ptitSeb/box86) - [box86](https://github.com/ptitSeb/box86)
- [box64](https://github.com/ptitSeb/box64) - [box64](https://github.com/ptitSeb/box64)
- [docker](docker.com) - [docker](docker.com)
- [podman](podman.io)

113
bootstrap
View File

@ -1,81 +1,52 @@
#!/bin/bash #!/bin/bash
# Get parameters function if [[ -z "${SAVEDIR}" ]] ; then
# This function will check all the parameters SAVEDIR=/vhsave
# Return: fi
# string: params to run the server mkdir -p "$SAVEDIR"
# int: -1 is something is wrong.
getparams() { export STEAMAPPID=${STEAMAPPID:-892970}
# Basic + default params values:
# -nographics: basic param for the valheim documentation. MANDATORY.
# -batchmode: bacic param for the valheim documentation. MANDATORY.
# -public: used the value of the param if defined, if not it will be a private server (0) MANDATORY.
# -port: used the value of the param if defined, if not it will use standard port (2456) MANDATORY.
params="-nographics -batchmode"
params="$params -public ${PUBLIC:-0}"
params="$params -port ${PORT:-2456}"
# Specific params values, if they are not defined, return error: if [[ -z "${BOX64_LD_LIBRARY_PATH}" ]]; then
## Name of the server MANDATORY: export BOX64_LD_LIBRARY_PATH="./linux64:/root/steam/linux32"
if [[ -z "${NAME}" ]]; then fi
echo "The variable NAME is not defined. Please, fix and run again." export BOX64_LOG=${BOX64_LOG:-0}
return -1
else
params="$params -name ${NAME}"
fi
## Name of the world MANDATORY if [[ -z "${BOX64_TRACE_FILE}" ]]; then
if [[ -z "${WORLD}" ]]; then export BOX64_TRACE_FILE="$SAVEDIR/output.log"
echo "The variable WORLD is not defined. Fixed and run again." fi
return -1 export BOX64_TRACE=${BOX64_TRACE:-0}
else
params="$params -world ${WORLD}"
fi
## Save folder for the data (if not defined can run, but the world will be saved on the container, bad idea): # RUN SERVER
if [[ -z "${SAVEDIR}" ]]; then export templdpath="${LD_LIBRARY_PATH}"
echo "The variable SAVEDIR is not defined. Fixed and run again." export LD_LIBRARY_PATH=./linux64:"${LD_LIBRARY_PATH}"
return -1 export SteamAppId=${STEAMAPPID}
else
params="$params -savedir ${SAVEDIR}"
fi
## Password for the server, if not defined, no password = free access: echo "##############################"
if [[ -z "${PASSWORD}" ]]; then echo "Basic variables running box64:"
echo "The variable PASSWORD is not defined. Running WITHOUT password." echo "BOX64_LD_LIBRARY_PATH: ${BOX64_LD_LIBRARY_PATH}"
else echo "BOX64_LOG: ${BOX64_LOG}"
params="$params -password ${PASSWORD}" echo "BOX64_TRACE_FILE: ${BOX64_TRACE_FILE}"
fi echo "BOX64_TRACE: ${BOX64_TRACE}"
} echo "##############################"
echo "COMMAND:" box64 ./valheim_server.x86_64 -nographics -batchmode \
-public "${PUBLIC:-0}" \
-port "${PORT:-2456}" \
-name "${NAME:-Docker Valheim}" \
-world "${WORLD:-Docker}" \
-savedir "${SAVEDIR}" \
-password "${PASSWORD:-nopassword}"
echo "##############################"
# Main function # Move to the execution folder
main() { cd /root/valheim_server
# Basic export for the BOX64 emulator
echo "##############################"
echo "Basic variables running box64:"
echo "BOX64_LD_LIBRARY_PATH: ${BOX64_LD_LIBRARY_PATH}"
echo "BOX64_LOG: ${BOX64_LOG}"
echo "BOX64_TRACE_FILE: ${BOX64_TRACE_FILE}"
echo "BOX64_TRACE: ${BOX64_TRACE}"
echo "##############################"
# Part of the standar code startup of the server: # Starting the server:
export templdpath="${LD_LIBRARY_PATH}" box64 ./valheim_server.x86_64 -nographics -batchmode \
export LD_LIBRARY_PATH=./linux64:"${LD_LIBRARY_PATH}" -public "${PUBLIC:-0}" \
export SteamAppId=${STEAMAPPID} -port "${PORT:-2456}" \
-name "${NAME:-Docker Valheim}" \
-world "${WORLD:-Docker}" \
-savedir "${SAVEDIR}" \
-password "${PASSWORD:-nopassword}"
# Move to the execution folder
cd /root/valheim_server
## Checking the final parameters to use:
echo "##############################"
echo "Final Valheim parameters to run: $params"
echo "##############################"
# Starting the server:
box64 ./valheim_server.x86_64 $params
}
getparams
main

25
docker-compose.yml Normal file
View File

@ -0,0 +1,25 @@
---
version: "3.7"
services:
vhserver:
network_mode: host
image: "nosklo/valheim-base"
build:
context: .
dockerfile: valheim.Dockerfile
# environment:
# NAME: New Server Name
# WORLD: ServerWorldFilename
# PASSWORD: nopassword
# SAVEDIR: /vhsave
# PUBLIC: 0
# PORT: 2456
ports:
- "2456-2457:2456-2457/udp"
volumes:
- "gameserver:/vhsave"
volumes:
gameserver:

View File

@ -1,11 +0,0 @@
STEAMAPPID=892970
BOX64_LD_LIBRARY_PATH=./linux64:/root/steam/linux32:$BOX64_LD_LIBRARY_PATH
BOX64_LOG=1
BOX64_TRACE_FILE=/root/valheim_data/output.log
BOX64_TRACE=1
PUBLIC=0
PORT=2456
NAME=YourServerName
WORLD=YourWorldName
SAVEDIR=/root/valheim_data
PASSWORD=YourUniquePassw0rd

View File

@ -1,11 +1,12 @@
FROM debian FROM ubuntu:20.04
LABEL maintainer="Tranko" LABEL maintainer="NoskLo"
# Install tools required for the project # Install tools required for the project
# Run 'docker build --no-cache .' to udpate dependencies # Run 'docker build --no-cache .' to udpate dependencies
RUN dpkg --add-architecture armhf RUN dpkg --add-architecture armhf
RUN apt update && apt full-upgrade -y RUN apt update && apt full-upgrade -y
RUN apt install -y tzdata && apt clean
RUN apt install -y \ RUN apt install -y \
gcc-arm-linux-gnueabihf \ gcc-arm-linux-gnueabihf \
git \ git \
@ -14,19 +15,23 @@ RUN apt install -y \
python3 \ python3 \
curl \ curl \
libsdl2-2.0-0 \ libsdl2-2.0-0 \
nano nano \
RUN apt install -y \
libc6:armhf \ libc6:armhf \
libncurses5:armhf \ libncurses5:armhf \
libstdc++6:armhf libstdc++6:armhf \
&& apt clean \
&& apt purge -y wget
# Install the box86 to emulate x86 platform (for steamcmd cliente) # Install the box86 to emulate x86 platform (for steamcmd cliente)
WORKDIR /root WORKDIR /root
RUN git clone https://github.com/ptitSeb/box86 RUN git clone https://github.com/ptitSeb/box86 \
WORKDIR /root/box86/build && mkdir -p /root/box86/build \
RUN cmake .. -DRPI4ARM64=1 -DCMAKE_BUILD_TYPE=RelWithDebInfo && cd /root/box86/build \
RUN make -j4; && cmake .. -DRPI4ARM64=1 -DCMAKE_BUILD_TYPE=RelWithDebInfo \
RUN make install && make -j4 \
&& make install \
&& cd /root \
&& rm -rf /root/box86
# Install steamcmd and download the valheim server: # Install steamcmd and download the valheim server:
WORKDIR /root/steam WORKDIR /root/steam
@ -38,16 +43,14 @@ RUN ./steamcmd.sh +@sSteamCmdForcePlatformType linux +login anonymous +force_ins
## Box64 installation ## Box64 installation
WORKDIR /root WORKDIR /root
RUN git clone https://github.com/ptitSeb/box64 RUN git clone https://github.com/ptitSeb/box64 \
WORKDIR /root/box64/build && mkdir -p /root/box64/build \
RUN cmake .. -DRPI4ARM64=1 -DCMAKE_BUILD_TYPE=RelWithDebInfo && cd /root/box64/build \
RUN make -j4; && cmake .. -DRPI4ARM64=1 -DCMAKE_BUILD_TYPE=RelWithDebInfo \
RUN make install && make -j4 \
&& make install \
# Cleaning the image && cd /root \
RUN apt-get purge -y wget && rm -rf /root/box64
RUN rm -r /root/box86
RUN rm -r /root/box64
# Specific for run Valheim server # Specific for run Valheim server
EXPOSE 2456-2457/udp EXPOSE 2456-2457/udp