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:
Michael Reichenbach 2019-03-23 14:12:58 +01:00
parent 1cc902062a
commit b51b19b3c0
3 changed files with 31 additions and 15 deletions

View File

@ -71,7 +71,8 @@ ENV UID=1000 GID=1000 \
JVM_XX_OPTS="-XX:+UseG1GC" MEMORY="1G" \
TYPE=VANILLA VERSION=LATEST FORGEVERSION=RECOMMENDED SPONGEBRANCH=STABLE SPONGEVERSION= LEVEL=world \
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* /
RUN dos2unix /start* && chmod +x /start*

View File

@ -132,4 +132,4 @@ else
echo "server.properties already created, skipping"
fi
exec /start-minecraftFinalSetup $@
exec /start-finalSetup05EnvVariables $@

View File

@ -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 $@