From fd2dfe3f0eafbceac7b291e1959bd35eb6fb9002 Mon Sep 17 00:00:00 2001 From: Ryan Hullah Date: Wed, 8 Feb 2023 21:30:28 -0500 Subject: [PATCH] Add source dir override for `/plugins`, `/mods`, and `/config` (#1957) --- README.md | 6 ++--- scripts/start-setupMounts | 25 +++++++++++-------- .../mounts-custom/custom/config/test.json | 1 + .../mounts-custom/custom/mods/mod.jar | 0 .../mounts-custom/custom/plugins/plugin.jar | 0 .../mounts-custom/docker-compose.yml | 21 ++++++++++++++++ tests/setuponlytests/mounts-custom/fake.jar | 0 tests/setuponlytests/mounts-custom/verify.sh | 3 +++ 8 files changed, 43 insertions(+), 13 deletions(-) create mode 100644 tests/setuponlytests/mounts-custom/custom/config/test.json create mode 100644 tests/setuponlytests/mounts-custom/custom/mods/mod.jar create mode 100644 tests/setuponlytests/mounts-custom/custom/plugins/plugin.jar create mode 100644 tests/setuponlytests/mounts-custom/docker-compose.yml create mode 100644 tests/setuponlytests/mounts-custom/fake.jar create mode 100644 tests/setuponlytests/mounts-custom/verify.sh diff --git a/README.md b/README.md index 939f36e5..21d62b11 100644 --- a/README.md +++ b/README.md @@ -747,13 +747,13 @@ packwiz modpack defitions are processed before other mod definitions (`MODPACK`, There are optional volume paths that can be attached to supply content to be copied into the data area: `/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`. +: contents are synchronized into `/data/plugins` for Bukkit related server types. The source can be changed by setting `COPY_PLUGINS_SRC`. The destination can be changed by setting `COPY_PLUGINS_DEST`. 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 synchronized into `/data/mods` for Fabric and Forge related server types. The destination can be changed by setting `COPY_MODS_DEST`. +: contents are synchronized into `/data/mods` for Fabric and Forge related server types. The source can be changed by setting `COPY_MODS_SRC`. The destination can be changed by setting `COPY_MODS_DEST`. `/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`. +: contents are synchronized into `/data/config` by default, but can be changed with `COPY_CONFIG_DEST`. The source can be changed by setting `COPY_CONFIG_SRC`. 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 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`. diff --git a/scripts/start-setupMounts b/scripts/start-setupMounts index c11f5f04..fb1da99a 100755 --- a/scripts/start-setupMounts +++ b/scripts/start-setupMounts @@ -24,47 +24,52 @@ else subcommand=sync fi -if [ -d /plugins ]; then +: "${COPY_PLUGINS_SRC:="/plugins"}" +: "${COPY_PLUGINS_DEST:="/data/plugins"}" + +if [ -d "${COPY_PLUGINS_SRC}" ]; then case ${FAMILY} in SPIGOT|HYBRID) - mkdir -p /data/plugins - log "Copying plugins over..." + mkdir -p "${COPY_PLUGINS_DEST}" + log "Copying any plugins from ${COPY_PLUGINS_SRC} to ${COPY_PLUGINS_DEST}" mc-image-helper \ ${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}" \ --replace-env-prefix="${REPLACE_ENV_VARIABLE_PREFIX}" \ - /plugins /data/plugins + "${COPY_PLUGINS_SRC}" "${COPY_PLUGINS_DEST}" ;; esac fi # If any modules have been provided, copy them over +: "${COPY_MODS_SRC:="/mods"}" : "${COPY_MODS_DEST:="/data/mods"}" -if [ -d /mods ]; then - log "Copying any mods over..." +if [ -d "${COPY_MODS_SRC}" ]; then + log "Copying any mods from ${COPY_MODS_SRC} to ${COPY_MODS_DEST}" mc-image-helper \ ${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}" \ --replace-env-prefix="${REPLACE_ENV_VARIABLE_PREFIX}" \ - /mods "${COPY_MODS_DEST}" + "${COPY_MODS_SRC}" "${COPY_MODS_DEST}" fi +: "${COPY_CONFIG_SRC:="/config"}" : "${COPY_CONFIG_DEST:="/data/config"}" -if [ -d /config ]; then - log "Copying any configs from /config to ${COPY_CONFIG_DEST}" +if [ -d "${COPY_CONFIG_SRC}" ]; then + log "Copying any configs from ${COPY_CONFIG_SRC} to ${COPY_CONFIG_DEST}" mc-image-helper \ ${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}" \ --replace-env-prefix="${REPLACE_ENV_VARIABLE_PREFIX}" \ - /config "${COPY_CONFIG_DEST}" + "${COPY_CONFIG_SRC}" "${COPY_CONFIG_DEST}" fi exec "${SCRIPTS:-/}start-setupServerProperties" "$@" diff --git a/tests/setuponlytests/mounts-custom/custom/config/test.json b/tests/setuponlytests/mounts-custom/custom/config/test.json new file mode 100644 index 00000000..9e26dfee --- /dev/null +++ b/tests/setuponlytests/mounts-custom/custom/config/test.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/tests/setuponlytests/mounts-custom/custom/mods/mod.jar b/tests/setuponlytests/mounts-custom/custom/mods/mod.jar new file mode 100644 index 00000000..e69de29b diff --git a/tests/setuponlytests/mounts-custom/custom/plugins/plugin.jar b/tests/setuponlytests/mounts-custom/custom/plugins/plugin.jar new file mode 100644 index 00000000..e69de29b diff --git a/tests/setuponlytests/mounts-custom/docker-compose.yml b/tests/setuponlytests/mounts-custom/docker-compose.yml new file mode 100644 index 00000000..0f6a59fa --- /dev/null +++ b/tests/setuponlytests/mounts-custom/docker-compose.yml @@ -0,0 +1,21 @@ +version: "3" + +services: + mc: + image: ${IMAGE_TO_TEST:-itzg/minecraft-server} + environment: + EULA: "true" + SETUP_ONLY: "true" + TYPE: CUSTOM + CUSTOM_SERVER: /servers/fake.jar + VERSION: 1.18.1 + COPY_PLUGINS_SRC: /custom/plugins + COPY_PLUGINS_DEST: /data/custom-plugins + COPY_MODS_SRC: /custom/mods + COPY_MODS_DEST: /data/custom-mods + COPY_CONFIG_SRC: /custom/config + COPY_CONFIG_DEST: /data/custom-config + volumes: + - ./data:/data + - ./custom:/custom + - ./fake.jar:/servers/fake.jar diff --git a/tests/setuponlytests/mounts-custom/fake.jar b/tests/setuponlytests/mounts-custom/fake.jar new file mode 100644 index 00000000..e69de29b diff --git a/tests/setuponlytests/mounts-custom/verify.sh b/tests/setuponlytests/mounts-custom/verify.sh new file mode 100644 index 00000000..b409ffb3 --- /dev/null +++ b/tests/setuponlytests/mounts-custom/verify.sh @@ -0,0 +1,3 @@ +mc-image-helper assert fileExists custom-plugins/plugin.jar +mc-image-helper assert fileExists custom-mods/mod.jar +mc-image-helper assert fileExists custom-config/test.json