From c2071e5038e422e595e53a85c7885bc765416abe Mon Sep 17 00:00:00 2001 From: Geoff Bourne Date: Sat, 2 Aug 2025 19:01:49 -0500 Subject: [PATCH] Add VERSION_FROM_MODRINTH_PROJECTS (#3580) --- Dockerfile | 2 +- docs/mods-and-plugins/modrinth.md | 20 +++++++++++++++++++ .../compose.yml | 15 ++++++++++++++ scripts/start-configuration | 9 +++++++++ 4 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 examples/modrinth/version-from-modrinth-projects/compose.yml diff --git a/Dockerfile b/Dockerfile index d336fa24..47d7b87e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -48,7 +48,7 @@ RUN easy-add --var os=${TARGETOS} --var arch=${TARGETARCH}${TARGETVARIANT} \ --var version=${MC_SERVER_RUNNER_VERSION} --var app=mc-server-runner --file {{.app}} \ --from ${GITHUB_BASEURL}/itzg/{{.app}}/releases/download/{{.version}}/{{.app}}_{{.version}}_{{.os}}_{{.arch}}.tar.gz -ARG MC_HELPER_VERSION=1.47.3 +ARG MC_HELPER_VERSION=1.48.0 ARG MC_HELPER_BASE_URL=${GITHUB_BASEURL}/itzg/mc-image-helper/releases/download/${MC_HELPER_VERSION} # used for cache busting local copy of mc-image-helper ARG MC_HELPER_REV=1 diff --git a/docs/mods-and-plugins/modrinth.md b/docs/mods-and-plugins/modrinth.md index d34acfbf..1e499ea2 100644 --- a/docs/mods-and-plugins/modrinth.md +++ b/docs/mods-and-plugins/modrinth.md @@ -42,6 +42,25 @@ datapack:terralith ``` +## Version from Projects + +When the environment variable `VERSION_FROM_MODRINTH_PROJECTS` is set to "true" the Minecraft [`VERSION`](../versions/minecraft.md) will be automatically determined by looking at the most recent version of Minecraft that is supported by all the projects provided in `MODRINTH_PROJECTS`. + +!!! example + + Given the environment variables + + ```yaml + MODRINTH_PROJECTS: | + viaversion + viabackwards + griefprevention + discordsrv + VERSION_FROM_MODRINTH_PROJECTS: true + ``` + + Let's say all are supported on Minecraft up to 1.21.8 except griefprevention, which is only supported up to 1.21.7. In that case, `VERSION` will be automatically set to 1.21.7. + ## Extra options `MODRINTH_DOWNLOAD_DEPENDENCIES` @@ -52,3 +71,4 @@ `MODRINTH_LOADER` : When using a custom server, set this to specify which loader type will be requested during lookups + diff --git a/examples/modrinth/version-from-modrinth-projects/compose.yml b/examples/modrinth/version-from-modrinth-projects/compose.yml new file mode 100644 index 00000000..59815fcc --- /dev/null +++ b/examples/modrinth/version-from-modrinth-projects/compose.yml @@ -0,0 +1,15 @@ +services: + mc: + image: itzg/minecraft-server + environment: + EULA: true + TYPE: paper + MODRINTH_PROJECTS: | + viaversion + viabackwards + griefprevention + discordsrv + VERSION_FROM_MODRINTH_PROJECTS: true + SETUP_ONLY: true + ports: + - "25565:25565" \ No newline at end of file diff --git a/scripts/start-configuration b/scripts/start-configuration index b1df96c3..031614b5 100755 --- a/scripts/start-configuration +++ b/scripts/start-configuration @@ -139,6 +139,15 @@ cd /data || exit 1 export DECLARED_TYPE=${TYPE^^} export DECLARED_VERSION="$VERSION" +if isTrue "${VERSION_FROM_MODRINTH_PROJECTS:-}" && [[ ${MODRINTH_PROJECTS:-} ]]; then + if ! VERSION=$(mc-image-helper version-from-modrinth-projects --projects "${MODRINTH_PROJECTS}"); then + logError "failed to resolve version from MODRINTH_PROJECTS: ${MODRINTH_PROJECTS}" + exit 1 + fi + log "Resolved Minecraft version $VERSION from Modrinth projects" + export VERSION +fi + if isTrue "${ENABLE_AUTOPAUSE}"; then "${SCRIPTS:-/}start-autopause" fi