Fix Docker setup - download GMod at runtime

- Dockerfile now only installs SteamCMD, server downloaded on first run
- Entrypoint handles full server installation including addons
- Fixed volume configuration for persistence
- Added AUTO_UPDATE environment variable
This commit is contained in:
Vish
2026-01-19 06:44:41 +00:00
parent ce7fc9f39c
commit 82ad91ea4e
3 changed files with 126 additions and 68 deletions

View File

@@ -1,6 +1,8 @@
#=============================================================================== #===============================================================================
# Garry's Mod PropHunt Server - Docker Image # Garry's Mod PropHunt Server - Docker Image
# Repository: https://git.vish.gg/Vish/gmod-prophunt-server # Repository: https://git.vish.gg/Vish/gmod-prophunt-server
#
# This Dockerfile downloads GMod server at runtime for better compatibility
#=============================================================================== #===============================================================================
FROM debian:bookworm-slim FROM debian:bookworm-slim
@@ -23,7 +25,8 @@ ENV DEBIAN_FRONTEND=noninteractive \
GAMEMODE="prop_hunt" \ GAMEMODE="prop_hunt" \
WORKSHOP_COLLECTION="" \ WORKSHOP_COLLECTION="" \
TICKRATE="66" \ TICKRATE="66" \
TZ="America/Los_Angeles" TZ="America/Los_Angeles" \
AUTO_UPDATE="true"
# Install dependencies # Install dependencies
RUN dpkg --add-architecture i386 && \ RUN dpkg --add-architecture i386 && \
@@ -36,7 +39,6 @@ RUN dpkg --add-architecture i386 && \
unzip \ unzip \
lib32gcc-s1 \ lib32gcc-s1 \
lib32stdc++6 \ lib32stdc++6 \
libsdl2-2.0-0:i386 \
locales \ locales \
tzdata && \ tzdata && \
sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && \ sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && \
@@ -50,70 +52,32 @@ ENV LANG=en_US.UTF-8 \
# Create user and directories # Create user and directories
RUN useradd -m -s /bin/bash gmod && \ RUN useradd -m -s /bin/bash gmod && \
mkdir -p ${SERVER_DIR} ${STEAMCMD_DIR} && \ mkdir -p /home/gmod/serverfiles /home/gmod/steamcmd && \
chown -R gmod:gmod /home/gmod chown -R gmod:gmod /home/gmod
# Switch to gmod user # Switch to gmod user
USER gmod USER gmod
WORKDIR /home/gmod WORKDIR /home/gmod
# Install SteamCMD # Install SteamCMD only (server downloaded at runtime)
RUN cd ${STEAMCMD_DIR} && \ RUN cd /home/gmod/steamcmd && \
curl -sqL "https://steamcdn-a.akamaihd.net/client/installer/steamcmd_linux.tar.gz" | tar zxvf - curl -sqL "https://steamcdn-a.akamaihd.net/client/installer/steamcmd_linux.tar.gz" | tar zxvf - && \
./steamcmd.sh +quit
# Install Garry's Mod server # Copy configuration and entrypoint
RUN cd ${STEAMCMD_DIR} && \ COPY --chown=gmod:gmod cfg/ /home/gmod/cfg-template/
./steamcmd.sh +force_install_dir ${SERVER_DIR} \
+login anonymous \
+app_update 4020 validate \
+quit
# Install MetaMod:Source
RUN cd /tmp && \
METAMOD_VER=$(curl -s "https://mms.alliedmods.net/mmsdrop/1.11/" | grep -oP 'mmsource-[\d.]+-git\d+-linux\.tar\.gz' | tail -1) && \
wget -q "https://mms.alliedmods.net/mmsdrop/1.11/${METAMOD_VER}" -O metamod.tar.gz && \
tar -xzf metamod.tar.gz -C ${SERVER_DIR}/garrysmod/ && \
rm metamod.tar.gz
# Install SourceMod
RUN cd /tmp && \
SOURCEMOD_VER=$(curl -s "https://sm.alliedmods.net/smdrop/1.11/" | grep -oP 'sourcemod-[\d.]+-git\d+-linux\.tar\.gz' | tail -1) && \
wget -q "https://sm.alliedmods.net/smdrop/1.11/${SOURCEMOD_VER}" -O sourcemod.tar.gz && \
tar -xzf sourcemod.tar.gz -C ${SERVER_DIR}/garrysmod/ && \
rm sourcemod.tar.gz
# Install ULib and ULX
RUN cd /tmp && \
wget -q "https://github.com/TeamUlysses/ulib/archive/refs/heads/master.zip" -O ulib.zip && \
unzip -q ulib.zip -d ${SERVER_DIR}/garrysmod/addons/ && \
mv ${SERVER_DIR}/garrysmod/addons/ulib-master ${SERVER_DIR}/garrysmod/addons/ulib && \
rm ulib.zip && \
wget -q "https://github.com/TeamUlysses/ulx/archive/refs/heads/master.zip" -O ulx.zip && \
unzip -q ulx.zip -d ${SERVER_DIR}/garrysmod/addons/ && \
mv ${SERVER_DIR}/garrysmod/addons/ulx-master ${SERVER_DIR}/garrysmod/addons/ulx && \
rm ulx.zip
# Copy configuration files
COPY --chown=gmod:gmod cfg/ ${SERVER_DIR}/garrysmod/cfg/
COPY --chown=gmod:gmod scripts/docker-entrypoint.sh /home/gmod/entrypoint.sh COPY --chown=gmod:gmod scripts/docker-entrypoint.sh /home/gmod/entrypoint.sh
# Make scripts executable
USER root USER root
RUN chmod +x /home/gmod/entrypoint.sh ${SERVER_DIR}/srcds_run ${SERVER_DIR}/srcds_linux 2>/dev/null || true RUN chmod +x /home/gmod/entrypoint.sh
USER gmod USER gmod
# Expose ports # Expose ports
EXPOSE 27015/tcp 27015/udp 27005/udp 27020/udp EXPOSE 27015/tcp 27015/udp 27005/udp 27020/udp
# Volumes for persistent data # Volumes for persistent data
VOLUME ["/home/gmod/serverfiles/garrysmod/data", \ VOLUME ["/home/gmod/serverfiles"]
"/home/gmod/serverfiles/garrysmod/cfg", \
"/home/gmod/serverfiles/garrysmod/addons"]
# Health check WORKDIR /home/gmod
HEALTHCHECK --interval=30s --timeout=10s --start-period=120s --retries=3 \
CMD curl -f http://localhost:27015/ 2>/dev/null || exit 1
WORKDIR ${SERVER_DIR}
ENTRYPOINT ["/home/gmod/entrypoint.sh"] ENTRYPOINT ["/home/gmod/entrypoint.sh"]

