From 59c2c3060362186496083a5350e66735f57eca37 Mon Sep 17 00:00:00 2001 From: Geoff Bourne Date: Sun, 26 Jun 2022 18:15:41 -0500 Subject: [PATCH 1/6] Added support for downloading mods from Modrinth --- Dockerfile | 2 +- README.md | 16 ++- examples/docker-compose-modrinth.yml | 18 ++++ scripts/start-setupModpack | 151 ++++++++++++++++----------- scripts/start-utils | 6 +- 5 files changed, 124 insertions(+), 69 deletions(-) create mode 100644 examples/docker-compose-modrinth.yml diff --git a/Dockerfile b/Dockerfile index 22e38e092ce..5744cbe53bb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -46,7 +46,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.17.0 +ARG MC_HELPER_VERSION=1.18.2 ARG MC_HELPER_BASE_URL=https://github.com/itzg/mc-image-helper/releases/download/v${MC_HELPER_VERSION} RUN curl -fsSL ${MC_HELPER_BASE_URL}/mc-image-helper-${MC_HELPER_VERSION}.tgz \ | tar -C /usr/share -zxf - \ diff --git a/README.md b/README.md index 095afd5cd36..6dfff5642a0 100644 --- a/README.md +++ b/README.md @@ -684,6 +684,20 @@ For example, the following will auto-download the [EssentialsX](https://www.spig -e SPIGET_RESOURCES=9089,34315 +### Auto-download mods from Modrinth + +[Modrinth](https://modrinth.com/) is an open source modding platform with a clean, easy to use website for finding [Fabric and Forge mods](https://modrinth.com/mods). At startup, the container will automatically locate and download the newest versions of mod files that correspond to the `TYPE` and `VERSION` in use. Older file versions downloaded previously will automatically be cleaned up. + +- **MODRINTH_PROJECTS** : comma separated list of project slugs (short name) or IDs. The project ID can be located in the "Technical information" section. The slug is the part of the page URL that follows `/mod/` in the URL: +``` + https://modrinth.com/mod/fabric-api + ---------- + | + +-- project slug +``` +- **MODRINTH_DOWNLOAD_OPTIONAL_DEPENDENCIES**=true : required dependencies of the project will _always_ be downloaded and optional dependencies can also be downloaded by setting this to `true` +- **MODRINTH_ALLOWED_VERSION_TYPE**=release : the version type is used to determine the newest version to use from each project. The allowed values are `release`, `beta`, `alpha`. + ### Downloadable mod/plugin pack for Forge, Fabric, and Bukkit-like Servers Like the `WORLD` option above, you can specify the URL or path of a "mod pack" @@ -899,7 +913,7 @@ Datapacks Json: "packs": { "survival": [ "graves", - "multiplayer sleep", + "multiplayer sleep" ], "items": ["armored elytra"] } diff --git a/examples/docker-compose-modrinth.yml b/examples/docker-compose-modrinth.yml new file mode 100644 index 00000000000..62dd7937d7d --- /dev/null +++ b/examples/docker-compose-modrinth.yml @@ -0,0 +1,18 @@ +version: "3.8" + +services: + mc: + image: itzg/minecraft-server + tty: true + stdin_open: true + ports: + - "25565:25565" + environment: + EULA: "TRUE" + TYPE: FABRIC + MODRINTH_PROJECTS: fallingtree + volumes: + - data:/data + +volumes: + data: {} \ No newline at end of file diff --git a/scripts/start-setupModpack b/scripts/start-setupModpack index 94010165553..827de93da6a 100755 --- a/scripts/start-setupModpack +++ b/scripts/start-setupModpack @@ -195,75 +195,102 @@ case "X$EFFECTIVE_MANIFEST_FILE" in esac fi -: "${GENERIC_PACKS:=${GENERIC_PACK}}" -: "${GENERIC_PACKS_PREFIX:=}" -: "${GENERIC_PACKS_SUFFIX:=}" - -if [[ "${GENERIC_PACKS}" ]]; then - IFS=',' read -ra packs <<< "${GENERIC_PACKS}" - - packFiles=() - for packEntry in "${packs[@]}"; do - pack="${GENERIC_PACKS_PREFIX}${packEntry}${GENERIC_PACKS_SUFFIX}" - if isURL "${pack}"; then - mkdir -p /data/packs - log "Downloading generic pack from $pack" - if ! outfile=$(get -o /data/packs --output-filename --skip-up-to-date "$pack"); then - log "ERROR: failed to download $pack" - exit 2 - fi - packFiles+=("$outfile") - else - packFiles+=("$pack") - fi - done +function genericPacks() { + : "${GENERIC_PACKS:=${GENERIC_PACK}}" + : "${GENERIC_PACKS_PREFIX:=}" + : "${GENERIC_PACKS_SUFFIX:=}" + + if [[ "${GENERIC_PACKS}" ]]; then + IFS=',' read -ra packs <<< "${GENERIC_PACKS}" - isDebugging && [ -f "$sum_file}" ] && cat "$sum_file" - - log "Checking if generic packs are up to date" - if isTrue "${SKIP_GENERIC_PACK_UPDATE_CHECK:-false}" && [ -f "$sum_file" ]; then - log "Skipping generic pack update check" - elif isTrue "${FORCE_GENERIC_PACK_UPDATE}" || ! checkSum "${sum_file}"; then - log "Generic pack(s) are out of date. Re-applying..." - - original_base_dir=/data/.tmp/generic_pack_base - base_dir=$original_base_dir - rm -rf "${base_dir}" - mkdir -p "${base_dir}" - for pack in "${packFiles[@]}"; do - isDebugging && ls -l "${pack}" - extract "${pack}" "${base_dir}" + packFiles=() + for packEntry in "${packs[@]}"; do + pack="${GENERIC_PACKS_PREFIX}${packEntry}${GENERIC_PACKS_SUFFIX}" + if isURL "${pack}"; then + mkdir -p /data/packs + log "Downloading generic pack from $pack" + if ! outfile=$(get -o /data/packs --output-filename --skip-up-to-date "$pack"); then + log "ERROR: failed to download $pack" + exit 2 + fi + packFiles+=("$outfile") + else + packFiles+=("$pack") + fi done - # recalculate the actual base directory of content - base_dir=$(find "$base_dir" -maxdepth 3 -type d \( -name mods -o -name plugins -o -name config \) -printf '%h' -quit) - if [[ ! $base_dir ]]; then - log "ERROR: Unable to find content base of generic packs ${GENERIC_PACKS}. Directories:" - find $original_base_dir -maxdepth 3 -type d -printf ' - %P\n' - exit 1 - fi + isDebugging && [ -f "$sum_file}" ] && cat "$sum_file" - if [ -f /data/manifest.txt ]; then - log "Manifest exists from older generic pack, cleaning up ..." - while read -r f; do - rm -rf "/data/${f}" - done < /data/manifest.txt - # prune empty dirs - find /data -mindepth 1 -depth -type d -empty -delete - rm -f /data/manifest.txt - fi + log "Checking if generic packs are up to date" + if isTrue "${SKIP_GENERIC_PACK_UPDATE_CHECK:-false}" && [ -f "$sum_file" ]; then + log "Skipping generic pack update check" + elif isTrue "${FORCE_GENERIC_PACK_UPDATE}" || ! checkSum "${sum_file}"; then + log "Generic pack(s) are out of date. Re-applying..." - log "Writing generic pack manifest ... " - find "${base_dir}" -type f -printf "%P\n" > /data/manifest.txt + original_base_dir=/data/.tmp/generic_pack_base + base_dir=$original_base_dir + rm -rf "${base_dir}" + mkdir -p "${base_dir}" + for pack in "${packFiles[@]}"; do + isDebugging && ls -l "${pack}" + extract "${pack}" "${base_dir}" + done - log "Applying generic pack ..." - cp -R -f "${base_dir}"/* /data - rm -rf $original_base_dir + # recalculate the actual base directory of content + base_dir=$(find "$base_dir" -maxdepth 3 -type d \( -name mods -o -name plugins -o -name config \) -printf '%h' -quit) + if [[ ! $base_dir ]]; then + log "ERROR: Unable to find content base of generic packs ${GENERIC_PACKS}. Directories:" + find $original_base_dir -maxdepth 3 -type d -printf ' - %P\n' + exit 1 + fi - log "Saving generic pack(s) checksum" - sha1sum "${packFiles[@]}" > "${sum_file}" - isDebugging && cat "$sum_file" + if [ -f /data/manifest.txt ]; then + log "Manifest exists from older generic pack, cleaning up ..." + while read -r f; do + rm -rf "/data/${f}" + done < /data/manifest.txt + # prune empty dirs + find /data -mindepth 1 -depth -type d -empty -delete + rm -f /data/manifest.txt + fi + + log "Writing generic pack manifest ... " + find "${base_dir}" -type f -printf "%P\n" > /data/manifest.txt + + log "Applying generic pack ..." + cp -R -f "${base_dir}"/* /data + rm -rf $original_base_dir + + log "Saving generic pack(s) checksum" + sha1sum "${packFiles[@]}" > "${sum_file}" + isDebugging && cat "$sum_file" + fi fi -fi +} + +function modrinthProjects() { + : "${MODRINTH_PROJECTS:=}" + : "${MODRINTH_DOWNLOAD_OPTIONAL_DEPENDENCIES:=true}" + : "${MODRINTH_ALLOWED_VERSION_TYPE:=release}" + + if [[ $MODRINTH_PROJECTS ]] && isFamily HYBRID FABRIC; then + if [[ ${FAMILY^^} = HYBRID ]]; then + loader=forge + else + loader="${FAMILY,,}" + fi + mc-image-helper modrinth \ + --output-directory=/data \ + --projects="${MODRINTH_PROJECTS}" \ + --game-version="${VANILLA_VERSION}" \ + --loader="$loader" \ + --download-optional-dependencies="$MODRINTH_DOWNLOAD_OPTIONAL_DEPENDENCIES" \ + --allowed-version-type="$MODRINTH_ALLOWED_VERSION_TYPE" + fi +} + +genericPacks + +modrinthProjects exec "${SCRIPTS:-/}start-setupModconfig" "$@" diff --git a/scripts/start-utils b/scripts/start-utils index efc33acae96..235347fe10b 100755 --- a/scripts/start-utils +++ b/scripts/start-utils @@ -212,11 +212,7 @@ function removeOldMods { } function get() { - local flags=() - if isTrue "${DEBUG_GET:-false}"; then - flags+=("--debug") - fi - mc-image-helper "${flags[@]}" get "$@" + mc-image-helper get "$@" } function get_silent() { From fb5580d82e85cfbb5b7c71795e2c4dc1b3e27e89 Mon Sep 17 00:00:00 2001 From: Geoff Bourne Date: Sun, 26 Jun 2022 18:20:11 -0500 Subject: [PATCH 2/6] Indent code block? --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 6dfff5642a0..8af46bcce0d 100644 --- a/README.md +++ b/README.md @@ -688,13 +688,13 @@ For example, the following will auto-download the [EssentialsX](https://www.spig [Modrinth](https://modrinth.com/) is an open source modding platform with a clean, easy to use website for finding [Fabric and Forge mods](https://modrinth.com/mods). At startup, the container will automatically locate and download the newest versions of mod files that correspond to the `TYPE` and `VERSION` in use. Older file versions downloaded previously will automatically be cleaned up. -- **MODRINTH_PROJECTS** : comma separated list of project slugs (short name) or IDs. The project ID can be located in the "Technical information" section. The slug is the part of the page URL that follows `/mod/` in the URL: -``` +- **MODRINTH_PROJECTS** : comma separated list of project slugs (short name) or IDs. The project ID can be located in the "Technical information" section. The slug is the part of the page URL that follows `/mod/`: + ``` https://modrinth.com/mod/fabric-api ---------- | +-- project slug -``` + ``` - **MODRINTH_DOWNLOAD_OPTIONAL_DEPENDENCIES**=true : required dependencies of the project will _always_ be downloaded and optional dependencies can also be downloaded by setting this to `true` - **MODRINTH_ALLOWED_VERSION_TYPE**=release : the version type is used to determine the newest version to use from each project. The allowed values are `release`, `beta`, `alpha`. From e6dc0e1ef95bf9f44cd5288219bb72f801f20d2d Mon Sep 17 00:00:00 2001 From: Geoff Bourne Date: Sun, 26 Jun 2022 18:37:49 -0500 Subject: [PATCH 3/6] Added test --- tests/setuponlytests/modrinth/docker-compose.yml | 15 +++++++++++++++ tests/setuponlytests/modrinth/fake.jar | 0 tests/setuponlytests/modrinth/verify.sh | 1 + 3 files changed, 16 insertions(+) create mode 100644 tests/setuponlytests/modrinth/docker-compose.yml create mode 100644 tests/setuponlytests/modrinth/fake.jar create mode 100644 tests/setuponlytests/modrinth/verify.sh diff --git a/tests/setuponlytests/modrinth/docker-compose.yml b/tests/setuponlytests/modrinth/docker-compose.yml new file mode 100644 index 00000000000..394538dd960 --- /dev/null +++ b/tests/setuponlytests/modrinth/docker-compose.yml @@ -0,0 +1,15 @@ +version: "3" + +services: + mc: + image: ${IMAGE_TO_TEST:-itzg/minecraft-server} + environment: + EULA: "true" + SETUP_ONLY: "true" + TYPE: FABRIC + FABRIC_LAUNCHER: /servers/fake.jar + CUSTOM_SERVER: /servers/fake.jar + MODRINTH_PROJECTS: fabric-api,cloth-config + volumes: + - ./data:/data + - ./fake.jar:/servers/fake.jar diff --git a/tests/setuponlytests/modrinth/fake.jar b/tests/setuponlytests/modrinth/fake.jar new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/setuponlytests/modrinth/verify.sh b/tests/setuponlytests/modrinth/verify.sh new file mode 100644 index 00000000000..1fd1fe618bd --- /dev/null +++ b/tests/setuponlytests/modrinth/verify.sh @@ -0,0 +1 @@ +mc-image-helper assert fileExists "mods/cloth-config-*.jar" "mods/fabric-api-*.jar" \ No newline at end of file From 2253aaf94adf7bce053b1263494a31316e5ad272 Mon Sep 17 00:00:00 2001 From: Geoff Bourne Date: Sun, 26 Jun 2022 18:48:02 -0500 Subject: [PATCH 4/6] Debug generic-packs test failing in GHA --- tests/setuponlytests/generic-packs/docker-compose.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/setuponlytests/generic-packs/docker-compose.yml b/tests/setuponlytests/generic-packs/docker-compose.yml index a2b27c5d065..0f2694188c8 100644 --- a/tests/setuponlytests/generic-packs/docker-compose.yml +++ b/tests/setuponlytests/generic-packs/docker-compose.yml @@ -18,6 +18,7 @@ services: TYPE: CUSTOM CUSTOM_SERVER: /servers/fake.jar VERSION: 1.18.1 + DEBUG: "true" volumes: - ./packs:/packs - ./data:/data From 952cb0cb4fc4bf56898d57af895a8439f0f6dc5e Mon Sep 17 00:00:00 2001 From: Geoff Bourne Date: Mon, 27 Jun 2022 08:13:50 -0500 Subject: [PATCH 5/6] mc-image-helper doesn't pick up DEBUG now --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 5744cbe53bb..4c3d6b0aff0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -46,7 +46,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.18.2 +ARG MC_HELPER_VERSION=1.18.3 ARG MC_HELPER_BASE_URL=https://github.com/itzg/mc-image-helper/releases/download/v${MC_HELPER_VERSION} RUN curl -fsSL ${MC_HELPER_BASE_URL}/mc-image-helper-${MC_HELPER_VERSION}.tgz \ | tar -C /usr/share -zxf - \ From b0348f04cfbb9f915566023683d033e7b9a93976 Mon Sep 17 00:00:00 2001 From: Geoff Bourne Date: Mon, 27 Jun 2022 08:27:07 -0500 Subject: [PATCH 6/6] Enable debug on generic-packs-prefix --- tests/setuponlytests/generic-packs-prefix/docker-compose.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/setuponlytests/generic-packs-prefix/docker-compose.yml b/tests/setuponlytests/generic-packs-prefix/docker-compose.yml index 4d84fa67ce5..5519c89fb4c 100644 --- a/tests/setuponlytests/generic-packs-prefix/docker-compose.yml +++ b/tests/setuponlytests/generic-packs-prefix/docker-compose.yml @@ -9,6 +9,7 @@ services: GENERIC_PACKS: testing GENERIC_PACKS_PREFIX: /packs/ GENERIC_PACKS_SUFFIX: .zip + DEBUG: "true" volumes: - ./packs:/packs - ./data:/data