-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathDockerfile
More file actions
113 lines (94 loc) · 4.66 KB
/
Copy pathDockerfile
File metadata and controls
113 lines (94 loc) · 4.66 KB
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
# syntax=docker/dockerfile:1
#
# One Dockerfile for all Debian variants, via build args:
# debian-root FINAL_USER=root
# debian-x64 STEAM_BETA="-beta x86-64" SRCDS_BINARY=srcds_run_x64
# debian-x64-root the x64 args + FINAL_USER=root
# GMod and CSS download in parallel stages; the final stage assembles both.
ARG BASE_IMAGE=debian:trixie-slim
# base: OS packages + SteamCMD, shared by every stage
FROM ${BASE_IMAGE} AS base
ARG STEAM_BETA=""
ENV DEBIAN_FRONTEND=noninteractive
# HOME under the server root so .steam/steamclient.so resolves for steam and root.
ENV HOME=/home/gmod
# Modern Debian renamed/dropped the old i386 libs (libssl1.1, libtinfo5, lib32gcc1...).
RUN dpkg --add-architecture i386 \
&& apt-get update \
&& apt-get -y --no-install-recommends --no-install-suggests install \
wget ca-certificates tar lib32gcc-s1 libgcc-s1 libcurl4-gnutls-dev:i386 \
libcurl4:i386 libtinfo6:i386 lib32z1 lib32stdc++6 libncurses6:i386 \
libcurl3-gnutls:i386 gdb libsdl2-2.0-0:i386 libfontconfig1 net-tools unzip gosu \
&& apt-get clean \
&& rm -rf /tmp/* /var/lib/apt/lists/*
# Build as steam so content is steam-owned; the root variant only flips USER at the end.
RUN useradd -d /home/gmod -m steam
USER steam
RUN mkdir /home/gmod/server /home/gmod/steamcmd
# +quit pre-warms SteamCMD's self-update.
RUN wget -P /home/gmod/steamcmd/ https://steamcdn-a.akamaihd.net/client/installer/steamcmd_linux.tar.gz \
&& tar -xzf /home/gmod/steamcmd/steamcmd_linux.tar.gz -C /home/gmod/steamcmd \
&& rm -rf /home/gmod/steamcmd/steamcmd_linux.tar.gz \
&& /home/gmod/steamcmd/steamcmd.sh +quit
RUN mkdir -p /home/gmod/.steam/sdk32 /home/gmod/.steam/sdk64 \
&& cp /home/gmod/steamcmd/linux32/steamclient.so /home/gmod/.steam/sdk32/steamclient.so \
&& cp /home/gmod/steamcmd/linux64/steamclient.so /home/gmod/.steam/sdk64/steamclient.so
# Kept for srcds -autoupdate. ${STEAM_BETA:+ ...} adds the beta flag only when set.
RUN printf '@ShutdownOnFailedCommand 0\n@NoPromptForPassword 1\n\nforce_install_dir /home/gmod/server\nlogin anonymous\napp_update 4020%s validate\nquit\n' "${STEAM_BETA:+ ${STEAM_BETA}}" > /home/gmod/update.txt
# gmod: download the dedicated server (parallel with css)
FROM base AS gmod
ARG SRCDS_BINARY=srcds_run
# Retry: a fresh SteamCMD can fail the first app_update yet exit 0.
RUN for i in 1 2 3 4 5; do \
/home/gmod/steamcmd/steamcmd.sh +runscript /home/gmod/update.txt +quit; \
[ -f "/home/gmod/server/${SRCDS_BINARY}" ] && break; \
echo "GMod download attempt $i incomplete, retrying..."; \
done; \
[ -f "/home/gmod/server/${SRCDS_BINARY}" ]
# css: download Counter-Strike: Source content (parallel with gmod)
FROM base AS css
RUN for i in 1 2 3 4 5; do \
/home/gmod/steamcmd/steamcmd.sh \
+force_install_dir /home/gmod/css \
+login anonymous \
+app_update 232330 validate \
+quit; \
[ -d /home/gmod/css/cstrike ] && break; \
echo "CSS download attempt $i incomplete, retrying..."; \
done; \
[ -d /home/gmod/css/cstrike ]
# final: assemble the runnable image
FROM base AS final
ARG SRCDS_BINARY=srcds_run
ARG FINAL_USER=steam
LABEL maintainer="ceifa"
LABEL description="A structured Garry's Mod dedicated server under a debian linux image"
COPY --from=gmod --chown=steam:steam /home/gmod/server /home/gmod/server
COPY --from=css --chown=steam:steam /home/gmod/css/cstrike /home/gmod/mounts/cstrike
# data/ is a volume (gamemode data + sv.db, symlinked in); addons/gamemodes stay
# non-volumes so they can be baked in or bind-mounted.
RUN echo '"mountcfg" {"cstrike" "/home/gmod/mounts/cstrike"}' > /home/gmod/server/garrysmod/cfg/mount.cfg \
&& mkdir -p /home/gmod/server/steam_cache/content /home/gmod/server/garrysmod/cache/srcds \
&& mkdir -p /home/gmod/server/garrysmod/data \
&& ln -sf data/sv.db /home/gmod/server/garrysmod/sv.db
VOLUME ["/home/gmod/server/garrysmod/data"]
# https://developer.valvesoftware.com/wiki/Source_Dedicated_Server#Connectivity
EXPOSE 27015
EXPOSE 27015/udp
EXPOSE 27005/udp
ENV MAXPLAYERS="16"
ENV GAMEMODE="sandbox"
ENV MAP="gm_construct"
ENV PORT="27015"
ENV SRCDS_BINARY=${SRCDS_BINARY}
COPY --chown=steam:steam assets/entrypoint.sh /home/gmod/entrypoint.sh
COPY --chown=steam:steam assets/start.sh /home/gmod/start.sh
COPY --chown=steam:steam assets/health.sh /home/gmod/health.sh
RUN chmod +x /home/gmod/entrypoint.sh /home/gmod/start.sh /home/gmod/health.sh
HEALTHCHECK --start-period=10s \
CMD /home/gmod/health.sh
# Entrypoint runs as root (PUID/PGID remap), then drops to GMOD_USER.
ENV GMOD_USER=${FINAL_USER}
USER root
ENTRYPOINT ["/home/gmod/entrypoint.sh"]
CMD ["/home/gmod/start.sh"]