View File

@@ -1,5 +1,3 @@
version: '3.8'
services: services:
gmod-prophunt: gmod-prophunt:
build: build:
@@ -19,6 +17,7 @@ services:
- WORKSHOP_COLLECTION=${WORKSHOP_COLLECTION:-} - WORKSHOP_COLLECTION=${WORKSHOP_COLLECTION:-}
- TICKRATE=${TICKRATE:-66} - TICKRATE=${TICKRATE:-66}
- TZ=${TZ:-America/Los_Angeles} - TZ=${TZ:-America/Los_Angeles}
- AUTO_UPDATE=${AUTO_UPDATE:-true}
ports: ports:
- "${PORT:-27015}:27015/tcp" - "${PORT:-27015}:27015/tcp"
@@ -27,11 +26,8 @@ services:
- "27020:27020/udp" - "27020:27020/udp"
volumes: volumes:
# Persistent data # Persistent server files (includes addons, data, configs)
- gmod-data:/home/gmod/serverfiles/garrysmod/data - gmod-server:/home/gmod/serverfiles
- gmod-addons:/home/gmod/serverfiles/garrysmod/addons
# Config can be bind-mounted for easy editing
- ./cfg:/home/gmod/serverfiles/garrysmod/cfg:ro
networks: networks:
- gmod-network - gmod-network
@@ -58,5 +54,4 @@ networks:
driver: bridge driver: bridge
volumes: volumes:
gmod-data: gmod-server:
gmod-addons:

View File

