# Build from OpenJDK image FROM "${JDK_IMAGE:-localhost/minecraft-jdk}":"${JDK_TAG:-latest}" as build # Minecraft version ARG VERSION=latest # Defaults to building Spigot over CraftBukkit ARG SPIGOT=true # Plugins prefix ARG PREFIX="PLUGIN_" # SpigotMC BuildTools URL ARG BASE_URL="https://hub.spigotmc.org/jenkins/job/BuildTools/" ARG ARTIFACT_PATH="lastSuccessfulBuild/artifact/target/BuildTools.jar" # Consider turning bStats (https://bStats.org) on but I'm turning it off by # default because it collects information ARG BSTATS_ENABLED=false # Build in common container location WORKDIR /build # Download and build Spigot using BuildTools RUN set -eux && \ # Grab latest version if not specified if [ "$VERSION" = "latest" ]; then \ VERSION="$( \ curl -s https://launchermeta.mojang.com/mc/game/version_manifest.json \ | jq -r '.latest.release' \ )"; \ fi && \ # Download BuildTools.jar curl -s -o BuildTools.jar "${BASE_URL}${ARTIFACT_PATH}" && \ # Build Craftbukkit if SPIGOT is false case "$SPIGOT" in \ true) \ BUILD_TYPE='SPIGOT' ;; \ false) \ BUILD_TYPE='CRAFTBUKKIT' ;; \ *) \ echo "ERROR: Invalid value for SPIGOT. Set to 'true' or 'false'"; \ exit 1 ;; \ esac && \ # Run BuildTools to build specified version java -jar BuildTools.jar --rev "$VERSION" --compile "$BUILD_TYPE" && \ ln -s \ "$(echo "$BUILD_TYPE" | tr '[:upper:]' '[:lower:]')-${VERSION}.jar" \ "server.jar" # Move into a directory just for storing plugins WORKDIR /plugins # Copy in plugins COPY ../plugins.json /plugins/ # Download defined plugins RUN set -eux && \ # Download defined plugins and check against hash tmp_downloads="$(mktemp -d)" && \ # Iterate over all plugins in plugins.json jq -c '.plugins[]' plugins.json | while read -r PLUGIN; do \ # Set variables from plugins.json name=$(echo "$PLUGIN" | jq -r '.name') && \ version=$(echo "$PLUGIN" | jq -r '.version') && \ # Interpolate instances of '${version}' in the URL url=$(echo "$PLUGIN" | jq -r '.url' | sed "s/\${version}/$version/g") && \ hash=$(echo "$PLUGIN" | jq -r '.hash') && \ info=$(echo "$PLUGIN" | jq -r '.info_url') && \ # Extract hash type and value, e.g., `md5:6f5902ac237024bdd0c176cb93063dc4` hash_type=$(echo "$hash" | cut -d':' -f1) && \ hash_value=$(echo "$hash" | cut -d':' -f2-) && \ # Download and compare the hash tmp_file="${tmp_downloads}/${name}-${version}.jar" && \ curl -s -L "$url" -o "${tmp_file}" && \ case "$hash_type" in \ sha256) \ echo "${hash_value} $tmp_file" | sha256sum -c - || { \ echo "SHA256 hash mismatch for ${name}-${version}.jar"; \ rm -rf "$tmp_downloads"; \ exit 1; \ } \ ;; \ md5) \ echo "${hash_value} $tmp_file" | md5sum -c - || { \ echo "MD5 hash mismatch for ${name}-${version}.jar"; \ rm -rf "$tmp_downloads"; \ exit 1; \ } \ ;; \ *) \ echo "Unsupported hash type: ${hash_type}"; \ rm -rf "$tmp_downloads"; \ exit 1; \ ;; \ esac && \ mv "$tmp_file" "${name}-${version}.jar"; \ done && \ rm -rf "$tmp_downloads" # Use OpenJRE image for runtime FROM "${JRE_IMAGE:-localhost/minecraft-jre}":"${JRE_TAG:-latest}" as runtime # Run as Minecraft user USER minecraft WORKDIR /app # Copy the built bukkit jar from the build stage COPY --from=build /build/server.jar /app/server.jar # Copy in plugins COPY --from=build /plugins/ /app/plugins/ # Generate initial settings RUN java -jar server.jar --initSettings --nogui && \ # Disable bStats by default if [ "$BSTATS_ENABLED" = "false" ]; then \ mkdir -p /app/plugins/bStats/ && \ echo "enabled: false" > /app/plugins/bStats/config.yml; \ fi # Back to root to copy the entrypoint in USER root WORKDIR /app # Copy in entrypoint script COPY ../entrypoint.sh /usr/local/bin/entrypoint.sh RUN chmod +x /usr/local/bin/entrypoint.sh # Run app as minecraft user USER minecraft WORKDIR /app # Expose port and run entrypoint script EXPOSE 25565 ENTRYPOINT ["entrypoint.sh"]