Reworked to allow mounted config volume.

This commit is contained in:
Matthew Green 2025-04-08 17:57:26 -05:00
parent 3b60e70d88
commit 5a1af7b1a5
5 changed files with 64 additions and 39 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
config/

View file

@ -1,46 +1,29 @@
FROM steamcmd/steamcmd:debian
ENV PORT=7777
ENV INSTALL_DIR=/home/steam
ENV SERVER_DIR=${INSTALL_DIR}/server
ENV CONFIG_DIR=${INSTALL_DIR}/.config
ENV CONFIG_TEMPLATES_DIR=${INSTALL_DIR}/config-templates
# Default UID/GID that can be overridden at runtime
ENV UID=1000
ENV GID=1000
# ENV HOME_DIR=/home/steam
# ENV SERVER=$HOME_DIR/server
# ENV CONFIGS=$HOME_DIR/.config/SCP\ Secret\ Laboratory/config/$PORT
ENV STEAM_DIR=/usr/lib/games/steam
ENV INSTALL_DIR=/home/steam
ENV SERVER_DIR=$INSTALL_DIR/server
ENV CONFIG_DIR=$INSTALL_DIR/.config
ENV CONFIG_TEMPLATES_DIR=$INSTALL_DIR/.config-templates
RUN mkdir -p ${INSTALL_DIR} ${SERVER_DIR} ${CONFIG_DIR} ${CONFIG_TEMPLATES_DIR}
# Install dependencies
RUN apt-get update && \
apt-get install -y libicu-dev
apt-get install -y libicu-dev gosu && \
rm -rf /var/lib/apt/lists/*
# COPY config_gameplay.txt $CONFIGS/config_gameplay.txt
# COPY config_remoteadmin.txt $CONFIGS/config_remoteadmin.txt
# COPY config_localadmin_global.txt $CONFIGS/../config_localadmin_global.txt
# COPY localadmin_internal_data.json $CONFIGS/../localadmin_internal_data.json
# Create directories (but don't create the user yet)
RUN mkdir -p ${CONFIG_TEMPLATES_DIR}
COPY config-templates/ ${CONFIG_TEMPLATES_DIR}/
# Create steam user and group
RUN groupadd --gid $GID steam && \
useradd --create-home -c 'Steam User' -l --uid $UID --gid $GID --home-dir $INSTALL_DIR steam && \
chown -R steam:steam ${INSTALL_DIR} ${SERVER_DIR} ${CONFIG_DIR} ${CONFIG_TEMPLATES_DIR} && \
chmod 777 ${INSTALL_DIR} ${SERVER_DIR} ${CONFIG_DIR} ${CONFIG_TEMPLATES_DIR}
# Copy and prepare scripts
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
# Copy and prepare start script
COPY start.sh $INSTALL_DIR/start.sh
RUN chmod +x ${INSTALL_DIR}/start.sh && \
chown -R steam:steam ${INSTALL_DIR}/start.sh
COPY start.sh /start.sh
RUN chmod +x /start.sh
# Copy configuration template files
COPY config-templates/ ${CONFIG_TEMPLATES_DIR}
# Switch to steam user
USER steam
WORKDIR $INSTALL_DIR
# Set HOME environment variable to INSTALL_DIR to force steamcmd to use it
ENV HOME=$INSTALL_DIR
ENTRYPOINT ["/bin/sh", "start.sh"]
# User will be created at runtime based on ENV values
ENTRYPOINT ["/bin/sh", "/entrypoint.sh"]

View file

@ -23,6 +23,9 @@ run: build
@echo "Running container: $(CONTAINER_NAME)"
docker run -d --name $(CONTAINER_NAME) \
-p $(PORT):$(PORT)/udp \
-v $(PWD)/config:/home/steam/config \
-e UID=1001 \
-e GID=1001 \
--restart unless-stopped \
$(IMAGE_NAME):latest

37
entrypoint.sh Normal file
View file

@ -0,0 +1,37 @@
#!/bin/sh
set -e
echo "Setting up container with UID:${UID} and GID:${GID}"
# Check if group with GID exists
if getent group ${GID} > /dev/null; then
EXISTING_GROUP=$(getent group ${GID} | cut -d: -f1)
if [ "${EXISTING_GROUP}" != "steam" ]; then
echo "ERROR: GID ${GID} already exists with group name '${EXISTING_GROUP}'" >&2
exit 1
fi
else
groupadd --gid ${GID} steam
fi
# Check if user with UID exists
if getent passwd ${UID} > /dev/null; then
EXISTING_USER=$(getent passwd ${UID} | cut -d: -f1)
if [ "${EXISTING_USER}" != "steam" ]; then
echo "ERROR: UID ${UID} already exists with username '${EXISTING_USER}'" >&2
exit 1
fi
else
useradd -c 'Steam User' -l --uid ${UID} --gid ${GID} --home-dir ${INSTALL_DIR} steam
fi
# Get username for the UID
USER_NAME=$(getent passwd ${UID} | cut -d: -f1)
mkdir -p ${SERVER_DIR} ${CONFIG_DIR}
# Ensure correct ownership of all directories
chown -R ${UID}:${GID} ${INSTALL_DIR} ${SERVER_DIR} ${CONFIG_TEMPLATES_DIR}
chmod -R 775 ${CONFIG_DIR}
# Now run the actual script as the specified user
exec gosu steam /start.sh

View file

@ -1,13 +1,14 @@
#!/bin/sh
set -e
echo "Current user is: $(whoami)"
# Install/update SCP:SL server
steamcmd +force_install_dir $SERVER_DIR +login anonymous +app_update 996560 validate +quit
# # Ensure config directory exists
# Ensure config directory exists
INTERNAL_CONFIG_SUBDIR="$CONFIG_DIR/SCP Secret Laboratory/config/"
mkdir -p "$INTERNAL_CONFIG_SUBDIR"
chmod 755 "$INTERNAL_CONFIG_SUBDIR"
# Process the internal data template to accept EULA
INTERNAL_DATA_TEMPLATE_FILE="$CONFIG_TEMPLATES_DIR/localadmin_internal_data.json.template"
@ -22,7 +23,7 @@ if [ ! -f "$INTERNAL_DATA_FILE" ]; then
echo "Successfully created \`localadmin_internal_data.json\` file with EULA acceptance."
fi
# Run server directly (no need to su)
cd $SERVER_DIR && HOME=$INSTALL_DIR ./LocalAdmin $PORT
# Run server
cd $SERVER_DIR && HOME=$INSTALL_DIR ./LocalAdmin $PORT --config $(CONFIG_DIR)
sleep infinity