From 83d3555eab66a3b88a5fbebc7f4f01c657b3a2f4 Mon Sep 17 00:00:00 2001 From: chblodg Date: Mon, 3 Jan 2022 19:59:19 -0800 Subject: [PATCH] Adding Vanilla Tweaks Options (#1246) --- .gitignore | 4 +- Dockerfile | 54 ++++++------ README.md | 41 +++++++++ examples/vanilla-tweaks/docker-compose.yml | 27 ++++++ .../vanillatweaks-datapacks.json | 15 ++++ scripts/start-setupVanillaTweaks | 84 +++++++++++++++++++ scripts/start-setupWorld | 2 +- tests/docker-compose.yml | 2 +- ...er-compose.test.yml => docker-compose.yml} | 7 +- tests/test.sh | 58 ++++++++++--- tests/vanillatweaks_file/docker-compose.yml | 14 ++++ .../vanillatweaks-datapacks.json | 17 ++++ .../docker-compose.yml | 12 +++ 13 files changed, 291 insertions(+), 46 deletions(-) create mode 100644 examples/vanilla-tweaks/docker-compose.yml create mode 100644 examples/vanilla-tweaks/vanillatweaks-datapacks.json create mode 100644 scripts/start-setupVanillaTweaks rename tests/generic-packs/{docker-compose.test.yml => docker-compose.yml} (75%) create mode 100644 tests/vanillatweaks_file/docker-compose.yml create mode 100644 tests/vanillatweaks_file/vanillatweaks-datapacks.json create mode 100644 tests/vanillatweaks_sharecode/docker-compose.yml diff --git a/.gitignore b/.gitignore index 574e0d91..d7b092b9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ +.vscode /data/ /.idea/ *.iml -/gh-md-toc \ No newline at end of file +*.zip +/gh-md-toc diff --git a/Dockerfile b/Dockerfile index 7beb2c13..c9133e3a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,23 +5,23 @@ LABEL org.opencontainers.image.authors="Geoff Bourne " RUN apt-get update \ && DEBIAN_FRONTEND=noninteractive \ apt-get install -y \ - imagemagick \ - gosu \ - sudo \ - net-tools \ - iputils-ping \ - curl wget \ - git \ - jq \ - dos2unix \ - mysql-client \ - tzdata \ - rsync \ - nano \ - unzip \ - knockd \ - ttf-dejavu \ - && apt-get clean + imagemagick \ + gosu \ + sudo \ + net-tools \ + iputils-ping \ + curl \ + git \ + jq \ + dos2unix \ + mysql-client \ + tzdata \ + rsync \ + nano \ + unzip \ + knockd \ + ttf-dejavu \ + && apt-get clean RUN addgroup --gid 1000 minecraft \ && adduser --system --shell /bin/false --uid 1000 --ingroup minecraft --home /data minecraft @@ -45,26 +45,26 @@ RUN easy-add --var os=${TARGETOS} --var arch=${TARGETARCH}${TARGETVARIANT} \ --from https://github.com/itzg/{{.app}}/releases/download/{{.version}}/{{.app}}_{{.version}}_{{.os}}_{{.arch}}.tar.gz RUN easy-add --var os=${TARGETOS} --var arch=${TARGETARCH}${TARGETVARIANT} \ - --var version=1.5.1 --var app=rcon-cli --file {{.app}} \ - --from https://github.com/itzg/{{.app}}/releases/download/{{.version}}/{{.app}}_{{.version}}_{{.os}}_{{.arch}}.tar.gz + --var version=1.5.1 --var app=rcon-cli --file {{.app}} \ + --from https://github.com/itzg/{{.app}}/releases/download/{{.version}}/{{.app}}_{{.version}}_{{.os}}_{{.arch}}.tar.gz RUN easy-add --var os=${TARGETOS} --var arch=${TARGETARCH}${TARGETVARIANT} \ - --var version=0.10.3 --var app=mc-monitor --file {{.app}} \ - --from https://github.com/itzg/{{.app}}/releases/download/{{.version}}/{{.app}}_{{.version}}_{{.os}}_{{.arch}}.tar.gz + --var version=0.10.3 --var app=mc-monitor --file {{.app}} \ + --from https://github.com/itzg/{{.app}}/releases/download/{{.version}}/{{.app}}_{{.version}}_{{.os}}_{{.arch}}.tar.gz RUN easy-add --var os=${TARGETOS} --var arch=${TARGETARCH}${TARGETVARIANT} \ - --var version=1.8.0 --var app=mc-server-runner --file {{.app}} \ - --from https://github.com/itzg/{{.app}}/releases/download/{{.version}}/{{.app}}_{{.version}}_{{.os}}_{{.arch}}.tar.gz + --var version=1.8.0 --var app=mc-server-runner --file {{.app}} \ + --from https://github.com/itzg/{{.app}}/releases/download/{{.version}}/{{.app}}_{{.version}}_{{.os}}_{{.arch}}.tar.gz 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 + --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.11.0 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 - \ - && ln -s /usr/share/mc-image-helper-${MC_HELPER_VERSION}/bin/mc-image-helper /usr/bin + | tar -C /usr/share -zxf - \ + && ln -s /usr/share/mc-image-helper-${MC_HELPER_VERSION}/bin/mc-image-helper /usr/bin VOLUME ["/data"] WORKDIR /data diff --git a/README.md b/README.md index 5bc263d6..30d0352b 100644 --- a/README.md +++ b/README.md @@ -810,6 +810,47 @@ Datapacks can be installed in a similar manner to mods/plugins. There are many e * `REMOVE_OLD_DATAPACKS_EXCLUDE` Datapacks will be placed in `/data/$LEVEL/datapacks` +### VanillaTweaks + +VanillaTweaks datapacks can be installed with a share code from the website UI **OR** a json file to specify packs to download and install. + +Accepted Parameters: + +- `VANILLATWEAKS_FILE` +- `VANILLATWEAKS_SHARECODE` +- `REMOVE_OLD_VANILLATWEAKS` +- `REMOVE_OLD_VANILLATWEAKS_DEPTH` +- `REMOVE_OLD_VANILLATWEAKS_INCLUDE` +- `REMOVE_OLD_VANILLATWEAKS_EXCLUDE` + +Example of expected Vanillatweaks sharecode: + +```yaml +VANILLATWEAKS_SHARECODE: MGr52E +``` + +Example of expected Vanillatweaks file format: + +```json +{ + "version": "1.18", + "packs": { + "survival": [ + "graves", + "multiplayer sleep", + "afk display", + "armor statues", + "unlock all recipes", + "fast leaf decay", + "coordinates hud" + ], + "items": ["armored elytra"] + } +} +``` + +Datapacks will be placed in `/data/$LEVEL/datapacks` + ## Server configuration By default, the server configuration will be created and set based on the following environment variables, but only the first time the server is started. If the `server.properties` file already exists, the values in them will not be changed. diff --git a/examples/vanilla-tweaks/docker-compose.yml b/examples/vanilla-tweaks/docker-compose.yml new file mode 100644 index 00000000..6adf5dce --- /dev/null +++ b/examples/vanilla-tweaks/docker-compose.yml @@ -0,0 +1,27 @@ +version: "3.3" + +services: + vanillatweaks_file: + restart: "no" + image: itzg/minecraft-server + ports: + - "25565:25565/tcp" + environment: + EULA: "TRUE" + VERSION: ${MINECRAFT_VERSION:-LATEST} + VANILLATWEAKS_FILE: /config/vanillatweaks-datapacks.json + REMOVE_OLD_VANILLATWEAKS: "TRUE" + volumes: + - data:/data + - ./vanillatweaks-datapacks.json:/config/vanillatweaks-datapacks.json:ro + vanillatweaks_sharecode: + # port is set to 25566 to not conflict with vanillatweaks_file example + ports: + - "25566:25565/tcp" + restart: "no" + image: itzg/minecraft-server + environment: + EULA: "TRUE" + VERSION: ${MINECRAFT_VERSION:-LATEST} + VANILLATWEAKS_SHARECODE: MGr52E + REMOVE_OLD_VANILLATWEAKS: "TRUE" diff --git a/examples/vanilla-tweaks/vanillatweaks-datapacks.json b/examples/vanilla-tweaks/vanillatweaks-datapacks.json new file mode 100644 index 00000000..aa19970d --- /dev/null +++ b/examples/vanilla-tweaks/vanillatweaks-datapacks.json @@ -0,0 +1,15 @@ +{ + "version": "1.18", + "packs": { + "survival": [ + "graves", + "multiplayer sleep", + "afk display", + "armor statues", + "unlock all recipes", + "fast leaf decay", + "coordinates hud" + ], + "items": ["armored elytra"] + } +} diff --git a/scripts/start-setupVanillaTweaks b/scripts/start-setupVanillaTweaks new file mode 100644 index 00000000..4da67423 --- /dev/null +++ b/scripts/start-setupVanillaTweaks @@ -0,0 +1,84 @@ +#!/bin/bash + +set -e -o pipefail + +: "${REMOVE_OLD_VANILLATWEAKS:=false}" +: "${VANILLATWEAKS_FILE:=}" +: "${VANILLATWEAKS_SHARECODE:=}" +: "${REMOVE_OLD_VANILLATWEAKS_DEPTH:=1} " +: "${REMOVE_OLD_VANILLATWEAKS_INCLUDE:=*.zip}" + +# shellcheck source=start-utils +. "${SCRIPTS:-/}start-utils" +isDebugging && set -x + +out_dir=/data/${LEVEL:-world}/datapacks + +# Remove old VANILLATWEAKS +if isTrue "${REMOVE_OLD_VANILLATWEAKS}" && [ -z "${VANILLATWEAKS_FILE}" ]; then + if [ -d "$out_dir" ]; then + find "$out_dir" -mindepth 1 -maxdepth ${REMOVE_OLD_VANILLATWEAKS_DEPTH:-16} -wholename "${REMOVE_OLD_VANILLATWEAKS_INCLUDE:-*}" -not -wholename "${REMOVE_OLD_VANILLATWEAKS_EXCLUDE:-}" -delete + fi +fi + +# Example: VANILLATWEAKS_SHARECODE=MGr52E +# Code generated from the UI website, typically a alphanumeric 6 digit code. +if [[ "$VANILLATWEAKS_SHARECODE" ]]; then + VANILLATWEAKS_FILE=/tmp/vanillatweaksfile.json + SHARECODE_LOOKUP_URL="https://vanillatweaks.net/assets/server/sharecode.php?code=${VANILLATWEAKS_SHARECODE}" + curl -f $SHARECODE_LOOKUP_URL -o $VANILLATWEAKS_FILE + if [ ! -f "$VANILLATWEAKS_FILE" ]; then + log "ERROR: Unable to use share code provided to retreive vanillatweaks file" + exit 2 + fi +fi + +# Use vanillatweaks file to specify VT and datapacks +if [[ "$VANILLATWEAKS_FILE" ]]; then + if [ ! -f "$VANILLATWEAKS_FILE" ]; then + log "ERROR: given VANILLATWEAKS_FILE file does not exist" + exit 2 + fi + + PACKS=$(jq -jc '.packs' $VANILLATWEAKS_FILE) + if [ ! "$PACKS" ]; then + log "ERROR: unable to retrieve packs from $VANILLATWEAKS_FILE" + exit 2 + fi + + VT_VERSION=$(jq -jc '.version' $VANILLATWEAKS_FILE) + if [ ! "$VT_VERSION" ]; then + log "ERROR: unable to retrieve version from $VANILLATWEAKS_FILE" + exit 2 + fi +fi + +# Download and unzip packs +if [[ "$PACKS" ]] && [[ "$VT_VERSION" ]]; then + VT_ZIPDATA_URL=https://vanillatweaks.net/assets/server/zipdatapacks.php + DOWNLOAD_URL=$(curl -X POST -F "packs=${PACKS}" -F "version=${VT_VERSION}" $VT_ZIPDATA_URL | jq -r '.link') + if [ ! "$DOWNLOAD_URL" ]; then + log "ERROR: unable to retrieve DOWNLOAD_URL from vanillatweaks.net!" + exit 2 + fi + + TEMPZIP=/tmp/vanillatweaks.zip + if ! get -o $TEMPZIP "https://vanillatweaks.net${DOWNLOAD_URL}"; then + log "ERROR: failed to download from ${DOWNLOAD_URL}" + exit 2 + fi + + mkdir -p "$out_dir" + if ! unzip -o -d "$out_dir" $TEMPZIP; then + log "ERROR: failed to unzip the ${PACKS} from ${$TEMPZIP}" + fi + + # clean up files time! + rm -f $TEMPZIP + # cleans up temp vanilla tweaks file download to get stored packs + if [[ "$VANILLATWEAKS_SHARECODE" ]]; then + rm -f $VANILLATWEAKS_FILE + fi +fi + +exec "${SCRIPTS:-/}start-setupDatapack" "$@" diff --git a/scripts/start-setupWorld b/scripts/start-setupWorld index 3484b46d..c4dad94f 100755 --- a/scripts/start-setupWorld +++ b/scripts/start-setupWorld @@ -69,4 +69,4 @@ if [[ "$WORLD" ]] && ( isTrue "${FORCE_WORLD_COPY}" || [ ! -d "$worldDest" ] ); fi fi -exec "${SCRIPTS:-/}start-setupDatapack" "$@" +exec "${SCRIPTS:-/}start-setupVanillaTweaks" "$@" diff --git a/tests/docker-compose.yml b/tests/docker-compose.yml index f3a0bb0a..61c6f289 100644 --- a/tests/docker-compose.yml +++ b/tests/docker-compose.yml @@ -1,4 +1,4 @@ -version: "3.8" +version: "3" services: monitor: diff --git a/tests/generic-packs/docker-compose.test.yml b/tests/generic-packs/docker-compose.yml similarity index 75% rename from tests/generic-packs/docker-compose.test.yml rename to tests/generic-packs/docker-compose.yml index 210c54dd..46dd8344 100644 --- a/tests/generic-packs/docker-compose.test.yml +++ b/tests/generic-packs/docker-compose.yml @@ -2,14 +2,13 @@ version: "3" services: mc: - image: itzg/minecraft-server + image: ${IMAGE_TO_TEST:-itzg/minecraft-server} environment: EULA: "true" + SETUP_ONLY: "TRUE" GENERIC_PACKS: https://github.com/itzg/mc-image-helper/releases/download/v1.9.5/mc-image-helper-1.9.5.zip,/packs/testing.zip - DEBUG: "true" volumes: - ./packs:/packs - data:/data - volumes: - data: {} \ No newline at end of file + data: {} diff --git a/tests/test.sh b/tests/test.sh index 9db35dec..661499be 100755 --- a/tests/test.sh +++ b/tests/test.sh @@ -1,22 +1,56 @@ #!/bin/bash +# go to script root directory cd "$(dirname "$0")" || exit 1 -failed=false - +# compose down function for reuse down() { - docker-compose down -v + docker-compose down -v --remove-orphans } -docker-compose run monitor || failed=true -echo " -Result: failed=$failed" +fullMinecraftUpTest(){ + name=$1 + failed=false + # run the monitor to validate the Minecraft image is healthy + docker-compose run monitor || failed=true + echo "${name} Result: failed=$failed" -if $failed; then - docker-compose logs mc + # docker-compose logs outputs messages from the specified container + if $failed; then + docker-compose logs mc + down + exit 2 + fi down - exit 1 -else - down -fi +} +setupOnlyMinecraftTest(){ + folder=$1 + failed=false + # run the monitor to validate the Minecraft image is healthy + docker-compose --log-level ERROR up --quiet-pull --exit-code-from mc 2>/dev/null || failed=true + echo "${folder} Result: failed=$failed" + + # docker-compose logs outputs messages from the specified container + if $failed; then + docker-compose logs mc + down + cd .. + exit 2 + fi + down + cd .. +} + +# run tests on base docker compose and validate mc service with monitor +fullMinecraftUpTest 'Full Vanilla Test' + +# go through each folder to test builds +FOLDERS=$(ls) +for folder in $FOLDERS; do + # If folder is a directory + if [ -d "$folder" ]; then + cd "$folder" + setupOnlyMinecraftTest $folder + fi +done diff --git a/tests/vanillatweaks_file/docker-compose.yml b/tests/vanillatweaks_file/docker-compose.yml new file mode 100644 index 00000000..b33292ee --- /dev/null +++ b/tests/vanillatweaks_file/docker-compose.yml @@ -0,0 +1,14 @@ +version: "3" + +services: + mc: + restart: "no" + image: ${IMAGE_TO_TEST:-itzg/minecraft-server} + environment: + EULA: "TRUE" + SETUP_ONLY: "TRUE" + VERSION: ${MINECRAFT_VERSION:-LATEST} + VANILLATWEAKS_FILE: /config/vanillatweaks-datapacks.json + REMOVE_OLD_VANILLATWEAKS: "TRUE" + volumes: + - ./vanillatweaks-datapacks.json:/config/vanillatweaks-datapacks.json:ro diff --git a/tests/vanillatweaks_file/vanillatweaks-datapacks.json b/tests/vanillatweaks_file/vanillatweaks-datapacks.json new file mode 100644 index 00000000..80604c49 --- /dev/null +++ b/tests/vanillatweaks_file/vanillatweaks-datapacks.json @@ -0,0 +1,17 @@ +{ + "type": "datapacks", + "version": "1.18", + "packs": { + "survival": [ + "graves", + "multiplayer sleep", + "afk display", + "armor statues", + "unlock all recipes", + "fast leaf decay", + "coordinates hud" + ], + "items": ["armored elytra"] + }, + "result": "ok" +} diff --git a/tests/vanillatweaks_sharecode/docker-compose.yml b/tests/vanillatweaks_sharecode/docker-compose.yml new file mode 100644 index 00000000..66eac5b5 --- /dev/null +++ b/tests/vanillatweaks_sharecode/docker-compose.yml @@ -0,0 +1,12 @@ +version: "3" + +services: + mc: + restart: "no" + image: ${IMAGE_TO_TEST:-itzg/minecraft-server} + environment: + EULA: "TRUE" + SETUP_ONLY: "TRUE" + VERSION: ${MINECRAFT_VERSION:-LATEST} + VANILLATWEAKS_SHARECODE: MGr52E + REMOVE_OLD_VANILLATWEAKS: "TRUE"