Reworked to allow mounted config volume.
This commit is contained in:
parent
3b60e70d88
commit
5a1af7b1a5
5 changed files with 64 additions and 39 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
config/
|
||||||
53
Dockerfile
53
Dockerfile
|
|
@ -1,46 +1,29 @@
|
||||||
FROM steamcmd/steamcmd:debian
|
FROM steamcmd/steamcmd:debian
|
||||||
|
|
||||||
ENV PORT=7777
|
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 UID=1000
|
||||||
ENV GID=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 && \
|
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
|
# Create directories (but don't create the user yet)
|
||||||
# COPY config_remoteadmin.txt $CONFIGS/config_remoteadmin.txt
|
RUN mkdir -p ${CONFIG_TEMPLATES_DIR}
|
||||||
# COPY config_localadmin_global.txt $CONFIGS/../config_localadmin_global.txt
|
COPY config-templates/ ${CONFIG_TEMPLATES_DIR}/
|
||||||
# COPY localadmin_internal_data.json $CONFIGS/../localadmin_internal_data.json
|
|
||||||
|
|
||||||
# Create steam user and group
|
# Copy and prepare scripts
|
||||||
RUN groupadd --gid $GID steam && \
|
COPY entrypoint.sh /entrypoint.sh
|
||||||
useradd --create-home -c 'Steam User' -l --uid $UID --gid $GID --home-dir $INSTALL_DIR steam && \
|
RUN chmod +x /entrypoint.sh
|
||||||
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 start script
|
COPY start.sh /start.sh
|
||||||
COPY start.sh $INSTALL_DIR/start.sh
|
RUN chmod +x /start.sh
|
||||||
RUN chmod +x ${INSTALL_DIR}/start.sh && \
|
|
||||||
chown -R steam:steam ${INSTALL_DIR}/start.sh
|
|
||||||
|
|
||||||
# Copy configuration template files
|
# User will be created at runtime based on ENV values
|
||||||
COPY config-templates/ ${CONFIG_TEMPLATES_DIR}
|
ENTRYPOINT ["/bin/sh", "/entrypoint.sh"]
|
||||||
|
|
||||||
# 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"]
|
|
||||||
3
Makefile
3
Makefile
|
|
@ -23,6 +23,9 @@ run: build
|
||||||
@echo "Running container: $(CONTAINER_NAME)"
|
@echo "Running container: $(CONTAINER_NAME)"
|
||||||
docker run -d --name $(CONTAINER_NAME) \
|
docker run -d --name $(CONTAINER_NAME) \
|
||||||
-p $(PORT):$(PORT)/udp \
|
-p $(PORT):$(PORT)/udp \
|
||||||
|
-v $(PWD)/config:/home/steam/config \
|
||||||
|
-e UID=1001 \
|
||||||
|
-e GID=1001 \
|
||||||
--restart unless-stopped \
|
--restart unless-stopped \
|
||||||
$(IMAGE_NAME):latest
|
$(IMAGE_NAME):latest
|
||||||
|
|
||||||
|
|
|
||||||
37
entrypoint.sh
Normal file
37
entrypoint.sh
Normal 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
|
||||||
9
start.sh
9
start.sh
|
|
@ -1,13 +1,14 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
set -e
|
||||||
|
|
||||||
echo "Current user is: $(whoami)"
|
echo "Current user is: $(whoami)"
|
||||||
|
|
||||||
# Install/update SCP:SL server
|
# Install/update SCP:SL server
|
||||||
steamcmd +force_install_dir $SERVER_DIR +login anonymous +app_update 996560 validate +quit
|
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/"
|
INTERNAL_CONFIG_SUBDIR="$CONFIG_DIR/SCP Secret Laboratory/config/"
|
||||||
mkdir -p "$INTERNAL_CONFIG_SUBDIR"
|
mkdir -p "$INTERNAL_CONFIG_SUBDIR"
|
||||||
chmod 755 "$INTERNAL_CONFIG_SUBDIR"
|
|
||||||
|
|
||||||
# Process the internal data template to accept EULA
|
# Process the internal data template to accept EULA
|
||||||
INTERNAL_DATA_TEMPLATE_FILE="$CONFIG_TEMPLATES_DIR/localadmin_internal_data.json.template"
|
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."
|
echo "Successfully created \`localadmin_internal_data.json\` file with EULA acceptance."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Run server directly (no need to su)
|
# Run server
|
||||||
cd $SERVER_DIR && HOME=$INSTALL_DIR ./LocalAdmin $PORT
|
cd $SERVER_DIR && HOME=$INSTALL_DIR ./LocalAdmin $PORT --config $(CONFIG_DIR)
|
||||||
|
|
||||||
sleep infinity
|
sleep infinity
|
||||||
Loading…
Reference in a new issue