Add REMOVE_OLD_CONFIGS to clear old configs before modpack install (#4266)

This commit is contained in:
alberto-is
2026-09-17 07:25:14 -05:00
committed by GitHub
parent efade6567b
commit 22749e08b7
8 changed files with 75 additions and 0 deletions
+2
View File
@@ -66,6 +66,8 @@ You can also specify the `REMOVE_OLD_MODS_DEPTH` (default is 16) variable to onl
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. 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.
To remove all files in the `/data/config` directory before a modpack is downloaded and unpacked, set `REMOVE_OLD_CONFIGS=TRUE`. This is useful when a modpack update would otherwise override locally customized configuration files. The removal process can be fine tuned with `REMOVE_OLD_CONFIGS_INCLUDE` and `REMOVE_OLD_CONFIGS_EXCLUDE` (comma separated lists of file glob patterns, defaults to `*` so everything is removed) and `REMOVE_OLD_CONFIGS_DEPTH` (default 16). The target directory can be changed with `CONFIG_OUT_DIR` (default `/data/config`).
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. 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.
!!! information "Multiple source directories" !!! information "Multiple source directories"
+9
View File
@@ -9,6 +9,11 @@ set -e -o pipefail
: "${PLUGINS_FILE:=}" : "${PLUGINS_FILE:=}"
: "${REMOVE_OLD_MODS_DEPTH:=1} " : "${REMOVE_OLD_MODS_DEPTH:=1} "
: "${REMOVE_OLD_MODS_INCLUDE:=*.jar,*-version.json}" : "${REMOVE_OLD_MODS_INCLUDE:=*.jar,*-version.json}"
: "${REMOVE_OLD_CONFIGS:=false}"
: "${CONFIG_OUT_DIR:=/data/config}"
: "${REMOVE_OLD_CONFIGS_DEPTH:=16}"
: "${REMOVE_OLD_CONFIGS_INCLUDE:=*}"
: "${REMOVE_OLD_CONFIGS_EXCLUDE:=}"
: "${CF_USE_HTTP2:=false}" # CF downloads are faster with HTTP 1.1 : "${CF_USE_HTTP2:=false}" # CF downloads are faster with HTTP 1.1
: "${MODRINTH_LOADER:=}" : "${MODRINTH_LOADER:=}"
@@ -25,6 +30,10 @@ if isTrue "${REMOVE_OLD_MODS}" && [ -z "${MODS_FILE}" ]; then
rm -f "$sum_file" rm -f "$sum_file"
fi fi
if isTrue "${REMOVE_OLD_CONFIGS}"; then
removeOldConfigs "$CONFIG_OUT_DIR"
fi
function handlePackwiz() { function handlePackwiz() {
# If packwiz url passed, bootstrap packwiz and update mods before other modpack processing # If packwiz url passed, bootstrap packwiz and update mods before other modpack processing
if [[ "${PACKWIZ_URL:-}" ]]; then if [[ "${PACKWIZ_URL:-}" ]]; then
+17
View File
@@ -547,6 +547,23 @@ function removeOldMods {
fi fi
} }
function removeOldConfigs {
if [ -d "$1" ]; then
log "Removing old configs including='${REMOVE_OLD_CONFIGS_INCLUDE}' excluding='${REMOVE_OLD_CONFIGS_EXCLUDE}' up to depth=${REMOVE_OLD_CONFIGS_DEPTH}"
args=(
--delete
--type file
--min-depth=1 --max-depth "${REMOVE_OLD_CONFIGS_DEPTH}"
--name "${REMOVE_OLD_CONFIGS_INCLUDE}"
--exclude-name "${REMOVE_OLD_CONFIGS_EXCLUDE}"
)
if ! isDebugging; then
args+=(--quiet)
fi
mc-image-helper find "${args[@]}" "$1"
fi
}
function get() { function get() {
mc-image-helper get "$@" mc-image-helper get "$@"
} }
Binary file not shown.
@@ -0,0 +1,43 @@
services:
# copies an existing config into /data before mc starts, so REMOVE_OLD_CONFIGS
# has an old config to remove once the modpack config is installed
seed:
restart: "no"
image: ${IMAGE_TO_TEST:-itzg/minecraft-server}
entrypoint: ["bash", "-c", "mkdir -p /data/config && cp /seed/config/stale.txt /data/config/ && chown -R 1000:1000 /data"]
volumes:
- ./seed:/seed
- ./data:/data
web:
image: nginx
volumes:
- ./configs.zip:/usr/share/nginx/html/configs.zip:ro
healthcheck:
test: ["CMD", "curl", "--fail", "http://localhost/configs.zip"]
interval: 3s
timeout: 5s
retries: 3
mc:
restart: "no"
image: ${IMAGE_TO_TEST:-itzg/minecraft-server}
depends_on:
seed:
condition: service_completed_successfully
web:
condition: service_healthy
environment:
EULA: "true"
SETUP_ONLY: "true"
GENERIC_PACKS: http://web/configs.zip
REMOVE_OLD_CONFIGS: "true"
LOG_TIMESTAMP: "true"
# the following are only used to speed up test execution
TYPE: CUSTOM
CUSTOM_SERVER: /servers/fake.jar
VERSION: 1.18.1
DEBUG: "true"
volumes:
- ./data:/data
- ./fake.jar:/servers/fake.jar
@@ -0,0 +1 @@
old
@@ -0,0 +1,3 @@
# verify that the old config was removed and the new one from the pack was installed
mc-image-helper assert fileNotExists config/stale.txt
mc-image-helper assert fileExists config/opt.yml