Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multiarch builds to run on other architectures e.g. Raspberry Pi #58

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 5 additions & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ RUN apt-get update && \
printf "Build of nimmis/spigot:latest, date: %s\n" `date -u +"%Y-%m-%dT%H:%M:%SZ"` > /etc/BUILDS/spigot && \

# install application
apt-get install -y wget git jq && \
apt-get install -y wget git jq libatomic1 && \

# Make special user for minecraft to run in
/usr/sbin/useradd -s /bin/bash -d /minecraft -m minecraft && \
Expand All @@ -57,20 +57,13 @@ RUN apt-get update && \

# get pgp key

# create java directory
mkdir -p /usr/lib/jvm/ && \

# download jdk and unpack in /usr/lib/jvm
curl -L https://github.com/adoptium/temurin${JAVA_VERSION_MAJOR}-binaries/releases/download/jdk-${JAVA_VERSION_MAJOR}.${JAVA_VERSION_MINOR}%2B${JAVA_VERSION_UPDATE}/OpenJDK${JAVA_VERSION_MAJOR}U-jdk_x64_linux_${JAVA_OPT}_${JAVA_VERSION_MAJOR}.${JAVA_VERSION_MINOR}_${JAVA_VERSION_UPDATE}.tar.gz | tar xz -C /usr/lib/jvm/ && \

# set compatible home path
ln -s /usr/lib/jvm/jdk-${JAVA_VERSION_MAJOR}.${JAVA_VERSION_MINOR}+${JAVA_VERSION_UPDATE} /usr/lib/jvm/default-jvm && \
ln -s /usr/lib/jvm/default-jvm/bin/java /usr/bin/java && \


# remove apt cache from image
apt-get clean all

RUN mkdir -p /usr/lib/jvm/ && \

ln -s /usr/lib/jvm/default-jvm/bin/java /usr/bin/java

# expose minecraft port
EXPOSE 25565

Expand Down
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,21 @@ and you should get an output simular to

and the versionlist is updated.

## Building the Docker Image
To build this image for your machine you can simply use the normal docker build command

docker build -t spigot ./

If you want to build this image for multiple architectures you need to use a slightly different set of commands. However this allows you to push a single image from which clients can automatically select the correct architecture.

First set up a binfmt container which allows other architectures to be emulated

docker run --privileged --rm tonistiigi/binfmt --install all

Then build the images and push (docker doesn't currently support loading multi-arch images directly)

docker buildx build --platform linux/amd64,linux/arm/v7,linux/arm64 --tag scratchcat1/minecraft-spigot:latest --push ./

## Old versions news

- Updated java version to 17 which is a LTS version
Expand Down
41 changes: 32 additions & 9 deletions rootfs/usr/local/bin/set_java_ver
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,30 @@
# (c) 2021 nimmis <[email protected]>
#
###########################################################

function get_cpu_arch_for_java () {
cpu_arch_line=$(lscpu | grep Architecture)
case "$cpu_arch_line" in
*x86_64*)
echo "x64"
;;
*armv7*)
echo "arm"
;;
*armv8*) # unconfirmed
echo "aarch64"
;;
*)
echo "Unknown processor architecture. Please file a bug report."
;;
esac
}

function set_java_17 () {
if ! [ -d /usr/lib/jvm/jdk-17* ]; then
echo "Downloading JDK 1.17"
curl -L https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.1%2B12/OpenJDK17U-jdk_x64_linux_hotspot_17.0.1_12.tar.gz | tar xz -C /usr/lib/jvm
CPU_ARCH=$(get_cpu_arch_for_java)
echo "Downloading JDK 1.17 $CPU_ARCH"
curl -L "https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.2%2B8/OpenJDK17U-jdk_${CPU_ARCH}_linux_hotspot_17.0.2_8.tar.gz" | tar xz -C /usr/lib/jvm
fi

echo "set java version to 17"
Expand All @@ -21,8 +41,9 @@ function set_java_17 () {

function set_java_16 () {
if ! [ -d /usr/lib/jvm/jdk-16* ]; then
echo "Downloading JDK 1.16"
curl -L https://github.com/adoptium/temurin16-binaries/releases/download/jdk-16.0.2%2B7/OpenJDK16U-jdk_x64_linux_hotspot_16.0.2_7.tar.gz | tar xz -C /usr/lib/jvm
CPU_ARCH=$(get_cpu_arch_for_java)
echo "Downloading JDK 1.16 $CPU_ARCH"
curl -L "https://github.com/adoptium/temurin16-binaries/releases/download/jdk-16.0.2%2B7/OpenJDK16U-jdk_${CPU_ARCH}_linux_hotspot_16.0.2_7.tar.gz" | tar xz -C /usr/lib/jvm
fi

echo "set java version to 16"
Expand All @@ -33,20 +54,22 @@ function set_java_16 () {

function set_java_11 () {
if ! [ -d /usr/lib/jvm/jdk-11* ]; then
echo "Downloading JDK 1.11"
curl -L https://github.com/adoptium/temurin11-binaries/releases/download/jdk-11.0.13%2B8/OpenJDK11U-jdk_x64_linux_hotspot_11.0.13_8.tar.gz | tar xz -C /usr/lib/jvm
CPU_ARCH=$(get_cpu_arch_for_java)
echo "Downloading JDK 1.11 $CPU_ARCH"
curl -L "https://github.com/adoptium/temurin11-binaries/releases/download/jdk-11.0.14.1%2B1/OpenJDK11U-jdk_${CPU_ARCH}_linux_hotspot_11.0.14.1_1.tar.gz" | tar xz -C /usr/lib/jvm
fi

echo "set java version to 16"
echo "set java version to 11"
rm -f /usr/lib/jvm/default-jvm
ln -s /usr/lib/jvm/jdk-11* /usr/lib/jvm/default-jvm

}

function set_java_8 () {
if ! [ -d /usr/lib/jvm/jdk8* ]; then
echo "Downloading JDK 1.8"
curl -L https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u312-b07/OpenJDK8U-jdk_x64_linux_hotspot_8u312b07.tar.gz | tar xz -C /usr/lib/jvm
CPU_ARCH=$(get_cpu_arch_for_java)
echo "Downloading JDK 1.8 $CPU_ARCH"
curl -L "https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u322-b06/OpenJDK8U-jdk_${CPU_ARCH}_linux_hotspot_8u322b06.tar.gz" | tar xz -C /usr/lib/jvm
fi

echo "set java version to 8"
Expand Down