- 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
Experimental Docker file to run a Valheim server in a Raspberry Pi4.
# Varmheim
#### 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:
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:
Raspberry Pi4: I only tested on a 8GB of RAM with the next requirements:
- [RaspianOs 64 Bits](https://downloads.raspberrypi.org/raspios_arm64/images/raspios_arm64-2020-05-28/) updated.
- Upgrade the distribution to Debian BullsEye (change the repositories to):
Install oracle cloud always free tier VM.Standard.A1.Flex instance
Install docker and docker-composer
```
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
```
run it:
Then run the typical upgrade of Debian:
```
sudo apt update & sudo apt upgrade & sudo apt dist-upgrade
```
$ docker-compose up -d --no-build
- 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).
- Install [Docker](https://docs.docker.com/engine/install/debian/) (Tested on version 20.10.9)
you can use environment variables to change the defaults:
## 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
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:
## Thanks to those projects for making it possible:
- [box86](https://github.com/ptitSeb/box86)
- [box64](https://github.com/ptitSeb/box64)
- [docker](docker.com)
- [podman](podman.io)

113
bootstrap
View File

@ -1,81 +1,52 @@
#!/bin/bash
# Get parameters function
# This function will check all the parameters
# Return:
# string: params to run the server
# int: -1 is something is wrong.
if [[ -z "${SAVEDIR}" ]] ; then
SAVEDIR=/vhsave
fi
mkdir -p "$SAVEDIR"
getparams() {
# 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}"
export STEAMAPPID=${STEAMAPPID:-892970}
# Specific params values, if they are not defined, return error:
## Name of the server MANDATORY:
if [[ -z "${NAME}" ]]; then
echo "The variable NAME is not defined. Please, fix and run again."
return -1
else
params="$params -name ${NAME}"
fi
if [[ -z "${BOX64_LD_LIBRARY_PATH}" ]]; then
export BOX64_LD_LIBRARY_PATH="./linux64:/root/steam/linux32"
fi
export BOX64_LOG=${BOX64_LOG:-0}
## Name of the world MANDATORY
if [[ -z "${WORLD}" ]]; then
echo "The variable WORLD is not defined. Fixed and run again."
return -1
else
params="$params -world ${WORLD}"
fi
if [[ -z "${BOX64_TRACE_FILE}" ]]; then
export BOX64_TRACE_FILE="$SAVEDIR/output.log"
fi
export BOX64_TRACE=${BOX64_TRACE:-0}
## Save folder for the data (if not defined can run, but the world will be saved on the container, bad idea):
if [[ -z "${SAVEDIR}" ]]; then
echo "The variable SAVEDIR is not defined. Fixed and run again."
return -1
else
params="$params -savedir ${SAVEDIR}"
fi
# RUN SERVER
export templdpath="${LD_LIBRARY_PATH}"
export LD_LIBRARY_PATH=./linux64:"${LD_LIBRARY_PATH}"
export SteamAppId=${STEAMAPPID}
## Password for the server, if not defined, no password = free access:
if [[ -z "${PASSWORD}" ]]; then
echo "The variable PASSWORD is not defined. Running WITHOUT password."
else
params="$params -password ${PASSWORD}"
fi
}
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 "##############################"
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
main() {
# 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 "##############################"
# Move to the execution folder
cd /root/valheim_server
# Part of the standar code startup of the server:
export templdpath="${LD_LIBRARY_PATH}"
export LD_LIBRARY_PATH=./linux64:"${LD_LIBRARY_PATH}"
export SteamAppId=${STEAMAPPID}
# Move to the execution folder
cd /root/valheim_server
# Starting the server:
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}"
## 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
# Run 'docker build --no-cache .' to udpate dependencies
RUN dpkg --add-architecture armhf
RUN apt update && apt full-upgrade -y
RUN apt install -y tzdata && apt clean
RUN apt install -y \
gcc-arm-linux-gnueabihf \
git \
@ -14,19 +15,23 @@ RUN apt install -y \
python3 \
curl \
libsdl2-2.0-0 \
nano
RUN apt install -y \
nano \
libc6: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)
WORKDIR /root
RUN git clone https://github.com/ptitSeb/box86
WORKDIR /root/box86/build
RUN cmake .. -DRPI4ARM64=1 -DCMAKE_BUILD_TYPE=RelWithDebInfo
RUN make -j4;
RUN make install
RUN git clone https://github.com/ptitSeb/box86 \
&& mkdir -p /root/box86/build \
&& cd /root/box86/build \
&& cmake .. -DRPI4ARM64=1 -DCMAKE_BUILD_TYPE=RelWithDebInfo \
&& make -j4 \
&& make install \
&& cd /root \
&& rm -rf /root/box86
# Install steamcmd and download the valheim server:
WORKDIR /root/steam
@ -38,16 +43,14 @@ RUN ./steamcmd.sh +@sSteamCmdForcePlatformType linux +login anonymous +force_ins
## Box64 installation
WORKDIR /root
RUN git clone https://github.com/ptitSeb/box64
WORKDIR /root/box64/build
RUN cmake .. -DRPI4ARM64=1 -DCMAKE_BUILD_TYPE=RelWithDebInfo
RUN make -j4;
RUN make install
# Cleaning the image
RUN apt-get purge -y wget
RUN rm -r /root/box86
RUN rm -r /root/box64
RUN git clone https://github.com/ptitSeb/box64 \
&& mkdir -p /root/box64/build \
&& cd /root/box64/build \
&& cmake .. -DRPI4ARM64=1 -DCMAKE_BUILD_TYPE=RelWithDebInfo \
&& make -j4 \
&& make install \
&& cd /root \
&& rm -rf /root/box64
# Specific for run Valheim server
EXPOSE 2456-2457/udp