diff --git a/fabric/Dockerfile b/fabric/Dockerfile new file mode 100644 index 0000000..81e707b --- /dev/null +++ b/fabric/Dockerfile @@ -0,0 +1,25 @@ +FROM alpine:latest + +ENV UID=1000 +ENV GID=1000 + +ARG JAVA=openjdk17 +RUN apk add --upgrade sudo shadow $JAVA curl jq + +ADD ./bin /usr/local/bin + +RUN useradd minecraft + +RUN mkdir /minecraft && chown -R minecraft /minecraft + +VOLUME ["/minecraft"] + +WORKDIR /minecraft + +EXPOSE 25565 + +ARG MC_VERSION +ENV MC_VERSION=${MC_VERSION:-1.19.4} + +ENTRYPOINT ["setup"] +CMD ["java", "-Xmx2G", "-Xms2G", "-jar", "fabric.jar"] diff --git a/fabric/bin/configure_and_start b/fabric/bin/configure_and_start new file mode 100755 index 0000000..ddfeb19 --- /dev/null +++ b/fabric/bin/configure_and_start @@ -0,0 +1,43 @@ +#!/bin/sh + +meta_dir="docker_meta" + +if test ! -f "$meta_dir/config_done"; then + download_fabricproxy + + mkdir -p config + config_path="config/FabricProxy-Lite.toml" + + config="" + + if test "$VELOCITY_ENABLE" = "true"; then + echo "online-mode=false" > server.properties + + velocity=$(cat << EOF +secret = "$VELOCITY_SECRET" +EOF + ) + + config="${config}${velocity}" + fi + + if test ! -z "$config"; then + echo "Writing config to $config_path" + echo "$config" > $config_path + fi + + echo "eula=true" > eula.txt + + mkdir -p "$meta_dir" && touch "$meta_dir/config_done" +else + echo "Configuration is done" +fi + +if test ! -f "fabric.jar" -o "$FABRIC_UPDATE_ON_START" == "true"; then + update_fabric +else + echo "Skipping Fabric download" +fi + +echo "> $@" +exec "$@" diff --git a/fabric/bin/download_fabricproxy b/fabric/bin/download_fabricproxy new file mode 100755 index 0000000..45e2e2b --- /dev/null +++ b/fabric/bin/download_fabricproxy @@ -0,0 +1,15 @@ +#!/bin/sh + +version=$MC_VERSION +echo "Downloading FabricProxy for version $version" + +apiURL="https://api.modrinth.com/v2/project/fabricproxy-lite/version?loaders=%5B%22fabric%22%5D&game_versions=%5B%22$version%22%5D" + +url=$(curl -X GET "$apiURL" | jq -r ".[0].files[0].url") +echo "FabricProxy download URL: $url" + +modFolder=$PWD/mods +mkdir -p "$modFolder" + +echo "Downloading to $modFolder" +wget -O "$modFolder/FabricProxy.jar" "$url" diff --git a/fabric/bin/setup b/fabric/bin/setup new file mode 100755 index 0000000..867c73b --- /dev/null +++ b/fabric/bin/setup @@ -0,0 +1,12 @@ +#!/bin/sh + +if test "$EULA" != "true"; then + echo "You need to accept the Mojang EULA (using -e EULA=true) to run the server" + exit 1 +fi + +usermod -u $UID minecraft +groupmod -g $GID minecraft +chown -R minecraft:minecraft /minecraft + +exec sudo -E -u minecraft configure_and_start "$@" diff --git a/fabric/bin/update_fabric b/fabric/bin/update_fabric new file mode 100755 index 0000000..4df3d31 --- /dev/null +++ b/fabric/bin/update_fabric @@ -0,0 +1,18 @@ +#!/bin/sh + +version=$MC_VERSION +echo "Updating Fabric version $version" + +apiURL=https://meta.fabricmc.net/v2/versions + +latestLoader=$(curl -X GET "$apiURL/loader" | jq -r ".[0].version") +echo "Latest loader: $latestLoader" + +latestInstaller=$(curl -X GET "$apiURL/installer" | jq -r ".[0].version") +echo "Latest installer: $latestInstaller" + +url="$apiURL/loader/$version/$latestLoader/$latestInstaller/server/jar" +echo "Full URL is: $url" + +echo "Downloading to $PWD" +wget -O fabric.jar "$url" diff --git a/fabric/build_all_versions.sh b/fabric/build_all_versions.sh new file mode 100755 index 0000000..99da5e3 --- /dev/null +++ b/fabric/build_all_versions.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +#!/bin/sh + +declare -A versions +#versions["1.8.8"]="openjdk8" +#versions["1.9.4"]="openjdk8" +#versions["1.10.2"]="openjdk8" +#versions["1.11.2"]="openjdk8" +#versions["1.12.2"]="openjdk8" +#versions["1.13.2"]="openjdk8" +versions["1.14.4"]="openjdk8" +versions["1.15.2"]="openjdk8" +versions["1.16.5"]="openjdk8" +versions["1.17.1"]="openjdk8" +versions["1.18.2"]="openjdk17" +versions["1.19.4"]="openjdk17" + +for version in "${!versions[@]}"; do + java=${versions[$version]} + echo "Building version $version, JAVA=$java" + docker build --build-arg MC_VERSION=$version --build-arg JAVA=$java -t mrletsplay/fabric:$version . +done