-
-
Notifications
You must be signed in to change notification settings - Fork 82
/
Dockerfile.valheim
141 lines (120 loc) · 4.85 KB
/
Dockerfile.valheim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
ARG UBUNTU_VERSION=22
ARG EXPECTED_OCTAL=775
ARG ODIN_IMAGE_VERSION=latest
# ------------------ #
# -- Odin Builder -- #
# ------------------ #
FROM --platform=linux/amd64 mbround18/odin:${ODIN_IMAGE_VERSION} AS runtime
# ------------------ #
# -- Steam Setup -- #
# ------------------ #
FROM steamcmd/steamcmd:ubuntu-${UBUNTU_VERSION} AS root
USER root
# Set environment variables
ENV TZ=America/Los_Angeles \
PUID=111 \
PGID=1000
# Set timezone and install necessary packages
RUN --mount=type=cache,target=/var/cache/apt \
--mount=type=cache,target=/var/lib/apt \
ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone && \
apt-get update && \
apt-get upgrade -y && \
apt-get install -y -qq \
build-essential procps htop net-tools nano gcc g++ gdb \
netcat-traditional curl wget zip unzip cron sudo gosu dos2unix \
libsdl2-2.0-0 jq libc6 libc6-dev libpulse-dev libatomic1 \
tzdata bc && \
rm -rf /var/lib/apt/lists/* && \
gosu nobody true && \
dos2unix && \
groupadd -g ${PGID} steam && \
useradd -u ${PUID} -g steam -d /home/steam -m -s /bin/bash steam
# Create necessary directories and set permissions
RUN mkdir -p /home/steam/.steam/steam/package && \
mkdir -p /home/{steam,steam/{valheim,.steam}} && \
chmod ugo+rw /tmp/dumps && \
chown -R ${PUID}:${PGID} /home/steam
# Container information
ARG GITHUB_SHA="not-set"
ARG GITHUB_REF="not-set"
ARG GITHUB_REPOSITORY="not-set"
COPY --from=runtime --chmod=755 /apps/odin /apps/huginn /usr/local/bin/
# Set version information and configure sudoers
RUN printf "${GITHUB_SHA}\n${GITHUB_REF}\n${GITHUB_REPOSITORY}\n" >/home/steam/.version && \
echo "root ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers && \
echo "steam ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
# --------------- #
# -- Steam CMD -- #
# --------------- #
FROM root AS steamcmd
USER steam
ENV HOME /home/steam
ENV USER steam
ADD --chown=steam:steam https://steamcdn-a.akamaihd.net/client/installer/steamcmd_linux.tar.gz /home/steam/steamcmd.tar.gz
COPY --chmod=${EXPECTED_OCTAL} --chown=steam:steam --from=root /home/steam/.version /home/steam/.version
RUN mkdir -p /home/steam/.local/share/Steam/steamcmd && \
tar -xvzf /home/steam/steamcmd.tar.gz -C /home/steam/.local/share/Steam/steamcmd/ && \
rm /home/steam/steamcmd.tar.gz && \
mkdir -p $HOME/.steam && \
ln -s $HOME/.local/share/Steam/steamcmd/linux32 $HOME/.steam/sdk32 && \
ln -s $HOME/.local/share/Steam/steamcmd/linux64 $HOME/.steam/sdk64 && \
ln -s $HOME/.steam/sdk32/steamclient.so $HOME/.steam/sdk32/steamservice.so && \
steamcmd +quit
# --------------- #
# -- Valheim -- #
# --------------- #
FROM steamcmd AS valheim
USER steam
ENV HOME /home/steam
ENV USER steam
# Set environment variables for Valheim server
ENV PORT="2456" \
NAME="Valheim Docker" \
WORLD="Dedicated" \
PUBLIC="1" \
PASSWORD="" \
TYPE="Vanilla" \
UPDATE_ON_STARTUP="1" \
AUTO_UPDATE="0" \
AUTO_UPDATE_SCHEDULE="0 1 * * *" \
AUTO_BACKUP="0" \
AUTO_BACKUP_SCHEDULE="*/15 * * * *" \
AUTO_BACKUP_REMOVE_OLD="1" \
AUTO_BACKUP_DAYS_TO_LIVE="3" \
AUTO_BACKUP_ON_UPDATE="0" \
AUTO_BACKUP_ON_SHUTDOWN="0" \
AUTO_BACKUP_PAUSE_WITH_NO_PLAYERS="0" \
SCHEDULED_RESTART="0" \
SCHEDULED_RESTART_SCHEDULE="0 2 * * *" \
SAVE_LOCATION="/home/steam/.config/unity3d/IronGate/Valheim" \
MODS_LOCATION="/home/steam/staging/mods" \
GAME_LOCATION="/home/steam/valheim" \
BACKUP_LOCATION="/home/steam/backups" \
WEBHOOK_STATUS_SUCCESSFUL="1" \
WEBHOOK_STATUS_FAILED="1" \
BEPINEX_RELEASES_URL="https://thunderstore.io/api/experimental/package/denikson/BepInExPack_Valheim/" \
WEBHOOK_STATUS_JOINED="1" \
WEBHOOK_STATUS_LEFT="1"
# Copy scripts and set permissions
COPY --chmod=${EXPECTED_OCTAL} --chown=steam:steam ./src/scripts/*.sh /home/steam/scripts/
COPY --chmod=${EXPECTED_OCTAL} --chown=steam:steam ./src/scripts/entrypoint.sh /entrypoint.sh
COPY --chmod=${EXPECTED_OCTAL} --chown=steam:steam ./src/scripts/env.sh /env.sh
COPY --chmod=${EXPECTED_OCTAL} --chown=steam:steam ./src/scripts/steam_bashrc.sh /home/steam/.bashrc
# Convert scripts to Unix format
RUN dos2unix /entrypoint.sh /home/steam/.bashrc /home/steam/scripts/*.sh || true \
&& chmod +x /entrypoint.sh /home/steam/.bashrc /home/steam/scripts/*.sh \
&& chmod ug+rw /home/steam/ \
&& chown -R steam:steam /home/steam/.steam \
&& steamcmd +quit
# Set the working directory to the game directory
WORKDIR /home/steam/valheim
# Expose the necessary ports
EXPOSE 2456/udp 2457/udp 2458/udp
EXPOSE 2456/tcp 2457/tcp 2458/tcp
EXPOSE 3000/tcp
# Healthcheck to ensure the Valheim server is running
HEALTHCHECK --interval=1m --timeout=3s CMD pidof valheim_server.x86_64 || exit 1
# Define the entrypoint and command
ENTRYPOINT ["/bin/bash", "/entrypoint.sh"]
CMD ["/bin/bash", "/home/steam/scripts/start_valheim.sh"]