From 86a072e33b55cf4c8facdf1b22e88a2f7d03e589 Mon Sep 17 00:00:00 2001 From: Geoff Bourne Date: Thu, 9 Sep 2021 22:22:52 -0500 Subject: [PATCH 01/12] Added mc-image-helper to interpolate copied files #987 --- Dockerfile | 8 +++++++- start-finalSetupMounts | 37 ++++++++++++++++++++++++++++--------- 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/Dockerfile b/Dockerfile index 617ee7abe02..7275cc4ad09 100644 --- a/Dockerfile +++ b/Dockerfile @@ -61,7 +61,13 @@ RUN easy-add --var os=${TARGETOS} --var arch=${TARGETARCH}${TARGETVARIANT} \ ARG ASCIIFY_VERSION=1.0.1 ADD https://jitpack.io/com/github/itzg/asciify/${ASCIIFY_VERSION}/asciify-${ASCIIFY_VERSION}.jar /usr/share/asciify/asciify.jar -RUN chmod -R a+r /usr/share/asciify + +ARG MC_HELPER_VERSION=1.0.5 +ADD https://jitpack.io/com/github/itzg/mc-image-helper/${MC_HELPER_VERSION}/mc-image-helper-${MC_HELPER_VERSION}.jar /usr/share/mc-image-helper/mc-image-helper.jar + +RUN chmod -R a+r \ + /usr/share/asciify \ + /usr/share/mc-image-helper COPY mcstatus /usr/local/bin diff --git a/start-finalSetupMounts b/start-finalSetupMounts index 2efe364f288..ee4d01ad2c3 100755 --- a/start-finalSetupMounts +++ b/start-finalSetupMounts @@ -3,19 +3,28 @@ . ${SCRIPTS:-/}start-utils : ${PLUGINS_SYNC_UPDATE:=true} +: ${REPLACE_ENV_SUFFIXES:=yml,yaml,txt,cfg,conf,properties,hjson,json,tml,toml} +: ${ENV_VARIABLE_PREFIX:=CFG_} +: ${HELPER_JAR:=/usr/share/mc-image-helper/mc-image-helper.jar} isDebugging && set -x +if isTrue ${PLUGINS_SYNC_UPDATE}; then + updateArg="--skip-newer-in-destination" +fi + if [ -d /plugins ]; then case ${TYPE} in SPIGOT|BUKKIT|PAPER|MAGMA) mkdir -p /data/plugins log "Copying plugins over..." - if isTrue ${PLUGINS_SYNC_UPDATE}; then - updateArg="--update" - fi - # Copy plugins over using rsync to allow deeply nested updates of plugins - rsync -a --out-format="update:%f:Last Modified %M" --prune-empty-dirs $updateArg /plugins /data + java -jar ${HELPER_JAR} \ + --debug=${DEBUG} copy-and-interpolate $updateArg \ + --replace-env-file-suffixes="${REPLACE_ENV_SUFFIXES}" \ + --replace-env-excludes="${REPLACE_ENV_VARIABLES_EXCLUDES}" \ + --replace-env-exclude-paths="${REPLACE_ENV_VARIABLES_EXCLUDE_PATHS}" \ + --replace-env-prefix=${ENV_VARIABLE_PREFIX} \ + /plugins /data/plugins ;; esac fi @@ -25,16 +34,26 @@ fi if [ -d /mods ]; then log "Copying any mods over..." - mkdir -p "${COPY_MODS_DEST}" - rsync -a --out-format="update:%f:Last Modified %M" "${rsyncArgs[@]}" --prune-empty-dirs --update /mods/ "${COPY_MODS_DEST}" + java -jar ${HELPER_JAR} \ + --debug=${DEBUG} copy-and-interpolate $updateArg \ + --replace-env-file-suffixes="${REPLACE_ENV_SUFFIXES}" \ + --replace-env-excludes="${REPLACE_ENV_VARIABLES_EXCLUDES}" \ + --replace-env-exclude-paths="${REPLACE_ENV_VARIABLES_EXCLUDE_PATHS}" \ + --replace-env-prefix=${ENV_VARIABLE_PREFIX} \ + /mods "${COPY_MODS_DEST}" fi : ${COPY_CONFIG_DEST:="/data/config"} if [ -d /config ]; then log "Copying any configs from /config to ${COPY_CONFIG_DEST}" - mkdir -p "${COPY_CONFIG_DEST}" - rsync -a --out-format="update:%f:Last Modified %M" "${rsyncArgs[@]}" --prune-empty-dirs --update /config/ "${COPY_CONFIG_DEST}" + java -jar ${HELPER_JAR} \ + --debug=${DEBUG} copy-and-interpolate $updateArg \ + --replace-env-file-suffixes="${REPLACE_ENV_SUFFIXES}" \ + --replace-env-excludes="${REPLACE_ENV_VARIABLES_EXCLUDES}" \ + --replace-env-exclude-paths="${REPLACE_ENV_VARIABLES_EXCLUDE_PATHS}" \ + --replace-env-prefix=${ENV_VARIABLE_PREFIX} \ + /config "${COPY_CONFIG_DEST}" fi exec ${SCRIPTS:-/}start-finalSetupServerProperties $@ From d0d4281adf5f36c86220db8932a6344479112c15 Mon Sep 17 00:00:00 2001 From: Geoff Bourne Date: Sat, 11 Sep 2021 10:27:16 -0500 Subject: [PATCH 02/12] docs: arranged server properties with more common to top --- README.md | 56 +++++++++++++++++++++++++++---------------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index eec25fa509f..541e71a6b4a 100644 --- a/README.md +++ b/README.md @@ -768,21 +768,25 @@ This will reset any manual configuration of the `server.properties` file, so if you want to make any persistent configuration changes you will need to make sure you have properly set the proper environment variables in your docker run command (described below). -### Server name +### Message of the Day -The server name (e.g. for bungeecord) can be set like: +The message of the day, shown below each server entry in the client UI, can be changed with the `MOTD` environment variable, such as - docker run -d -e SERVER_NAME=MyServer ... + -e MOTD="My Server" -### Server port +If you leave it off, a default is computed from the server type and version, such as -> **WARNING:** only change this value if you know what you're doing. It is only needed when using host networking and it is rare that host networking should be used. Use `-p` port mappings instead. + A Paper Minecraft Server powered by Docker -If you must, the server port can be set like: +That way you can easily differentiate between several servers you may have started. - docker run -d -e SERVER_PORT=25566 ... +The section symbol (§) and other unicode characters are automatically converted to allow [formatting codes](https://minecraft.fandom.com/wiki/Formatting_codes) to be used consistently with all server versions. For example, -**however**, be sure to change your port mapping accordingly and be prepared for some features to break. + -e MOTD="A §l§cMinecraft§r §nserver" + +renders + +![](docs/motd-example.png) ### Difficulty @@ -971,26 +975,6 @@ For example: docker run -d -e MODE=creative ... -### Message of the Day - -The message of the day, shown below each server entry in the client UI, can be changed with the `MOTD` environment variable, such as - - -e MOTD="My Server" - -If you leave it off, a default is computed from the server type and version, such as - - A Paper Minecraft Server powered by Docker - -That way you can easily differentiate between several servers you may have started. - -The section symbol (§) and other unicode characters are automatically converted to allow [formatting codes](https://minecraft.fandom.com/wiki/Formatting_codes) to be used consistently with all server versions. For example, - - -e MOTD="A §l§cMinecraft§r §nserver" - -renders - -![](docs/motd-example.png) - ### PVP Mode By default, servers are created with player-vs-player (PVP) mode enabled. You can disable this with the `PVP` @@ -1058,6 +1042,22 @@ Allows users to use flight on your server while in Survival mode, if they have a -e ALLOW_FLIGHT=TRUE|FALSE +### Server name + +The server name (e.g. for bungeecord) can be set like: + + docker run -d -e SERVER_NAME=MyServer ... + +### Server port + +> **WARNING:** only change this value if you know what you're doing. It is only needed when using host networking and it is rare that host networking should be used. Use `-p` port mappings instead. + +If you must, the server port can be set like: + + docker run -d -e SERVER_PORT=25566 ... + +**however**, be sure to change your port mapping accordingly and be prepared for some features to break. + ### Other server property mappings | Environment Variable | Server Property | From dea751294c1d4553854b31267af1bfa963cf5124 Mon Sep 17 00:00:00 2001 From: Geoff Bourne Date: Sat, 11 Sep 2021 11:01:43 -0500 Subject: [PATCH 03/12] Added REPLACE_ENV_DURING_SYNC and updated README #987 --- Dockerfile | 6 +----- README.md | 19 +++++-------------- start-finalSetupEnvVariables | 3 ++- start-finalSetupMounts | 21 +++++++++++++++------ start-finalSetupServerProperties | 2 +- start-utils | 10 ++++++++++ 6 files changed, 34 insertions(+), 27 deletions(-) diff --git a/Dockerfile b/Dockerfile index 7275cc4ad09..873ea7c1b89 100644 --- a/Dockerfile +++ b/Dockerfile @@ -59,14 +59,10 @@ RUN easy-add --var os=${TARGETOS} --var arch=${TARGETARCH}${TARGETVARIANT} \ --var version=0.1.1 --var app=maven-metadata-release --file {{.app}} \ --from https://github.com/itzg/{{.app}}/releases/download/{{.version}}/{{.app}}_{{.version}}_{{.os}}_{{.arch}}.tar.gz -ARG ASCIIFY_VERSION=1.0.1 -ADD https://jitpack.io/com/github/itzg/asciify/${ASCIIFY_VERSION}/asciify-${ASCIIFY_VERSION}.jar /usr/share/asciify/asciify.jar - -ARG MC_HELPER_VERSION=1.0.5 +ARG MC_HELPER_VERSION=1.1.1 ADD https://jitpack.io/com/github/itzg/mc-image-helper/${MC_HELPER_VERSION}/mc-image-helper-${MC_HELPER_VERSION}.jar /usr/share/mc-image-helper/mc-image-helper.jar RUN chmod -R a+r \ - /usr/share/asciify \ /usr/share/mc-image-helper COPY mcstatus /usr/local/bin diff --git a/README.md b/README.md index 541e71a6b4a..0a6825d806a 100644 --- a/README.md +++ b/README.md @@ -1090,24 +1090,15 @@ in your config files after the container starts. For those cases there is the option to replace defined variables inside your configs with environment variables defined at container runtime. -If you set the enviroment variable `REPLACE_ENV_VARIABLES` to `TRUE` the startup script -will go thru all files inside your `/data` volume and replace variables that match your -defined environment variables. Variables that you want to replace need to be wrapped -inside `${YOUR_VARIABLE}` curly brackets and prefixed with a dollar sign. This is the regular -syntax for enviromment variables inside strings or config files. +When the environment variable `REPLACE_ENV_IN_PLACE` is set to `TRUE`, the startup script will go through all files inside the container's `/data` path and replace variables that match the container's environment variables. Variables can instead (or in addition to) be replaced in files sync'ed from `/plugins`, `/mods`, and `/config` by setting `REPLACE_ENV_DURING_SYNC` to `TRUE`. -Optionally you can also define a prefix to only match predefined environment variables. +Variables that you want to replace need to be declared inside curly brackets and prefixed with a dollar sign, such as `${CFG_YOUR_VARIABLE}`, which is same as many scripting languages. -`ENV_VARIABLE_PREFIX="CFG_"` <-- this is the default prefix +You can also define a prefix to only match predefined environment variables, which defaults to `CFG_`. -If you want use file for value (like when use secrets) you can add suffix `_FILE` to your variable name (in run command). +`ENV_VARIABLE_PREFIX="CFG_"` -There are some limitations to what characters you can use. - -| Type | Allowed Characters | -| ----- | ------------------- | -| Name | `0-9a-zA-Z_-` | -| Value | `0-9a-zA-Z_-:/=?.+` | +If you want to use a file for value (like when use secrets) you can add suffix `_FILE` to your variable name. Variables will be replaced in files with the following extensions: `.yml`, `.yaml`, `.txt`, `.cfg`, `.conf`, `.properties`. diff --git a/start-finalSetupEnvVariables b/start-finalSetupEnvVariables index dc0fdd1c0ec..6d36f644256 100644 --- a/start-finalSetupEnvVariables +++ b/start-finalSetupEnvVariables @@ -3,8 +3,9 @@ . ${SCRIPTS:-/}start-utils : ${ENV_VARIABLE_PREFIX:=CFG_} +: ${REPLACE_ENV_IN_PLACE:=${REPLACE_ENV_VARIABLES:-false}} -if isTrue "${REPLACE_ENV_VARIABLES}"; then +if isTrue "${REPLACE_ENV_IN_PLACE}"; then log "Replacing env variables in configs that match the prefix $ENV_VARIABLE_PREFIX ..." # File excludes diff --git a/start-finalSetupMounts b/start-finalSetupMounts index ee4d01ad2c3..afa2c41f077 100755 --- a/start-finalSetupMounts +++ b/start-finalSetupMounts @@ -4,22 +4,31 @@ : ${PLUGINS_SYNC_UPDATE:=true} : ${REPLACE_ENV_SUFFIXES:=yml,yaml,txt,cfg,conf,properties,hjson,json,tml,toml} +: ${REPLACE_ENV_DURING_SYNC:=false} : ${ENV_VARIABLE_PREFIX:=CFG_} : ${HELPER_JAR:=/usr/share/mc-image-helper/mc-image-helper.jar} +: ${DEBUG:=false} +set -e isDebugging && set -x if isTrue ${PLUGINS_SYNC_UPDATE}; then updateArg="--skip-newer-in-destination" fi +if isTrue ${REPLACE_ENV_DURING_SYNC}; then + subcommand=sync-and-interpolate +else + subcommand=sync +fi + if [ -d /plugins ]; then case ${TYPE} in SPIGOT|BUKKIT|PAPER|MAGMA) mkdir -p /data/plugins log "Copying plugins over..." - java -jar ${HELPER_JAR} \ - --debug=${DEBUG} copy-and-interpolate $updateArg \ + mc_helper \ + --debug=${DEBUG} ${subcommand} $updateArg \ --replace-env-file-suffixes="${REPLACE_ENV_SUFFIXES}" \ --replace-env-excludes="${REPLACE_ENV_VARIABLES_EXCLUDES}" \ --replace-env-exclude-paths="${REPLACE_ENV_VARIABLES_EXCLUDE_PATHS}" \ @@ -34,8 +43,8 @@ fi if [ -d /mods ]; then log "Copying any mods over..." - java -jar ${HELPER_JAR} \ - --debug=${DEBUG} copy-and-interpolate $updateArg \ + mc_helper \ + --debug=${DEBUG} ${subcommand} $updateArg \ --replace-env-file-suffixes="${REPLACE_ENV_SUFFIXES}" \ --replace-env-excludes="${REPLACE_ENV_VARIABLES_EXCLUDES}" \ --replace-env-exclude-paths="${REPLACE_ENV_VARIABLES_EXCLUDE_PATHS}" \ @@ -47,8 +56,8 @@ fi if [ -d /config ]; then log "Copying any configs from /config to ${COPY_CONFIG_DEST}" - java -jar ${HELPER_JAR} \ - --debug=${DEBUG} copy-and-interpolate $updateArg \ + mc_helper \ + --debug=${DEBUG} ${subcommand} $updateArg \ --replace-env-file-suffixes="${REPLACE_ENV_SUFFIXES}" \ --replace-env-excludes="${REPLACE_ENV_VARIABLES_EXCLUDES}" \ --replace-env-exclude-paths="${REPLACE_ENV_VARIABLES_EXCLUDE_PATHS}" \ diff --git a/start-finalSetupServerProperties b/start-finalSetupServerProperties index 79a45ec66c2..85f024d1fc5 100644 --- a/start-finalSetupServerProperties +++ b/start-finalSetupServerProperties @@ -56,7 +56,7 @@ function customizeServerProps { setServerProp "server-name" "$SERVER_NAME" setServerProp "server-ip" "$SERVER_IP" setServerProp "server-port" "$SERVER_PORT" - setServerProp "motd" "$(echo $MOTD | java -jar /usr/share/asciify/asciify.jar)" + setServerProp "motd" "$(echo $MOTD | asciify)" setServerProp "allow-nether" "$ALLOW_NETHER" setServerProp "announce-player-achievements" "$ANNOUNCE_PLAYER_ACHIEVEMENTS" setServerProp "enable-command-block" "$ENABLE_COMMAND_BLOCK" diff --git a/start-utils b/start-utils index dd5051b00ee..0a2a9134107 100644 --- a/start-utils +++ b/start-utils @@ -180,3 +180,13 @@ function removeOldMods { find "$1" -mindepth 1 -maxdepth ${REMOVE_OLD_MODS_DEPTH:-16} -wholename "${REMOVE_OLD_MODS_INCLUDE:-*}" -not -wholename "${REMOVE_OLD_MODS_EXCLUDE:-}" -delete fi } + +: ${HELPER_JAR:=/usr/share/mc-image-helper/mc-image-helper.jar} + +function mc_helper() { + java -jar ${HELPER_JAR} "$@" +} + +function asciify() { + java -jar ${HELPER_JAR} asciify "$@" +} \ No newline at end of file From e2c122ea47ff18b2622b99f8107c66bea76d5bc2 Mon Sep 17 00:00:00 2001 From: Geoff Bourne Date: Sun, 12 Sep 2021 10:06:42 -0500 Subject: [PATCH 04/12] misc: better naming of setup scripts --- DEVELOPMENT.md | 2 +- start-deployCF | 5 ++--- start-deployCatserver | 2 +- start-deployCustom | 3 +-- start-deployFTBA | 3 +-- start-deployFabric | 3 +-- start-deployForge | 3 +-- start-deployLimbo | 3 +-- start-deployMagma | 3 +-- start-deployMohist | 3 +-- start-deploySpongeVanilla | 3 +-- start-deployVanilla | 3 +-- start-deployYatopia | 3 +-- start-minecraftFinalSetup => start-finalExec | 0 start-finalSetupEnvVariables => start-setupEnvVariables | 2 +- start-finalSetupModconfig => start-setupModconfig | 2 +- start-finalSetupModpack => start-setupModpack | 2 +- start-finalSetupMounts => start-setupMounts | 2 +- ...finalSetupServerProperties => start-setupServerProperties | 2 +- start-finalSetupWorld => start-setupWorld | 2 +- start-spiget | 3 +-- start-validateCurseInstance | 3 +-- 22 files changed, 22 insertions(+), 35 deletions(-) rename start-minecraftFinalSetup => start-finalExec (100%) rename start-finalSetupEnvVariables => start-setupEnvVariables (97%) rename start-finalSetupModconfig => start-setupModconfig (94%) rename start-finalSetupModpack => start-setupModpack (99%) rename start-finalSetupMounts => start-setupMounts (97%) mode change 100755 => 100644 rename start-finalSetupServerProperties => start-setupServerProperties (99%) rename start-finalSetupWorld => start-setupWorld (98%) diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index 55bea272c20..fadc6141d9b 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -3,7 +3,7 @@ Adding a new server `TYPE` can vary due to the complexity of obtaining and configuring each type; however, the addition of any server type includes at least the following steps: 1. Copy an existing "start-deploy*" script, such as [start-deployMohist](start-deployMohist) and rename it accordingly making sure to retain the "start-deploy" prefix -2. Modify the type-specific behavior between the "start-utils" preamble and the hand-off to `start-finalSetupWorld` at the end of the script +2. Modify the type-specific behavior between the "start-utils" preamble and the hand-off to `start-setupWorld` at the end of the script 3. Develop and test the changes using the [iterative process described below](#iterative-script-development) 4. Add a case-entry to the `case "${TYPE^^}"` in [start-configuration](start-configuration) 5. Add a section to the [README](README.md). It is recommended to copy-modify an existing section to retain a similar wording and level of detail diff --git a/start-deployCF b/start-deployCF index 345f4132dc6..d821636a74a 100644 --- a/start-deployCF +++ b/start-deployCF @@ -101,7 +101,7 @@ if ! isTrue ${USE_MODPACK_START_SCRIPT:-true}; then export FTB_DIR=$(dirname "${SERVER}") - exec ${SCRIPTS:-/}start-finalSetupWorld $@ + exec ${SCRIPTS:-/}start-setupWorld $@ fi entryScriptExpr=" @@ -236,5 +236,4 @@ elif [ -e "${FTB_DIR}/Install.sh" ]; then popd fi -# Continue to Final Setup -exec ${SCRIPTS:-/}start-finalSetupWorld $@ +exec ${SCRIPTS:-/}start-setupWorld $@ diff --git a/start-deployCatserver b/start-deployCatserver index 093769ec3a8..32ad7d72e11 100644 --- a/start-deployCatserver +++ b/start-deployCatserver @@ -29,4 +29,4 @@ fi export SKIP_LOG4J_CONFIG=true # Continue to Final Setup -exec ${SCRIPTS:-/}start-finalSetupWorld "$@" +exec ${SCRIPTS:-/}start-setupWorld "$@" diff --git a/start-deployCustom b/start-deployCustom index 156ee9ba848..a51e7c72907 100644 --- a/start-deployCustom +++ b/start-deployCustom @@ -32,5 +32,4 @@ fi export SKIP_LOG4J_CONFIG=true -# Continue to Final Setup -exec ${SCRIPTS:-/}start-finalSetupWorld $@ +exec ${SCRIPTS:-/}start-setupWorld $@ diff --git a/start-deployFTBA b/start-deployFTBA index 91318f382b3..f3eeaca408a 100644 --- a/start-deployFTBA +++ b/start-deployFTBA @@ -79,5 +79,4 @@ if ! [ -v SERVER ]; then exit 2 fi -# Continue to Final Setup -exec ${SCRIPTS:-/}start-finalSetupWorld $@ +exec ${SCRIPTS:-/}start-setupWorld $@ diff --git a/start-deployFabric b/start-deployFabric index d8d9d6be679..cb178bb2420 100644 --- a/start-deployFabric +++ b/start-deployFabric @@ -60,5 +60,4 @@ if [[ ! -e ${SERVER} ]]; then mv fabric-server-launch.jar ${SERVER} fi -# Continue to Final Setup -exec ${SCRIPTS:-/}start-finalSetupWorld $@ +exec ${SCRIPTS:-/}start-setupWorld $@ diff --git a/start-deployForge b/start-deployForge index d34f1dead27..e78e2c4f3a4 100644 --- a/start-deployForge +++ b/start-deployForge @@ -118,5 +118,4 @@ else export SERVER=$(cat $installMarker) fi -# Continue to Final Setup -exec ${SCRIPTS:-/}start-finalSetupWorld $@ +exec ${SCRIPTS:-/}start-setupWorld $@ diff --git a/start-deployLimbo b/start-deployLimbo index 5abb5bced7e..3c4e086fd98 100644 --- a/start-deployLimbo +++ b/start-deployLimbo @@ -60,5 +60,4 @@ export LEVEL export SKIP_LOG4J_CONFIG=true -# Continue to Final Setup -exec ${SCRIPTS:-/}start-finalSetupWorld $@ +exec ${SCRIPTS:-/}start-setupWorld $@ diff --git a/start-deployMagma b/start-deployMagma index f285af1772d..bf54a1e4021 100644 --- a/start-deployMagma +++ b/start-deployMagma @@ -89,5 +89,4 @@ else fi fi -# Continue to Final Setup -exec ${SCRIPTS:-/}start-finalSetupWorld $@ +exec ${SCRIPTS:-/}start-setupWorld $@ diff --git a/start-deployMohist b/start-deployMohist index 21267eb8be2..4128af14460 100644 --- a/start-deployMohist +++ b/start-deployMohist @@ -40,5 +40,4 @@ fi export SKIP_LOG4J_CONFIG=true -# Continue to Final Setup -exec ${SCRIPTS:-/}start-finalSetupWorld "$@" +exec ${SCRIPTS:-/}start-setupWorld "$@" diff --git a/start-deploySpongeVanilla b/start-deploySpongeVanilla index 8c80b4d3383..b296e7f3ef3 100644 --- a/start-deploySpongeVanilla +++ b/start-deploySpongeVanilla @@ -37,5 +37,4 @@ if [ ! -e $SERVER ] || [ -n "$FORCE_REDOWNLOAD" ]; then curl -sSL -o $SERVER https://repo.spongepowered.org/maven/org/spongepowered/$TYPE/$SPONGEVERSION/$SERVER fi -# Continue to Final Setup -exec ${SCRIPTS:-/}start-finalSetupWorld $@ +exec ${SCRIPTS:-/}start-setupWorld $@ diff --git a/start-deployVanilla b/start-deployVanilla index c7c9d05f66c..93582889ca6 100644 --- a/start-deployVanilla +++ b/start-deployVanilla @@ -45,5 +45,4 @@ fi isDebugging && ls -l -# Continue to Final Setup -exec ${SCRIPTS:-/}start-finalSetupWorld $@ +exec ${SCRIPTS:-/}start-setupWorld $@ diff --git a/start-deployYatopia b/start-deployYatopia index 39f08cf3340..890b9b30098 100644 --- a/start-deployYatopia +++ b/start-deployYatopia @@ -26,5 +26,4 @@ fi export TYPE=SPIGOT export SKIP_LOG4J_CONFIG=true -# Continue to Final Setup -exec ${SCRIPTS:-/}start-finalSetupWorld $@ +exec ${SCRIPTS:-/}start-setupWorld $@ diff --git a/start-minecraftFinalSetup b/start-finalExec similarity index 100% rename from start-minecraftFinalSetup rename to start-finalExec diff --git a/start-finalSetupEnvVariables b/start-setupEnvVariables similarity index 97% rename from start-finalSetupEnvVariables rename to start-setupEnvVariables index 6d36f644256..86ca6e29319 100644 --- a/start-finalSetupEnvVariables +++ b/start-setupEnvVariables @@ -49,4 +49,4 @@ if isTrue "${REPLACE_ENV_IN_PLACE}"; then done fi -exec ${SCRIPTS:-/}start-minecraftFinalSetup $@ +exec ${SCRIPTS:-/}start-finalExec $@ diff --git a/start-finalSetupModconfig b/start-setupModconfig similarity index 94% rename from start-finalSetupModconfig rename to start-setupModconfig index c695cc7ef76..82d4c1b5fca 100644 --- a/start-finalSetupModconfig +++ b/start-setupModconfig @@ -24,4 +24,4 @@ case "X$MODCONFIG" in esac fi -exec ${SCRIPTS:-/}start-finalSetupMounts $@ +exec ${SCRIPTS:-/}start-setupMounts $@ diff --git a/start-finalSetupModpack b/start-setupModpack similarity index 99% rename from start-finalSetupModpack rename to start-setupModpack index 855233e2ea1..a037b8f2ff7 100644 --- a/start-finalSetupModpack +++ b/start-setupModpack @@ -188,4 +188,4 @@ if [[ "${GENERIC_PACK}" ]]; then fi fi -exec ${SCRIPTS:-/}start-finalSetupModconfig $@ +exec ${SCRIPTS:-/}start-setupModconfig $@ diff --git a/start-finalSetupMounts b/start-setupMounts old mode 100755 new mode 100644 similarity index 97% rename from start-finalSetupMounts rename to start-setupMounts index afa2c41f077..466d91b9d0f --- a/start-finalSetupMounts +++ b/start-setupMounts @@ -65,4 +65,4 @@ if [ -d /config ]; then /config "${COPY_CONFIG_DEST}" fi -exec ${SCRIPTS:-/}start-finalSetupServerProperties $@ +exec ${SCRIPTS:-/}start-setupServerProperties $@ diff --git a/start-finalSetupServerProperties b/start-setupServerProperties similarity index 99% rename from start-finalSetupServerProperties rename to start-setupServerProperties index 85f024d1fc5..7234e5f9dd8 100644 --- a/start-finalSetupServerProperties +++ b/start-setupServerProperties @@ -217,4 +217,4 @@ if isDebugging; then cat "${SERVER_PROPERTIES}" fi -exec ${SCRIPTS:-/}start-finalSetupEnvVariables $@ +exec ${SCRIPTS:-/}start-setupEnvVariables $@ diff --git a/start-finalSetupWorld b/start-setupWorld similarity index 98% rename from start-finalSetupWorld rename to start-setupWorld index e8ac56cc471..dee5055b08e 100644 --- a/start-finalSetupWorld +++ b/start-setupWorld @@ -71,4 +71,4 @@ if [[ "$WORLD" ]] && ( isTrue "${FORCE_WORLD_COPY}" || [ ! -d "$worldDest" ] ); fi fi -exec ${SCRIPTS:-/}start-finalSetupModpack $@ +exec ${SCRIPTS:-/}start-setupModpack $@ diff --git a/start-spiget b/start-spiget index c7e451ff941..451312ab51d 100644 --- a/start-spiget +++ b/start-spiget @@ -101,5 +101,4 @@ if [[ ${SPIGET_RESOURCES} ]]; then done fi -# Continue to Final Setup -exec ${SCRIPTS:-/}start-finalSetupWorld $@ +exec ${SCRIPTS:-/}start-setupWorld $@ diff --git a/start-validateCurseInstance b/start-validateCurseInstance index f3563990dbe..33024d57aa1 100755 --- a/start-validateCurseInstance +++ b/start-validateCurseInstance @@ -14,5 +14,4 @@ fi log "Resolved CURSE_INSTANCE_JSON as ${CURSE_INSTANCE_JSON}" -# Continue to Final Setup -exec ${SCRIPTS:-/}start-finalSetupWorld "$@" +exec ${SCRIPTS:-/}start-setupWorld "$@" From 9ef2dbbc3ba6714a821d6235b3f7d3f5f377331c Mon Sep 17 00:00:00 2001 From: Geoff Bourne Date: Sun, 12 Sep 2021 10:08:07 -0500 Subject: [PATCH 05/12] Defaulted REPLACE_ENV_DURING_SYNC to true --- README.md | 2 +- start-setupMounts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0a6825d806a..67f4f5e94c0 100644 --- a/README.md +++ b/README.md @@ -1090,7 +1090,7 @@ in your config files after the container starts. For those cases there is the option to replace defined variables inside your configs with environment variables defined at container runtime. -When the environment variable `REPLACE_ENV_IN_PLACE` is set to `TRUE`, the startup script will go through all files inside the container's `/data` path and replace variables that match the container's environment variables. Variables can instead (or in addition to) be replaced in files sync'ed from `/plugins`, `/mods`, and `/config` by setting `REPLACE_ENV_DURING_SYNC` to `TRUE`. +When the environment variable `REPLACE_ENV_IN_PLACE` is set to `true` (the default), the startup script will go through all files inside the container's `/data` path and replace variables that match the container's environment variables. Variables can instead (or in addition to) be replaced in files sync'ed from `/plugins`, `/mods`, and `/config` by setting `REPLACE_ENV_DURING_SYNC` to `true` (defaults to `false`). Variables that you want to replace need to be declared inside curly brackets and prefixed with a dollar sign, such as `${CFG_YOUR_VARIABLE}`, which is same as many scripting languages. diff --git a/start-setupMounts b/start-setupMounts index 466d91b9d0f..58659cad7ec 100644 --- a/start-setupMounts +++ b/start-setupMounts @@ -4,7 +4,7 @@ : ${PLUGINS_SYNC_UPDATE:=true} : ${REPLACE_ENV_SUFFIXES:=yml,yaml,txt,cfg,conf,properties,hjson,json,tml,toml} -: ${REPLACE_ENV_DURING_SYNC:=false} +: ${REPLACE_ENV_DURING_SYNC:=true} : ${ENV_VARIABLE_PREFIX:=CFG_} : ${HELPER_JAR:=/usr/share/mc-image-helper/mc-image-helper.jar} : ${DEBUG:=false} From 631d8676d6b0bd8e6a80b2a72fdbbce7d0b53b6e Mon Sep 17 00:00:00 2001 From: Geoff Bourne Date: Sun, 12 Sep 2021 10:10:36 -0500 Subject: [PATCH 06/12] Upgraded mc-image-helper to 1.1.2 to detect char encoding --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 873ea7c1b89..07fd1ddc30d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -59,7 +59,7 @@ RUN easy-add --var os=${TARGETOS} --var arch=${TARGETARCH}${TARGETVARIANT} \ --var version=0.1.1 --var app=maven-metadata-release --file {{.app}} \ --from https://github.com/itzg/{{.app}}/releases/download/{{.version}}/{{.app}}_{{.version}}_{{.os}}_{{.arch}}.tar.gz -ARG MC_HELPER_VERSION=1.1.1 +ARG MC_HELPER_VERSION=1.1.2 ADD https://jitpack.io/com/github/itzg/mc-image-helper/${MC_HELPER_VERSION}/mc-image-helper-${MC_HELPER_VERSION}.jar /usr/share/mc-image-helper/mc-image-helper.jar RUN chmod -R a+r \ From a08ab6e506a72ee7103f0c9ae13db8ccc422e237 Mon Sep 17 00:00:00 2001 From: Geoff Bourne Date: Sun, 12 Sep 2021 20:48:57 -0500 Subject: [PATCH 07/12] ci: Upgraded mc-image-helper to 1.1.5 --- Dockerfile | 9 ++++----- start-setupMounts | 7 +++---- start-setupServerProperties | 2 +- start-utils | 10 ---------- 4 files changed, 8 insertions(+), 20 deletions(-) diff --git a/Dockerfile b/Dockerfile index 07fd1ddc30d..f35411f9eec 100644 --- a/Dockerfile +++ b/Dockerfile @@ -59,11 +59,10 @@ RUN easy-add --var os=${TARGETOS} --var arch=${TARGETARCH}${TARGETVARIANT} \ --var version=0.1.1 --var app=maven-metadata-release --file {{.app}} \ --from https://github.com/itzg/{{.app}}/releases/download/{{.version}}/{{.app}}_{{.version}}_{{.os}}_{{.arch}}.tar.gz -ARG MC_HELPER_VERSION=1.1.2 -ADD https://jitpack.io/com/github/itzg/mc-image-helper/${MC_HELPER_VERSION}/mc-image-helper-${MC_HELPER_VERSION}.jar /usr/share/mc-image-helper/mc-image-helper.jar - -RUN chmod -R a+r \ - /usr/share/mc-image-helper +ARG MC_HELPER_VERSION=1.1.5 +RUN curl -fsSL https://github.com/itzg/mc-image-helper/releases/download/v${MC_HELPER_VERSION}/mc-image-helper-${MC_HELPER_VERSION}.tgz \ + | tar -C /usr/share -zxf - \ + && ln -s /usr/share/mc-image-helper-${MC_HELPER_VERSION}/bin/mc-image-helper /usr/bin COPY mcstatus /usr/local/bin diff --git a/start-setupMounts b/start-setupMounts index 58659cad7ec..e65e29ccca2 100644 --- a/start-setupMounts +++ b/start-setupMounts @@ -6,7 +6,6 @@ : ${REPLACE_ENV_SUFFIXES:=yml,yaml,txt,cfg,conf,properties,hjson,json,tml,toml} : ${REPLACE_ENV_DURING_SYNC:=true} : ${ENV_VARIABLE_PREFIX:=CFG_} -: ${HELPER_JAR:=/usr/share/mc-image-helper/mc-image-helper.jar} : ${DEBUG:=false} set -e @@ -27,7 +26,7 @@ if [ -d /plugins ]; then SPIGOT|BUKKIT|PAPER|MAGMA) mkdir -p /data/plugins log "Copying plugins over..." - mc_helper \ + mc-image-helper \ --debug=${DEBUG} ${subcommand} $updateArg \ --replace-env-file-suffixes="${REPLACE_ENV_SUFFIXES}" \ --replace-env-excludes="${REPLACE_ENV_VARIABLES_EXCLUDES}" \ @@ -43,7 +42,7 @@ fi if [ -d /mods ]; then log "Copying any mods over..." - mc_helper \ + mc-image-helper \ --debug=${DEBUG} ${subcommand} $updateArg \ --replace-env-file-suffixes="${REPLACE_ENV_SUFFIXES}" \ --replace-env-excludes="${REPLACE_ENV_VARIABLES_EXCLUDES}" \ @@ -56,7 +55,7 @@ fi if [ -d /config ]; then log "Copying any configs from /config to ${COPY_CONFIG_DEST}" - mc_helper \ + mc-image-helper \ --debug=${DEBUG} ${subcommand} $updateArg \ --replace-env-file-suffixes="${REPLACE_ENV_SUFFIXES}" \ --replace-env-excludes="${REPLACE_ENV_VARIABLES_EXCLUDES}" \ diff --git a/start-setupServerProperties b/start-setupServerProperties index 7234e5f9dd8..b1e4361b8d7 100644 --- a/start-setupServerProperties +++ b/start-setupServerProperties @@ -56,7 +56,7 @@ function customizeServerProps { setServerProp "server-name" "$SERVER_NAME" setServerProp "server-ip" "$SERVER_IP" setServerProp "server-port" "$SERVER_PORT" - setServerProp "motd" "$(echo $MOTD | asciify)" + setServerProp "motd" "$(echo $MOTD | mc-image-helper asciify)" setServerProp "allow-nether" "$ALLOW_NETHER" setServerProp "announce-player-achievements" "$ANNOUNCE_PLAYER_ACHIEVEMENTS" setServerProp "enable-command-block" "$ENABLE_COMMAND_BLOCK" diff --git a/start-utils b/start-utils index 0a2a9134107..dd5051b00ee 100644 --- a/start-utils +++ b/start-utils @@ -180,13 +180,3 @@ function removeOldMods { find "$1" -mindepth 1 -maxdepth ${REMOVE_OLD_MODS_DEPTH:-16} -wholename "${REMOVE_OLD_MODS_INCLUDE:-*}" -not -wholename "${REMOVE_OLD_MODS_EXCLUDE:-}" -delete fi } - -: ${HELPER_JAR:=/usr/share/mc-image-helper/mc-image-helper.jar} - -function mc_helper() { - java -jar ${HELPER_JAR} "$@" -} - -function asciify() { - java -jar ${HELPER_JAR} asciify "$@" -} \ No newline at end of file From 32c4f24ec32044a0aa474257e54199c6cc5ae994 Mon Sep 17 00:00:00 2001 From: Geoff Bourne Date: Mon, 13 Sep 2021 17:48:50 -0500 Subject: [PATCH 08/12] Improved naming of SYNC_SKIP_NEWER_IN_DESTINATION and REPLACE_ENV_VARIABLE_PREFIX --- README.md | 12 ++++-------- start-setupEnvVariables | 6 +++--- start-setupMounts | 10 +++++----- 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 67f4f5e94c0..5a0bed5ab36 100644 --- a/README.md +++ b/README.md @@ -656,20 +656,18 @@ then you apply a workaround by adding this to the run invocation: There are optional volume paths that can be attached to supply content to be copied into the data area: `/plugins` -: contents are copied into `/data/plugins` for Bukkit related server types. Set `PLUGINS_SYNC_UPDATE=false` if you want files from `/plugins` to take precedence over newer files in `/data/plugins`. +: contents are copied into `/data/plugins` for Bukkit related server types. Set `SYNC_SKIP_NEWER_IN_DESTINATION=false` if you want files from `/plugins` to take precedence over newer files in `/data/plugins`. `/mods` -: contents are copied into `/data/mods` for Forge related server types +: contents are copied into `/data/mods` for Forge related server types. The destination can be changed by setting `COPY_MODS_DEST`. `/config` -: contents are copied into `/data/config` by default, but can be changed with `COPY_CONFIG_DEST` +: contents are copied into `/data/config` by default, but can be changed with `COPY_CONFIG_DEST`. For example, `-v ./config:/config -e COPY_CONFIG_DEST=/data` will allow you to copy over files like `bukkit.yml` and so on directly into the server directory. Set `SYNC_SKIP_NEWER_IN_DESTINATION=false` if you want files from `/config` to take precedence over newer files in `/data/config`. If you want old mods/plugins to be removed before the content is brought over from those attach points, then add `-e REMOVE_OLD_MODS=TRUE`. You can fine tune the removal process by specifying the `REMOVE_OLD_MODS_INCLUDE` and `REMOVE_OLD_MODS_EXCLUDE` variables. By default, everything will be removed. You can also specify the `REMOVE_OLD_MODS_DEPTH` (default is 16) variable to only delete files up to a certain level. For example: `-e REMOVE_OLD_MODS=TRUE -e REMOVE_OLD_MODS_INCLUDE="*.jar" -e REMOVE_OLD_MODS_DEPTH=1` will remove all old jar files that are directly inside the `plugins/` or `mods/` directory. -You can specify the destination of the files that are copied from `/mods` and `/config` by setting the `COPY_MODS_DEST` and `COPY_CONFIG_DEST`, where the default is `/data/mods` and `/data/config`. For example, `-v ./config:/config -e COPY_CONFIG_DEST=/data` will allow you to copy over files like `bukkit.yml` and so on directly into the server directory. - These paths work well if you want to have a common set of modules in a separate location, but still have multiple worlds with different server requirements in either persistent volumes or a downloadable archive. > For more flexibility with mods/plugins preparation, you can declare directories to use in [the `MODS` variable](#downloadable-modplugin-pack-for-forge-bukkit-and-spigot-servers) @@ -1094,9 +1092,7 @@ When the environment variable `REPLACE_ENV_IN_PLACE` is set to `true` (the defau Variables that you want to replace need to be declared inside curly brackets and prefixed with a dollar sign, such as `${CFG_YOUR_VARIABLE}`, which is same as many scripting languages. -You can also define a prefix to only match predefined environment variables, which defaults to `CFG_`. - -`ENV_VARIABLE_PREFIX="CFG_"` +You can also change `REPLACE_ENV_VARIABLE_PREFIX`, which defaults to "CFG_", to limit which environment variables are allowed to be used. For example, with "CFG_" as the prefix, the variable `${CFG_DB_HOST}` would be subsituted, but not `${DB_HOST}`. If you want to use a file for value (like when use secrets) you can add suffix `_FILE` to your variable name. diff --git a/start-setupEnvVariables b/start-setupEnvVariables index 86ca6e29319..1d6366696e5 100644 --- a/start-setupEnvVariables +++ b/start-setupEnvVariables @@ -2,11 +2,11 @@ . ${SCRIPTS:-/}start-utils -: ${ENV_VARIABLE_PREFIX:=CFG_} +: ${REPLACE_ENV_VARIABLE_PREFIX:=${ENV_VARIABLE_PREFIX:-CFG_}} : ${REPLACE_ENV_IN_PLACE:=${REPLACE_ENV_VARIABLES:-false}} if isTrue "${REPLACE_ENV_IN_PLACE}"; then - log "Replacing env variables in configs that match the prefix $ENV_VARIABLE_PREFIX ..." + log "Replacing env variables in configs that match the prefix $REPLACE_ENV_VARIABLE_PREFIX ..." # File excludes fileExcludes= @@ -23,7 +23,7 @@ if isTrue "${REPLACE_ENV_IN_PLACE}"; then isDebugging && echo "Using find file exclusions: $fileExcludes" isDebugging && echo "Using find directory exclusions: $dirExcludes" - for name in $(compgen -v $ENV_VARIABLE_PREFIX); do + for name in $(compgen -v $REPLACE_ENV_VARIABLE_PREFIX); do # check if name of env variable matches the prefix # sanity check environment variables to avoid code injections # Read content from file environment diff --git a/start-setupMounts b/start-setupMounts index e65e29ccca2..ec8cd85fd5b 100644 --- a/start-setupMounts +++ b/start-setupMounts @@ -2,10 +2,10 @@ . ${SCRIPTS:-/}start-utils -: ${PLUGINS_SYNC_UPDATE:=true} +: ${SYNC_SKIP_NEWER_IN_DESTINATION:=${PLUGINS_SYNC_UPDATE:-true}} : ${REPLACE_ENV_SUFFIXES:=yml,yaml,txt,cfg,conf,properties,hjson,json,tml,toml} : ${REPLACE_ENV_DURING_SYNC:=true} -: ${ENV_VARIABLE_PREFIX:=CFG_} +: ${REPLACE_ENV_VARIABLE_PREFIX:=${ENV_VARIABLE_PREFIX:-CFG_}} : ${DEBUG:=false} set -e @@ -31,7 +31,7 @@ if [ -d /plugins ]; then --replace-env-file-suffixes="${REPLACE_ENV_SUFFIXES}" \ --replace-env-excludes="${REPLACE_ENV_VARIABLES_EXCLUDES}" \ --replace-env-exclude-paths="${REPLACE_ENV_VARIABLES_EXCLUDE_PATHS}" \ - --replace-env-prefix=${ENV_VARIABLE_PREFIX} \ + --replace-env-prefix=${REPLACE_ENV_VARIABLE_PREFIX} \ /plugins /data/plugins ;; esac @@ -47,7 +47,7 @@ if [ -d /mods ]; then --replace-env-file-suffixes="${REPLACE_ENV_SUFFIXES}" \ --replace-env-excludes="${REPLACE_ENV_VARIABLES_EXCLUDES}" \ --replace-env-exclude-paths="${REPLACE_ENV_VARIABLES_EXCLUDE_PATHS}" \ - --replace-env-prefix=${ENV_VARIABLE_PREFIX} \ + --replace-env-prefix=${REPLACE_ENV_VARIABLE_PREFIX} \ /mods "${COPY_MODS_DEST}" fi @@ -60,7 +60,7 @@ if [ -d /config ]; then --replace-env-file-suffixes="${REPLACE_ENV_SUFFIXES}" \ --replace-env-excludes="${REPLACE_ENV_VARIABLES_EXCLUDES}" \ --replace-env-exclude-paths="${REPLACE_ENV_VARIABLES_EXCLUDE_PATHS}" \ - --replace-env-prefix=${ENV_VARIABLE_PREFIX} \ + --replace-env-prefix=${REPLACE_ENV_VARIABLE_PREFIX} \ /config "${COPY_CONFIG_DEST}" fi From bbab855c6345fdac1d13f0e94bb79445fdbe00b3 Mon Sep 17 00:00:00 2001 From: Geoff Bourne Date: Mon, 13 Sep 2021 18:00:12 -0500 Subject: [PATCH 09/12] Described variable processing for synchronized content --- README.md | 8 +++++--- start-setupMounts | 2 ++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 5a0bed5ab36..2151392f05c 100644 --- a/README.md +++ b/README.md @@ -656,13 +656,15 @@ then you apply a workaround by adding this to the run invocation: There are optional volume paths that can be attached to supply content to be copied into the data area: `/plugins` -: contents are copied into `/data/plugins` for Bukkit related server types. Set `SYNC_SKIP_NEWER_IN_DESTINATION=false` if you want files from `/plugins` to take precedence over newer files in `/data/plugins`. +: contents are synchronized into `/data/plugins` for Bukkit related server types. Set `SYNC_SKIP_NEWER_IN_DESTINATION=false` if you want files from `/plugins` to take precedence over newer files in `/data/plugins`. `/mods` -: contents are copied into `/data/mods` for Forge related server types. The destination can be changed by setting `COPY_MODS_DEST`. +: contents are synchronized into `/data/mods` for Forge related server types. The destination can be changed by setting `COPY_MODS_DEST`. `/config` -: contents are copied into `/data/config` by default, but can be changed with `COPY_CONFIG_DEST`. For example, `-v ./config:/config -e COPY_CONFIG_DEST=/data` will allow you to copy over files like `bukkit.yml` and so on directly into the server directory. Set `SYNC_SKIP_NEWER_IN_DESTINATION=false` if you want files from `/config` to take precedence over newer files in `/data/config`. +: contents are synchronized into `/data/config` by default, but can be changed with `COPY_CONFIG_DEST`. For example, `-v ./config:/config -e COPY_CONFIG_DEST=/data` will allow you to copy over files like `bukkit.yml` and so on directly into the server directory. Set `SYNC_SKIP_NEWER_IN_DESTINATION=false` if you want files from `/config` to take precedence over newer files in `/data/config`. + +By default, the [environment variable processing](#replacing-variables-inside-configs) is performed on synchronized files that match the expected suffixes (`REPLACE_ENV_SUFFIXES`) and are not excluded by `REPLACE_ENV_VARIABLES_EXCLUDES` and `REPLACE_ENV_VARIABLES_EXCLUDE_PATHS`. This processing can be disabled by setting `REPLACE_ENV_DURING_SYNC` to `false`. If you want old mods/plugins to be removed before the content is brought over from those attach points, then add `-e REMOVE_OLD_MODS=TRUE`. You can fine tune the removal process by specifying the `REMOVE_OLD_MODS_INCLUDE` and `REMOVE_OLD_MODS_EXCLUDE` variables. By default, everything will be removed. You can also specify the `REMOVE_OLD_MODS_DEPTH` (default is 16) variable to only delete files up to a certain level. diff --git a/start-setupMounts b/start-setupMounts index ec8cd85fd5b..0636c85ffac 100644 --- a/start-setupMounts +++ b/start-setupMounts @@ -6,6 +6,8 @@ : ${REPLACE_ENV_SUFFIXES:=yml,yaml,txt,cfg,conf,properties,hjson,json,tml,toml} : ${REPLACE_ENV_DURING_SYNC:=true} : ${REPLACE_ENV_VARIABLE_PREFIX:=${ENV_VARIABLE_PREFIX:-CFG_}} +: ${REPLACE_ENV_VARIABLES_EXCLUDES:=} +: ${REPLACE_ENV_VARIABLES_EXCLUDE_PATHS:=} : ${DEBUG:=false} set -e From 8eed6294d14b4ddbcfebc08562f9e58a4789cdb8 Mon Sep 17 00:00:00 2001 From: Geoff Bourne Date: Mon, 13 Sep 2021 18:04:43 -0500 Subject: [PATCH 10/12] ci: use multiarch build for test/* branches --- .github/workflows/build-multiarch.yml | 2 +- .github/workflows/main.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-multiarch.yml b/.github/workflows/build-multiarch.yml index 9c6612e3357..b9061cead06 100644 --- a/.github/workflows/build-multiarch.yml +++ b/.github/workflows/build-multiarch.yml @@ -8,7 +8,7 @@ on: - java8-openj9 - java11* - java16* - - test/multiarch/* + - test/* tags: - "[0-9]+.[0-9]+.[0-9]+" - "[0-9]+.[0-9]+.[0-9]+-multiarch*" diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index baf8ef1399a..5fddc8cc959 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -7,7 +7,7 @@ on: - openj9 - openj9-11 - adopt11 - - test/* + - test/alpine/* tags: - "[0-9]+.[0-9]+.[0-9]+-java8" - "[0-9]+.[0-9]+.[0-9]+-openj9" From d3b8294a2210d58913d7d2cf0c4d8126f69707b1 Mon Sep 17 00:00:00 2001 From: Geoff Bourne Date: Mon, 13 Sep 2021 18:05:08 -0500 Subject: [PATCH 11/12] docs: Clarified REPLACE_ENV_SUFFIXES --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2151392f05c..b3f40df732c 100644 --- a/README.md +++ b/README.md @@ -664,7 +664,7 @@ There are optional volume paths that can be attached to supply content to be cop `/config` : contents are synchronized into `/data/config` by default, but can be changed with `COPY_CONFIG_DEST`. For example, `-v ./config:/config -e COPY_CONFIG_DEST=/data` will allow you to copy over files like `bukkit.yml` and so on directly into the server directory. Set `SYNC_SKIP_NEWER_IN_DESTINATION=false` if you want files from `/config` to take precedence over newer files in `/data/config`. -By default, the [environment variable processing](#replacing-variables-inside-configs) is performed on synchronized files that match the expected suffixes (`REPLACE_ENV_SUFFIXES`) and are not excluded by `REPLACE_ENV_VARIABLES_EXCLUDES` and `REPLACE_ENV_VARIABLES_EXCLUDE_PATHS`. This processing can be disabled by setting `REPLACE_ENV_DURING_SYNC` to `false`. +By default, the [environment variable processing](#replacing-variables-inside-configs) is performed on synchronized files that match the expected suffixes in `REPLACE_ENV_SUFFIXES` (by default "yml,yaml,txt,cfg,conf,properties,hjson,json,tml,toml") and are not excluded by `REPLACE_ENV_VARIABLES_EXCLUDES` and `REPLACE_ENV_VARIABLES_EXCLUDE_PATHS`. This processing can be disabled by setting `REPLACE_ENV_DURING_SYNC` to `false`. If you want old mods/plugins to be removed before the content is brought over from those attach points, then add `-e REMOVE_OLD_MODS=TRUE`. You can fine tune the removal process by specifying the `REMOVE_OLD_MODS_INCLUDE` and `REMOVE_OLD_MODS_EXCLUDE` variables. By default, everything will be removed. You can also specify the `REMOVE_OLD_MODS_DEPTH` (default is 16) variable to only delete files up to a certain level. From 4ff429a56affdfb02663b03cad830ebe99113b82 Mon Sep 17 00:00:00 2001 From: Geoff Bourne Date: Mon, 13 Sep 2021 19:47:56 -0500 Subject: [PATCH 12/12] Switched to mc-image-helper to interpolate files in-place --- Dockerfile | 2 +- start-setupEnvVariables | 56 +++++++++++------------------------------ start-setupMounts | 4 +-- 3 files changed, 17 insertions(+), 45 deletions(-) diff --git a/Dockerfile b/Dockerfile index f35411f9eec..155a5e015db 100644 --- a/Dockerfile +++ b/Dockerfile @@ -59,7 +59,7 @@ RUN easy-add --var os=${TARGETOS} --var arch=${TARGETARCH}${TARGETVARIANT} \ --var version=0.1.1 --var app=maven-metadata-release --file {{.app}} \ --from https://github.com/itzg/{{.app}}/releases/download/{{.version}}/{{.app}}_{{.version}}_{{.os}}_{{.arch}}.tar.gz -ARG MC_HELPER_VERSION=1.1.5 +ARG MC_HELPER_VERSION=1.2.0 RUN curl -fsSL https://github.com/itzg/mc-image-helper/releases/download/v${MC_HELPER_VERSION}/mc-image-helper-${MC_HELPER_VERSION}.tgz \ | tar -C /usr/share -zxf - \ && ln -s /usr/share/mc-image-helper-${MC_HELPER_VERSION}/bin/mc-image-helper /usr/bin diff --git a/start-setupEnvVariables b/start-setupEnvVariables index 1d6366696e5..51232c0f255 100644 --- a/start-setupEnvVariables +++ b/start-setupEnvVariables @@ -2,51 +2,23 @@ . ${SCRIPTS:-/}start-utils -: ${REPLACE_ENV_VARIABLE_PREFIX:=${ENV_VARIABLE_PREFIX:-CFG_}} : ${REPLACE_ENV_IN_PLACE:=${REPLACE_ENV_VARIABLES:-false}} +: ${REPLACE_ENV_PATHS:=/data} +: ${REPLACE_ENV_SUFFIXES:=yml,yaml,txt,cfg,conf,properties,hjson,json,tml,toml} +: ${REPLACE_ENV_VARIABLE_PREFIX:=${ENV_VARIABLE_PREFIX:-CFG_}} +: ${REPLACE_ENV_VARIABLES_EXCLUDES:=} +: ${REPLACE_ENV_VARIABLES_EXCLUDE_PATHS:=} +: ${DEBUG:=false} if isTrue "${REPLACE_ENV_IN_PLACE}"; then - log "Replacing env variables in configs that match the prefix $REPLACE_ENV_VARIABLE_PREFIX ..." - - # File excludes - fileExcludes= - for f in ${REPLACE_ENV_VARIABLES_EXCLUDES}; do - fileExcludes="${fileExcludes} -not -name $f" - done - - # Directory excludes (recursive) - dirExcludes=$(join_by " -o -path " ${REPLACE_ENV_VARIABLES_EXCLUDE_PATHS}) - if [[ $dirExcludes ]]; then - dirExcludes=" -type d ( -path ${dirExcludes} ) -prune -o" - fi - - isDebugging && echo "Using find file exclusions: $fileExcludes" - isDebugging && echo "Using find directory exclusions: $dirExcludes" - - for name in $(compgen -v $REPLACE_ENV_VARIABLE_PREFIX); do - # check if name of env variable matches the prefix - # sanity check environment variables to avoid code injections - # Read content from file environment - if [[ $name = *"_FILE" ]]; then - value=$(<${!name}) - name="${name%_FILE}" - else - value=${!name} - fi - - log "Replacing $name with $value ..." - - value=${value//\\/\\\\} - value=${value//#/\\#} - - find /data/ \ - $dirExcludes \ - -type f \ - \( -name "*.yml" -or -name "*.yaml" -or -name "*.txt" -or -name "*.cfg" \ - -or -name "*.conf" -or -name "*.properties" -or -name "*.hjson" -or -name "*.json" \) \ - $fileExcludes \ - -exec sed -i 's#${'"$name"'}#'"$value"'#g' {} \; - done + log "Replacing env variables in ${REPLACE_ENV_PATHS} that match the prefix $REPLACE_ENV_VARIABLE_PREFIX ..." + + mc-image-helper --debug=${DEBUG} interpolate \ + --replace-env-file-suffixes="${REPLACE_ENV_SUFFIXES}" \ + --replace-env-excludes="${REPLACE_ENV_VARIABLES_EXCLUDES}" \ + --replace-env-exclude-paths="${REPLACE_ENV_VARIABLES_EXCLUDE_PATHS}" \ + --replace-env-prefix=${REPLACE_ENV_VARIABLE_PREFIX} \ + "${REPLACE_ENV_PATHS[@]}" fi exec ${SCRIPTS:-/}start-finalExec $@ diff --git a/start-setupMounts b/start-setupMounts index 0636c85ffac..b2037a6ac31 100644 --- a/start-setupMounts +++ b/start-setupMounts @@ -3,8 +3,8 @@ . ${SCRIPTS:-/}start-utils : ${SYNC_SKIP_NEWER_IN_DESTINATION:=${PLUGINS_SYNC_UPDATE:-true}} -: ${REPLACE_ENV_SUFFIXES:=yml,yaml,txt,cfg,conf,properties,hjson,json,tml,toml} : ${REPLACE_ENV_DURING_SYNC:=true} +: ${REPLACE_ENV_SUFFIXES:=yml,yaml,txt,cfg,conf,properties,hjson,json,tml,toml} : ${REPLACE_ENV_VARIABLE_PREFIX:=${ENV_VARIABLE_PREFIX:-CFG_}} : ${REPLACE_ENV_VARIABLES_EXCLUDES:=} : ${REPLACE_ENV_VARIABLES_EXCLUDE_PATHS:=} @@ -13,7 +13,7 @@ set -e isDebugging && set -x -if isTrue ${PLUGINS_SYNC_UPDATE}; then +if isTrue ${SYNC_SKIP_NEWER_IN_DESTINATION}; then updateArg="--skip-newer-in-destination" fi