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:
@@ -1,6 +1,8 @@
|
||||
#===============================================================================
|
||||
# Garry's Mod PropHunt Server - Docker Image
|
||||
# Repository: https://git.vish.gg/Vish/gmod-prophunt-server
|
||||
#
|
||||
# This Dockerfile downloads GMod server at runtime for better compatibility
|
||||
#===============================================================================
|
||||
|
||||
FROM debian:bookworm-slim
|
||||
@@ -23,7 +25,8 @@ ENV DEBIAN_FRONTEND=noninteractive \
|
||||
GAMEMODE="prop_hunt" \
|
||||
WORKSHOP_COLLECTION="" \
|
||||
TICKRATE="66" \
|
||||
TZ="America/Los_Angeles"
|
||||
TZ="America/Los_Angeles" \
|
||||
AUTO_UPDATE="true"
|
||||
|
||||
# Install dependencies
|
||||
RUN dpkg --add-architecture i386 && \
|
||||
@@ -36,7 +39,6 @@ RUN dpkg --add-architecture i386 && \
|
||||
unzip \
|
||||
lib32gcc-s1 \
|
||||
lib32stdc++6 \
|
||||
libsdl2-2.0-0:i386 \
|
||||
locales \
|
||||
tzdata && \
|
||||
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
|
||||
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
|
||||
|
||||
# Switch to gmod user
|
||||
USER gmod
|
||||
WORKDIR /home/gmod
|
||||
|
||||
# Install SteamCMD
|
||||
RUN cd ${STEAMCMD_DIR} && \
|
||||
curl -sqL "https://steamcdn-a.akamaihd.net/client/installer/steamcmd_linux.tar.gz" | tar zxvf -
|
||||
# Install SteamCMD only (server downloaded at runtime)
|
||||
RUN cd /home/gmod/steamcmd && \
|
||||
curl -sqL "https://steamcdn-a.akamaihd.net/client/installer/steamcmd_linux.tar.gz" | tar zxvf - && \
|
||||
./steamcmd.sh +quit
|
||||
|
||||
# Install Garry's Mod server
|
||||
RUN cd ${STEAMCMD_DIR} && \
|
||||
./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 configuration and entrypoint
|
||||
COPY --chown=gmod:gmod cfg/ /home/gmod/cfg-template/
|
||||
COPY --chown=gmod:gmod scripts/docker-entrypoint.sh /home/gmod/entrypoint.sh
|
||||
|
||||
# Make scripts executable
|
||||
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
|
||||
|
||||
# Expose ports
|
||||
EXPOSE 27015/tcp 27015/udp 27005/udp 27020/udp
|
||||
|
||||
# Volumes for persistent data
|
||||
VOLUME ["/home/gmod/serverfiles/garrysmod/data", \
|
||||
"/home/gmod/serverfiles/garrysmod/cfg", \
|
||||
"/home/gmod/serverfiles/garrysmod/addons"]
|
||||
VOLUME ["/home/gmod/serverfiles"]
|
||||
|
||||
# Health check
|
||||
HEALTHCHECK --interval=30s --timeout=10s --start-period=120s --retries=3 \
|
||||
CMD curl -f http://localhost:27015/ 2>/dev/null || exit 1
|
||||
|
||||
WORKDIR ${SERVER_DIR}
|
||||
WORKDIR /home/gmod
|
||||
|
||||
ENTRYPOINT ["/home/gmod/entrypoint.sh"]
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
version: '3.8'
|
||||
|
||||
services:
|
||||
gmod-prophunt:
|
||||
build:
|
||||
@@ -19,6 +17,7 @@ services:
|
||||
- WORKSHOP_COLLECTION=${WORKSHOP_COLLECTION:-}
|
||||
- TICKRATE=${TICKRATE:-66}
|
||||
- TZ=${TZ:-America/Los_Angeles}
|
||||
- AUTO_UPDATE=${AUTO_UPDATE:-true}
|
||||
|
||||
ports:
|
||||
- "${PORT:-27015}:27015/tcp"
|
||||
@@ -27,11 +26,8 @@ services:
|
||||
- "27020:27020/udp"
|
||||
|
||||
volumes:
|
||||
# Persistent data
|
||||
- gmod-data:/home/gmod/serverfiles/garrysmod/data
|
||||
- gmod-addons:/home/gmod/serverfiles/garrysmod/addons
|
||||
# Config can be bind-mounted for easy editing
|
||||
- ./cfg:/home/gmod/serverfiles/garrysmod/cfg:ro
|
||||
# Persistent server files (includes addons, data, configs)
|
||||
- gmod-server:/home/gmod/serverfiles
|
||||
|
||||
networks:
|
||||
- gmod-network
|
||||
@@ -58,5 +54,4 @@ networks:
|
||||
driver: bridge
|
||||
|
||||
volumes:
|
||||
gmod-data:
|
||||
gmod-addons:
|
||||
gmod-server:
|
||||
|
||||
@@ -3,8 +3,9 @@
|
||||
# Garry's Mod PropHunt Server - Docker Entrypoint
|
||||
#===============================================================================
|
||||
|
||||
SERVER_DIR="${GMOD_INSTALL_DIR:-/home/gmod}/serverfiles"
|
||||
STEAMCMD_DIR="${GMOD_INSTALL_DIR:-/home/gmod}/steamcmd"
|
||||
SERVER_DIR="/home/gmod/serverfiles"
|
||||
STEAMCMD_DIR="/home/gmod/steamcmd"
|
||||
CFG_TEMPLATE="/home/gmod/cfg-template"
|
||||
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
@@ -15,6 +16,7 @@ NC='\033[0m'
|
||||
log_info() { echo -e "${BLUE}[INFO]${NC} $1"; }
|
||||
log_success() { echo -e "${GREEN}[SUCCESS]${NC} $1"; }
|
||||
log_warning() { echo -e "${YELLOW}[WARNING]${NC} $1"; }
|
||||
log_error() { echo -e "${RED}[ERROR]${NC} $1"; }
|
||||
|
||||
echo -e "${GREEN}"
|
||||
echo "╔═══════════════════════════════════════════════════════════════╗"
|
||||
@@ -22,15 +24,104 @@ echo "║ 🎮 Garry's Mod PropHunt Server Starting 🎮 ║"
|
||||
echo "╚═══════════════════════════════════════════════════════════════╝"
|
||||
echo -e "${NC}"
|
||||
|
||||
# Update server if AUTO_UPDATE is set
|
||||
if [[ "${AUTO_UPDATE:-false}" == "true" ]]; then
|
||||
log_info "Checking for server updates..."
|
||||
# Check if server is installed
|
||||
install_server() {
|
||||
log_info "Installing/Updating Garry's Mod server..."
|
||||
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 \
|
||||
+app_update 4020 \
|
||||
+quit
|
||||
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"
|
||||
|
||||
@@ -78,10 +169,18 @@ echo ""
|
||||
log_info "Starting server..."
|
||||
|
||||
# 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
|
||||
exec ./srcds_run $ARGS &
|
||||
./srcds_run $ARGS &
|
||||
SERVER_PID=$!
|
||||
|
||||
# Wait for the server process
|
||||
|
||||
Reference in New Issue
Block a user