@@ -3,8 +3,9 @@
# Garry's Mod PropHunt Server - Docker Entrypoint # Garry's Mod PropHunt Server - Docker Entrypoint
#=============================================================================== #===============================================================================
SERVER_DIR="${GMOD_INSTALL_DIR:-/home/gmod}/serverfiles" SERVER_DIR="/home/gmod/serverfiles"
STEAMCMD_DIR="${GMOD_INSTALL_DIR:-/home/gmod}/steamcmd" STEAMCMD_DIR="/home/gmod/steamcmd"
CFG_TEMPLATE="/home/gmod/cfg-template"
RED='\033[0;31m' RED='\033[0;31m'
GREEN='\033[0;32m' GREEN='\033[0;32m'
@@ -15,6 +16,7 @@ NC='\033[0m'
log_info() { echo -e "${BLUE}[INFO]${NC} $1"; } log_info() { echo -e "${BLUE}[INFO]${NC} $1"; }
log_success() { echo -e "${GREEN}[SUCCESS]${NC} $1"; } log_success() { echo -e "${GREEN}[SUCCESS]${NC} $1"; }
log_warning() { echo -e "${YELLOW}[WARNING]${NC} $1"; } log_warning() { echo -e "${YELLOW}[WARNING]${NC} $1"; }
log_error() { echo -e "${RED}[ERROR]${NC} $1"; }
echo -e "${GREEN}" echo -e "${GREEN}"
echo "╔═══════════════════════════════════════════════════════════════╗" echo "╔═══════════════════════════════════════════════════════════════╗"
@@ -22,15 +24,104 @@ echo "║ 🎮 Garry's Mod PropHunt Server Starting 🎮 ║"
echo "╚═══════════════════════════════════════════════════════════════╝" echo "╚═══════════════════════════════════════════════════════════════╝"
echo -e "${NC}" echo -e "${NC}"
# Update server if AUTO_UPDATE is set # Check if server is installed
if [[ "${AUTO_UPDATE:-false}" == "true" ]]; then install_server() {
log_info "Checking for server updates..." log_info "Installing/Updating Garry's Mod server..."
cd "$STEAMCMD_DIR" cd "$STEAMCMD_DIR"
./steamcmd.sh +force_install_dir "$SERVER_DIR" \ ./steamcmd.sh +@sSteamCmdForcePlatformType linux \
+force_install_dir "$SERVER_DIR" \
+login anonymous \
+app_update 4020 validate \
+quit
if [[ $? -ne 0 ]]; then
log_error "Failed to install server. Retrying..."
./steamcmd.sh +@sSteamCmdForcePlatformType linux \
+force_install_dir "$SERVER_DIR" \
+login anonymous \ +login anonymous \
+app_update 4020 \ +app_update 4020 \
+quit +quit
fi fi
}
install_addons() {
log_info "Installing MetaMod, SourceMod, and ULX..."
cd /tmp
# Install MetaMod
METAMOD_VER=$(curl -s "https://mms.alliedmods.net/mmsdrop/1.11/" | grep -oP 'mmsource-[\d.]+-git\d+-linux\.tar\.gz' | tail -1)
if [[ -n "$METAMOD_VER" ]]; then
wget -q "https://mms.alliedmods.net/mmsdrop/1.11/${METAMOD_VER}" -O metamod.tar.gz
tar -xzf metamod.tar.gz -C "$SERVER_DIR/garrysmod/"
rm -f metamod.tar.gz
log_success "MetaMod installed."
fi
# Install SourceMod
SOURCEMOD_VER=$(curl -s "https://sm.alliedmods.net/smdrop/1.11/" | grep -oP 'sourcemod-[\d.]+-git\d+-linux\.tar\.gz' | tail -1)
if [[ -n "$SOURCEMOD_VER" ]]; then
wget -q "https://sm.alliedmods.net/smdrop/1.11/${SOURCEMOD_VER}" -O sourcemod.tar.gz
tar -xzf sourcemod.tar.gz -C "$SERVER_DIR/garrysmod/"
rm -f sourcemod.tar.gz
log_success "SourceMod installed."
fi
# Install ULib
if [[ ! -d "$SERVER_DIR/garrysmod/addons/ulib" ]]; then
wget -q "https://github.com/TeamUlysses/ulib/archive/refs/heads/master.zip" -O ulib.zip
unzip -q ulib.zip -d "$SERVER_DIR/garrysmod/addons/"
mv "$SERVER_DIR/garrysmod/addons/ulib-master" "$SERVER_DIR/garrysmod/addons/ulib"
rm -f ulib.zip
log_success "ULib installed."
fi
# Install ULX
if [[ ! -d "$SERVER_DIR/garrysmod/addons/ulx" ]]; then
wget -q "https://github.com/TeamUlysses/ulx/archive/refs/heads/master.zip" -O ulx.zip
unzip -q ulx.zip -d "$SERVER_DIR/garrysmod/addons/"
mv "$SERVER_DIR/garrysmod/addons/ulx-master" "$SERVER_DIR/garrysmod/addons/ulx"
rm -f ulx.zip
log_success "ULX installed."
fi
}
apply_configs() {
log_info "Applying configuration files..."
# Copy default configs if they don't exist
if [[ -d "$CFG_TEMPLATE" ]]; then
mkdir -p "$SERVER_DIR/garrysmod/cfg"
for file in "$CFG_TEMPLATE"/*; do
if [[ -f "$file" ]]; then
filename=$(basename "$file")
if [[ ! -f "$SERVER_DIR/garrysmod/cfg/$filename" ]]; then
cp "$file" "$SERVER_DIR/garrysmod/cfg/"
fi
fi
done
fi
log_success "Configuration applied."
}
# Check if server needs installation
if [[ ! -f "$SERVER_DIR/srcds_run" ]]; then
log_info "Server not found. Installing..."
install_server
install_addons
apply_configs
elif [[ "${AUTO_UPDATE:-true}" == "true" ]]; then
log_info "Checking for updates..."
install_server
fi
# Ensure addons are installed
if [[ ! -d "$SERVER_DIR/garrysmod/addons/ulx" ]]; then
install_addons
fi
apply_configs
cd "$SERVER_DIR" cd "$SERVER_DIR"
@@ -78,10 +169,18 @@ echo ""
log_info "Starting server..." log_info "Starting server..."
# Handle shutdown signals # Handle shutdown signals
trap 'log_info "Shutting down server..."; kill -SIGTERM $SERVER_PID; wait $SERVER_PID' SIGTERM SIGINT cleanup() {
log_info "Shutting down server..."
if [[ -n "$SERVER_PID" ]]; then
kill -SIGTERM $SERVER_PID 2>/dev/null
wait $SERVER_PID 2>/dev/null
fi
exit 0
}
trap cleanup SIGTERM SIGINT
# Start the server # Start the server
exec ./srcds_run $ARGS & ./srcds_run $ARGS &
SERVER_PID=$! SERVER_PID=$!
# Wait for the server process # Wait for the server process