diff --git a/.github/workflows/verify-pr.yml b/.github/workflows/verify-pr.yml index 3fe4129c3e2..4192ed5bd51 100644 --- a/.github/workflows/verify-pr.yml +++ b/.github/workflows/verify-pr.yml @@ -64,5 +64,6 @@ jobs: MINECRAFT_VERSION: ${{ matrix.mcVersion }} VARIANT: ${{ matrix.variant }} MODS_FORGEAPI_KEY: ${{ secrets.MODS_FORGEAPI_KEY }} + DEBUG: ${{ runner.debug }} run: | tests/test.sh diff --git a/Dockerfile b/Dockerfile index e08bcf4a2a8..e2bb057aa2d 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.22.4 +ARG MC_HELPER_VERSION=1.22.6 ARG MC_HELPER_RELEASE=v${MC_HELPER_VERSION} ARG MC_HELPER_BASE_URL=https://github.com/itzg/mc-image-helper/releases/download/${MC_HELPER_RELEASE} RUN curl -fsSL ${MC_HELPER_BASE_URL}/mc-image-helper-${MC_HELPER_VERSION}.tgz \ diff --git a/examples/.gitignore b/examples/.gitignore index 5fac628525f..a67cdf21038 100644 --- a/examples/.gitignore +++ b/examples/.gitignore @@ -1 +1,2 @@ -/data/ \ No newline at end of file +/data/ +modpacks/ \ No newline at end of file diff --git a/examples/docker-compose-mods-mount.yml b/examples/docker-compose-mods-mount.yml new file mode 100644 index 00000000000..3ad145f1026 --- /dev/null +++ b/examples/docker-compose-mods-mount.yml @@ -0,0 +1,21 @@ +version: '3.8' + +services: + minecraft: + image: itzg/minecraft-server + volumes: + - data:/data + - ./mods:/mods + ports: + - "25565:25565" + environment: + EULA: "true" + TYPE: "FORGE" + VERSION: "1.19.2" + DEBUG: "true" + SETUP_ONLY: "true" + tty: True + stdin_open: True + +volumes: + data: {} \ No newline at end of file diff --git a/examples/valhelsia2/docker-compose.yml b/examples/valhelsia2/docker-compose.yml new file mode 100644 index 00000000000..3dfb367d06a --- /dev/null +++ b/examples/valhelsia2/docker-compose.yml @@ -0,0 +1,21 @@ +version: '3.8' + +services: + mc: + image: itzg/minecraft-server:java8-multiarch + volumes: + - data:/data + - ./modpacks:/modpacks:ro + environment: + EULA: "true" + TYPE: FORGE + VERSION: "1.15.2" + GENERIC_PACK: /modpacks/Valhelsia_2-2.3.4-SERVER.zip + MEMORY: "2G" + ports: + - "25565:25565" + healthcheck: + test: NONE + +volumes: + data: {} \ No newline at end of file diff --git a/scripts/start-setupEnvVariables b/scripts/start-setupEnvVariables index 42eae28f742..970afb6eee0 100755 --- a/scripts/start-setupEnvVariables +++ b/scripts/start-setupEnvVariables @@ -17,7 +17,7 @@ set -e if isTrue "${REPLACE_ENV_IN_PLACE}"; then log "Replacing env variables in ${REPLACE_ENV_PATHS} that match the prefix $REPLACE_ENV_VARIABLE_PREFIX ..." - mc-image-helper --debug=${DEBUG} interpolate \ + mc-image-helper interpolate \ --replace-env-file-suffixes="${REPLACE_ENV_SUFFIXES}" \ --replace-env-excludes="${REPLACE_ENV_VARIABLES_EXCLUDES}" \ --replace-env-exclude-paths="${REPLACE_ENV_VARIABLES_EXCLUDE_PATHS}" \ @@ -27,7 +27,7 @@ fi if [[ ${PATCH_DEFINITIONS} ]]; then log "Applying patch definitions from ${PATCH_DEFINITIONS}" - mc-image-helper --debug=${DEBUG} patch \ + mc-image-helper patch \ --patch-env-prefix="${REPLACE_ENV_VARIABLE_PREFIX}" \ "${PATCH_DEFINITIONS}" fi diff --git a/scripts/start-setupModpack b/scripts/start-setupModpack index 71b988e75de..a6ddbb578fc 100755 --- a/scripts/start-setupModpack +++ b/scripts/start-setupModpack @@ -22,39 +22,26 @@ if isTrue "${REMOVE_OLD_MODS}" && [ -z "${MODS_FILE}" ]; then rm -f "$sum_file" fi -# If packwiz url passed, bootstrap packwiz and update mods before other modpack processing -if [[ "${PACKWIZ_URL:-}" ]]; then - # Ensure we have the latest packwiz bootstrap installer - latestPackwiz=$(get_from_gh "https://api.github.com/repos/packwiz/packwiz-installer-bootstrap/releases/latest") - if [[ -z "${latestPackwiz}" ]]; then - log "WARNING: Could not retrieve Packwiz bootstrap installer release information" - else - isDebugging && log "Latest packwiz ${latestPackwiz}" - latestPackwizVer=$(echo "${latestPackwiz}" | jq --raw-output '.tag_name') - latestPackwizUrl=$(echo "${latestPackwiz}" | jq --raw-output '.assets[] | select(.name | match("packwiz-installer-bootstrap.jar")) | .url') - : "${PACKWIZ_BOOTSTRAP_JAR:=packwiz-installer-bootstrap_${latestPackwizVer}.jar}" - if [[ ! -e $PACKWIZ_BOOTSTRAP_JAR ]]; then - log "Downloading Packwiz ${latestPackwizVer}" - if ! curl -H "Accept:application/octet-stream" -o "$PACKWIZ_BOOTSTRAP_JAR" -fsSL ${latestPackwizUrl}; then - log "ERROR: failed to download Packwiz bootstrap installer" - exit 1 - fi +function handlePackwiz() { + # If packwiz url passed, bootstrap packwiz and update mods before other modpack processing + if [[ "${PACKWIZ_URL:-}" ]]; then + if ! packwizInstaller=$(mc-image-helper maven-download \ + --maven-repo=https://maven.packwiz.infra.link/repository/release/ \ + --group=link.infra.packwiz --artifact=packwiz-installer --classifier=dist \ + --skip-existing); then + log "ERROR: failed to get packwiz installer" + exit 1 + fi + + log "Running packwiz installer against URL: ${PACKWIZ_URL}" + if ! java -cp "${packwizInstaller}" link.infra.packwiz.installer.Main "${PACKWIZ_URL}"; then + log "ERROR failed to run packwiz installer" + exit 1 fi fi - log "Running packwiz installer against URL: ${PACKWIZ_URL}" - java -jar "${PACKWIZ_BOOTSTRAP_JAR}" -g -s server "${PACKWIZ_URL}" - #if bootstrap download fails, download installer manually - then run without updating - returnVal=$? - if [[ $returnVal ]]; then - latestPackwizInstaller=$(get_from_gh "https://api.github.com/repos/packwiz/packwiz-installer/releases/latest") - latestPackwizInstallerVer=$(echo "${latestPackwizInstaller}" | jq --raw-output '.tag_name') - latestPackwizInstallerUrl=$(echo "${latestPackwizInstaller}" | jq --raw-output '.assets[] | select(.name | match("packwiz-installer.jar")) | .url') - log "Packwiz couldn't update - Downloading Packwiz Installer ${latestPackwizInstallerVer}" - get_from_gh "${latestPackwizInstallerUrl}" -H "Accept:application/octet-stream" -o "packwiz-installer.jar" - java -jar "${PACKWIZ_BOOTSTRAP_JAR}" -g -bootstrap-no-update -s server "${PACKWIZ_URL}" - fi -fi +} +function handleModpackListOrFile() { # If supplied with a URL for a modpack (simple zip of jars), download it and unpack if [[ "$MODPACK" ]]; then if isURL "${MODPACK}"; then @@ -149,7 +136,9 @@ elif [[ "$MODS_FILE" ]]; then exit 1 fi fi +} +function handleCurseForgeManifest() { if [[ "$MANIFEST" ]]; then if [[ -e "$MANIFEST" ]]; then EFFECTIVE_MANIFEST_FILE=$MANIFEST @@ -192,6 +181,7 @@ case "X$EFFECTIVE_MANIFEST_FILE" in ;; esac fi +} function genericPacks() { : "${GENERIC_PACKS:=${GENERIC_PACK}}" @@ -291,6 +281,12 @@ function modrinthProjects() { fi } +handlePackwiz + +handleModpackListOrFile + +handleCurseForgeManifest + genericPacks modrinthProjects diff --git a/scripts/start-setupMounts b/scripts/start-setupMounts index 6650a38bbb7..c9460b66acb 100755 --- a/scripts/start-setupMounts +++ b/scripts/start-setupMounts @@ -30,7 +30,7 @@ if [ -d /plugins ]; then mkdir -p /data/plugins log "Copying plugins over..." mc-image-helper \ - --debug=${DEBUG} ${subcommand} $updateArg \ + ${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}" \ @@ -46,7 +46,7 @@ fi if [ -d /mods ]; then log "Copying any mods over..." mc-image-helper \ - --debug=${DEBUG} ${subcommand} $updateArg \ + ${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}" \ @@ -59,7 +59,7 @@ fi if [ -d /config ]; then log "Copying any configs from /config to ${COPY_CONFIG_DEST}" mc-image-helper \ - --debug=${DEBUG} ${subcommand} $updateArg \ + ${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}" \ diff --git a/scripts/start-utils b/scripts/start-utils index d2a7f117406..91e3edf1756 100755 --- a/scripts/start-utils +++ b/scripts/start-utils @@ -63,47 +63,27 @@ function getFilenameFromUrl() { } function isTrue() { - local oldState - oldState=$(shopt -po xtrace) - shopt -u -o xtrace - - local value=${1,,} - - result= - - case ${value} in - true | on) - result=0 + local arg="${1?}" + case ${arg,,} in + true | on | 1) + return 0 ;; *) - result=1 + return 1 ;; esac - - eval "$oldState" - return ${result} } function isFalse() { - local oldState - oldState=$(shopt -po xtrace) - shopt -u -o xtrace - - local value=${1,,} - - result= - - case ${value} in - false | off) - result=0 + local arg="${1?}" + case ${arg,,} in + false | off | 0) + return 0 ;; *) - result=1 + return 1 ;; esac - - eval "$oldState" - return ${result} } function isDebugging() { diff --git a/tests/setuponlytests/conflicting_world_for_spigot_server/verify.sh b/tests/setuponlytests/conflicting_world_for_spigot_server/verify.sh index 75daef8d790..9d2f7be4e72 100644 --- a/tests/setuponlytests/conflicting_world_for_spigot_server/verify.sh +++ b/tests/setuponlytests/conflicting_world_for_spigot_server/verify.sh @@ -1,5 +1,7 @@ -mc-image-helper assert fileExists world/level.dat && \ -mc-image-helper assert fileExists world_nether/DIM-1/some_spigot_nether_file && \ -mc-image-helper assert fileExists world_the_end/DIM1/some_spigot_end_file && \ -! mc-image-helper assert fileExists world_nether/DIM-1/some_vanilla_nether_file && \ -! mc-image-helper assert fileExists world_the_end/DIM1/some_vanilla_end_file +mc-image-helper assert fileExists \ + world/level.dat \ + world_nether/DIM-1/some_spigot_nether_file \ + world_the_end/DIM1/some_spigot_end_file +mc-image-helper assert fileNotExists \ + world_nether/DIM-1/some_vanilla_nether_file \ + world_the_end/DIM1/some_vanilla_end_file diff --git a/tests/setuponlytests/packwiz/docker-compose.yml b/tests/setuponlytests/packwiz/docker-compose.yml index 8adf17b2fbf..83610b60057 100644 --- a/tests/setuponlytests/packwiz/docker-compose.yml +++ b/tests/setuponlytests/packwiz/docker-compose.yml @@ -11,11 +11,11 @@ services: image: ${IMAGE_TO_TEST:-itzg/minecraft-server} environment: EULA: "true" - SETUP_ONLY: "true" PACKWIZ_URL: http://web/pack.toml TYPE: CUSTOM CUSTOM_SERVER: /servers/fake.jar VERSION: 1.19 + DEBUG_HELPER: "true" volumes: - ./data:/data - ./fake.jar:/servers/fake.jar diff --git a/tests/setuponlytests/test.sh b/tests/setuponlytests/test.sh index e1b5ffe8491..fb0b439921c 100644 --- a/tests/setuponlytests/test.sh +++ b/tests/setuponlytests/test.sh @@ -39,8 +39,10 @@ setupOnlyMinecraftTest(){ fi fi + # false positive since it's used in delta calculations below + # shellcheck disable=SC2034 start=$(date +%s) - if ! logs=$(docker compose run mc 2>&1); then + if ! logs=$(docker compose run --rm -e SETUP_ONLY=true -e DEBUG="${DEBUG:-false}" mc 2>&1); then outputContainerLog "$logs" result=1 elif [ -f verify.sh ]; then