mirror of
https://github.com/itzg/docker-minecraft-server.git
synced 2026-09-02 20:27:14 +00:00
feat(minecraft-server): replace environment variables in configs
Add additional setup script that replaces environment variables inside config files. Closes #298
This commit is contained in:
+15
-14
@@ -3,19 +3,19 @@ FROM openjdk:8u171-jre-alpine
|
|||||||
LABEL maintainer "itzg"
|
LABEL maintainer "itzg"
|
||||||
|
|
||||||
RUN apk add --no-cache -U \
|
RUN apk add --no-cache -U \
|
||||||
openssl \
|
openssl \
|
||||||
imagemagick \
|
imagemagick \
|
||||||
lsof \
|
lsof \
|
||||||
su-exec \
|
su-exec \
|
||||||
shadow \
|
shadow \
|
||||||
bash \
|
bash \
|
||||||
curl iputils wget \
|
curl iputils wget \
|
||||||
git \
|
git \
|
||||||
jq \
|
jq \
|
||||||
mysql-client \
|
mysql-client \
|
||||||
tzdata \
|
tzdata \
|
||||||
rsync \
|
rsync \
|
||||||
python python-dev py2-pip
|
python python-dev py2-pip
|
||||||
|
|
||||||
RUN pip install mcstatus
|
RUN pip install mcstatus
|
||||||
|
|
||||||
@@ -71,7 +71,8 @@ ENV UID=1000 GID=1000 \
|
|||||||
JVM_XX_OPTS="-XX:+UseG1GC" MEMORY="1G" \
|
JVM_XX_OPTS="-XX:+UseG1GC" MEMORY="1G" \
|
||||||
TYPE=VANILLA VERSION=LATEST FORGEVERSION=RECOMMENDED SPONGEBRANCH=STABLE SPONGEVERSION= LEVEL=world \
|
TYPE=VANILLA VERSION=LATEST FORGEVERSION=RECOMMENDED SPONGEBRANCH=STABLE SPONGEVERSION= LEVEL=world \
|
||||||
PVP=true DIFFICULTY=easy ENABLE_RCON=true RCON_PORT=25575 RCON_PASSWORD=minecraft \
|
PVP=true DIFFICULTY=easy ENABLE_RCON=true RCON_PORT=25575 RCON_PASSWORD=minecraft \
|
||||||
LEVEL_TYPE=DEFAULT GENERATOR_SETTINGS= WORLD= MODPACK= MODS= SERVER_PORT=25565 ONLINE_MODE=TRUE CONSOLE=true SERVER_NAME="Dedicated Server"
|
LEVEL_TYPE=DEFAULT GENERATOR_SETTINGS= WORLD= MODPACK= MODS= SERVER_PORT=25565 ONLINE_MODE=TRUE CONSOLE=true SERVER_NAME="Dedicated Server" \
|
||||||
|
REPLACE_ENV_VARIABLES="FALSE" ENV_VARIABLE_PREFIX="CFG_"
|
||||||
|
|
||||||
COPY start* /
|
COPY start* /
|
||||||
RUN dos2unix /start* && chmod +x /start*
|
RUN dos2unix /start* && chmod +x /start*
|
||||||
|
|||||||
@@ -132,4 +132,4 @@ else
|
|||||||
echo "server.properties already created, skipping"
|
echo "server.properties already created, skipping"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
exec /start-minecraftFinalSetup $@
|
exec /start-finalSetup05EnvVariables $@
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
if [ "$REPLACE_ENV_VARIABLES" = "TRUE" ]; then
|
||||||
|
echo "Replacing env variables in configs that match the prefix $ENV_VARIABLE_PREFIX..."
|
||||||
|
while IFS='=' read -r name value ; do
|
||||||
|
# check if name of env variable matches the prefix
|
||||||
|
# sanity check environment variables to avoid code injections
|
||||||
|
if [[ "$name" = $ENV_VARIABLE_PREFIX* ]] && [[ $value =~ ^[0-9a-zA-Z_\-:/=?.+]*$ ]] && [[ $name =~ ^[0-9a-zA-Z_\-]*$ ]]; then
|
||||||
|
echo "$name = $value"
|
||||||
|
find /data/ -type f -exec sed -i 's#${'"$name"'}#'"$value"'#g' {} \;
|
||||||
|
fi
|
||||||
|
done < <(env)
|
||||||
|
fi
|
||||||
|
|
||||||
|
exec /start-minecraftFinalSetup $@
|
||||||
Reference in New Issue
Block a user