Add build configuration system and paper image
- Add 'make paper' target to build a Paper image with plugins based on JRE - Introduce dynamic .env and plugins.json configuration using Makefile - Enable users to extend builds by managing their own directories in scratch/ - Implement copy_build_files macro for reproducible build management - Add BUILDKIT_PROGRESS and DOCKER_BUILDKIT as configurable make vars
This commit is contained in:
@@ -7,6 +7,9 @@ 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"
|
||||
@@ -15,7 +18,7 @@ ARG ARTIFACT_PATH="lastSuccessfulBuild/artifact/target/BuildTools.jar"
|
||||
WORKDIR /build
|
||||
|
||||
# Download and build Spigot using BuildTools
|
||||
RUN set -ux && \
|
||||
RUN set -eux && \
|
||||
# Grab latest version if not specified
|
||||
if [ "$VERSION" = "latest" ]; then \
|
||||
VERSION="$( \
|
||||
@@ -38,9 +41,59 @@ RUN set -ux && \
|
||||
# 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" \
|
||||
"$(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
|
||||
|
||||
@@ -51,6 +104,9 @@ 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
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ RUN apt-get update && \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Eclipse Adoptium DEB installer package
|
||||
RUN set -ux && \
|
||||
RUN set -eux && \
|
||||
# Download the Eclipse Adoptium GPG key
|
||||
curl -s https://packages.adoptium.net/artifactory/api/gpg/key/public \
|
||||
| gpg --dearmor | tee /etc/apt/trusted.gpg.d/adoptium.gpg > /dev/null && \
|
||||
@@ -21,7 +21,7 @@ RUN set -ux && \
|
||||
| tee /etc/apt/sources.list.d/adoptium.list
|
||||
|
||||
# Install Adoptium Temurin (OpenJDK/OpenJRE)
|
||||
RUN set -ux && \
|
||||
RUN set -eux && \
|
||||
# Grab latest LTS version if not specified
|
||||
if [ "$JAVA_VERSION" = "latest" ]; then \
|
||||
JAVA_VERSION="$( \
|
||||
|
||||
111
dockerfiles/Dockerfile.paper
Normal file
111
dockerfiles/Dockerfile.paper
Normal file
@@ -0,0 +1,111 @@
|
||||
FROM "${JRE_IMAGE:-localhost/minecraft-jre}":"${JRE_TAG:-latest}"
|
||||
|
||||
# Minecraft version to download
|
||||
ARG VERSION=latest
|
||||
|
||||
# Plugins prefix
|
||||
ARG PREFIX="PLUGIN_"
|
||||
|
||||
# PaperMC base URL
|
||||
ARG BASE_URL="https://api.papermc.io/v2/projects/paper/versions/${VERSION}"
|
||||
|
||||
# Download files
|
||||
USER root
|
||||
WORKDIR /app
|
||||
|
||||
# Download and verify sha256sum for PaperMC server.jar
|
||||
RUN set -eux && \
|
||||
# Grab latest version if not specified
|
||||
if [ "$VERSION" = "latest" ]; then \
|
||||
VERSION="$( \
|
||||
curl -s https://api.papermc.io/v2/projects/paper | \
|
||||
jq -r '.versions[-1]' \
|
||||
)"; \
|
||||
fi && \
|
||||
# Get latest build for the specified version
|
||||
BUILD="$( \
|
||||
curl -s "$BASE_URL" \
|
||||
| jq -r '.builds[-1]' \
|
||||
)" && \
|
||||
URL="${BASE_URL}/builds/${BUILD}/downloads/paper-${VERSION}-${BUILD}.jar" && \
|
||||
curl -s -o /tmp/server.jar "$URL" && \
|
||||
# Get SHA256 hash of server.jar and compare
|
||||
SHA256="$(sha256sum /tmp/server.jar | awk '{print $1}')" && \
|
||||
EXPECTED="$( \
|
||||
curl -s "$BASE_URL/builds/$BUILD" \
|
||||
| jq -r '.downloads.application.sha256' \
|
||||
)" && \
|
||||
if [ ! "$SHA256" = "$EXPECTED" ]; then \
|
||||
echo "[ERROR] SHA256=\"$SHA256\" expected \"$EXPECTED\""; \
|
||||
exit 1; \
|
||||
fi && \
|
||||
mv /tmp/server.jar /app/server.jar
|
||||
|
||||
# Move into a directory just for storing plugins
|
||||
WORKDIR /app/plugins
|
||||
|
||||
# Copy in plugins
|
||||
COPY ../plugins.json /app/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" && \
|
||||
chown minecraft:minecraft /app/plugins/
|
||||
|
||||
# Generate initial settings
|
||||
USER minecraft
|
||||
WORKDIR /app
|
||||
RUN java -jar server.jar --initSettings --nogui
|
||||
|
||||
# Back to root to copy the entrypoint in
|
||||
USER root
|
||||
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"]
|
||||
@@ -8,7 +8,7 @@ USER minecraft
|
||||
WORKDIR /app
|
||||
|
||||
# Download and verify sha1sum for server.jar
|
||||
RUN set -ux && \
|
||||
RUN set -eux && \
|
||||
# Grab latest version if not specified
|
||||
if [ "$VERSION" = "latest" ]; then \
|
||||
VERSION="$( \
|
||||
|
||||
Reference in New Issue
Block a user