From bbaec307523a26d2f8f0e8f852e505b3dbed0699 Mon Sep 17 00:00:00 2001 From: uzurka Date: Sun, 13 Aug 2023 18:29:37 +0200 Subject: [PATCH] first commit --- Dockerfile | 126 ++++++++++++++++++++++++++++++++++++++++++++++ _bashrc | 13 +++++ _docker-java-home | 3 ++ _entrypoint.sh | 54 ++++++++++++++++++++ build.sh | 55 ++++++++++++++++++++ platform.sh | 19 +++++++ 6 files changed, 270 insertions(+) create mode 100644 Dockerfile create mode 100644 _bashrc create mode 100644 _docker-java-home create mode 100644 _entrypoint.sh create mode 100644 build.sh create mode 100644 platform.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..64f22b7 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,126 @@ +# ---------------------------------- +# Pterodactyl Core Dockerfile +# Environment: Java +# Minimum Panel Version: 1.7.0 +# ---------------------------------- +# Copyright (c) 2021 Matthew Penner +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# ---------------------------------- + +# 2023-08-09 + +FROM --platform=linux/amd64 debian:stable-slim + +ARG TARGETPLATFORM +ARG TARGETOS +ARG TARGETARCH +ARG BUILDPLATFORM +ARG BUILDOS +ARG BUILDARCH +ARG BUILDVARIANT + +ARG GRAALVERSION +ARG SDKMAN +ARG GRAALVM_YEAR_VERSION +ARG GRAALVM_MAJOR_VERSION +ARG GRAALVM_MINOR_VERSION +ARG JAVA_VERSION +ARG JAVA_HOME + +COPY platform.sh . +RUN ./platform.sh + +SHELL ["/bin/bash", "-c"] + +LABEL org.opencontainers.image.title "GraalVM Enterprise Edition" +LABEL org.opencontainers.image.authors "GraalVM Sustaining Team " +LABEL org.opencontainers.image.description "GraalVM is a universal virtual machine for running applications written in JavaScript, Python, Ruby, R, JVM-based languages like Java, Scala, Clojure, Kotlin, and LLVM-based languages such as C and C++." + +LABEL com.centurylinklabs.watchtower.enable false +LABEL org.opencontainers.image.licenses MIT + +LABEL author "Olivier Le Bris" +LABEL maintainer "tech@zogg.fr" +LABEL org.opencontainers.image.source "https://zogg.fr" + +ENV GRAALVERSION $GRAALVERSION +ENV LANG C.UTF-8 +ENV GRAALVM_YEAR_VERSION $GRAALVM_YEAR_VERSION +ENV GRAALVM_MAJOR_VERSION $GRAALVM_MAJOR_VERSION +ENV GRAALVM_MINOR_VERSION $GRAALVM_MINOR_VERSION +ENV JAVA_VERSION $JAVA_VERSION +ENV JAVA_HOME $JAVA_HOME +ENV PATH $JAVA_HOME/bin:${PATH} + +USER root +WORKDIR / + +# Install neccessary packages +RUN set -eux \ + && apt update \ + && apt full-upgrade -y \ + && apt install curl ca-certificates p11-kit openssl tar sqlite3 fontconfig tzdata iproute2 libstdc++-11-dev bash wget zip unzip -y \ + && apt autoremove -y + +# Setup 'container' user and group (with home folder) +RUN useradd -d /home/container -m container -s /bin/bash -p 'none' \ + && passwd -d container + +# Install SDKMAN! and GraalVM specified version +RUN curl -s "https://get.sdkman.io" | bash \ + && source "$SDKMAN/bin/sdkman-init.sh" \ + && sdk install java $GRAALVERSION + +# Copy GraalVM files to destination folder +RUN mkdir -p /opt/graalvm \ + && cp -rf $SDKMAN/candidates/java/$GRAALVERSION/. /opt/graalvm/ \ + && chown -R container:container /opt/graalvm + +# Setup GraalVM as default Java interpreter +USER root +WORKDIR /app +RUN mkdir -p /usr/java \ + && ln -sf /opt/graalvm /usr/java/default \ + && ln -sf /opt/graalvm /usr/java/latest \ + && for bin in "/opt/graalvm/bin/"*; do base="$(basename "$bin")"; \ + [ ! -e "/usr/bin/$base" ]; \ + update-alternatives --install "/usr/bin/$base" "$base" "$bin" 20000; \ + done + +# Uninstall SDKMAN! and do some cleanup +USER root +WORKDIR / +RUN source "$SDKMAN/bin/sdkman-init.sh" \ + && sdk uninstall java $GRAALVERSION --force \ + && sdk flush \ + && rm -rf $SDKMAN \ + && apt autoremove -y + +# Setup Pterodactyl necessary context +USER container +WORKDIR /home/container +ENV USER container +ENV HOME /home/container +COPY files/docker-java-home /usr/local/bin/docker-java-home +COPY files/bashrc /home/container/.bashrc +COPY files/entrypoint.sh /entrypoint.sh + +# Run Pterodactyl entrypoint +CMD ["/bin/bash", "/entrypoint.sh"] diff --git a/_bashrc b/_bashrc new file mode 100644 index 0000000..706a826 --- /dev/null +++ b/_bashrc @@ -0,0 +1,13 @@ +# 2023-08-09 + +export PS1='\n\[\e[32m\]\u@\h: \[\e[33m\]\w\[\e[0m\]\n> ' +export BASH=/bin/bash +export SHELL=$BASH + +export LS_OPTIONS='--color=auto' +alias ls='ls $LS_OPTIONS' +alias ll='ls $LS_OPTIONS -l' +alias la='ls $LS_OPTIONS -la' + +export JAVA_HOME=/opt/graalvm +export PATH=$JAVA_HOME/bin:$PATH diff --git a/_docker-java-home b/_docker-java-home new file mode 100644 index 0000000..12163bf --- /dev/null +++ b/_docker-java-home @@ -0,0 +1,3 @@ +#/bin/sh +# 2023-08-09 +echo $JAVA_HOME diff --git a/_entrypoint.sh b/_entrypoint.sh new file mode 100644 index 0000000..a65a0a0 --- /dev/null +++ b/_entrypoint.sh @@ -0,0 +1,54 @@ +#!/bin/bash +# 2023-08-09 + +# +# Copyright (c) 2021 Matthew Penner +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# + +# Default the TZ environment variable to UTC. +TZ=${TZ:-UTC} +export TZ + +# Set environment variable that holds the Internal Docker IP +INTERNAL_IP=$(ip route get 1 | awk '{print $NF;exit}') +export INTERNAL_IP + +# Switch to the container's working directory +cd /home/container || exit 1 + +# Display Specifics +printf ">>> [ GraalVM AMD64 Image ] <<<\n" + +# Print Java version +printf "\033[1m\033[33mcontainer@pterodactyl~ \033[0mjava -version\n" +java -version + +# Convert all of the "{{VARIABLE}}" parts of the command into the expected shell +# variable format of "${VARIABLE}" before evaluating the string and automatically +# replacing the values. +PARSED=$(echo "${STARTUP}" | sed -e 's/{{/${/g' -e 's/}}/}/g' | eval echo "$(cat -)") + +# Display the command we're running in the output, and then execute it with the env +# from the container itself. +printf "\033[1m\033[33mcontainer@pterodactyl~ \033[0m%s\n" "$PARSED" + +# shellcheck disable=SC2086 +exec env ${PARSED} diff --git a/build.sh b/build.sh new file mode 100644 index 0000000..3836927 --- /dev/null +++ b/build.sh @@ -0,0 +1,55 @@ +#!/bin/bash +# 2023-08-09 +# ---------------------------------- +# Pterodactyl Core Dockerfile Builder +# Environment: Java / GraalVM +# Minimum Panel Version: 1.7.0 +# ---------------------------------- + +clear +cd "$(dirname "$0")" || exit 1 + +# Define what version of GraalVM +GRAALVM_YEAR_VERSION=20 +GRAALVM_MAJOR_VERSION=0 +GRAALVM_MINOR_VERSION=2 +JAVA_VERSION=20 +JAVA_HOME=/opt/graalvm + +# Setup for SDKMAN! +GRAALVERSION=$GRAALVM_YEAR_VERSION.$GRAALVM_MAJOR_VERSION.$GRAALVM_MINOR_VERSION-graal +SDKMAN=/root/.sdkman + +# Docker image name and version +IMAGE_BASE=zogg/graalvm +IMAGE_NAME_LATEST=${IMAGE_BASE}:latest + +# Update GraalVM version in relevant files +find="GRAALVERSION" +replace="$GRAALVERSION" +sed "s/${find}/${replace}/g" files/_bashrc > files/bashrc +sed "s/${find}/${replace}/g" files/_docker-java-home > files/docker-java-home +sed "s/${find}/${replace}/g" files/_entrypoint.sh > files/entrypoint.sh + +# Prepare for cross compile +export DOCKER_DEFAULT_PLATFORM=linux/amd64 +export DOCKER_CLI_EXPERIMENTAL=enabled +docker run --privileged --rm tonistiigi/binfmt --install all + +# Build with no caching disabled +docker buildx build --pull --no-cache \ + --platform=linux/amd64 \ + --output=type=docker \ + --build-arg TZ=Europe/Paris \ + --build-arg CONCURRENCY=$(nproc) \ + --build-arg GRAALVERSION=${GRAALVERSION} \ + --build-arg SDKMAN=${SDKMAN} \ + --build-arg GRAALVM_YEAR_VERSION=${GRAALVM_YEAR_VERSION} \ + --build-arg GRAALVM_MAJOR_VERSION=${GRAALVM_MAJOR_VERSION} \ + --build-arg GRAALVM_MINOR_VERSION=${GRAALVM_MINOR_VERSION} \ + --build-arg JAVA_VERSION=${JAVA_VERSION} \ + --build-arg JAVA_HOME=${JAVA_HOME} \ + -t "${IMAGE_NAME_LATEST}" \ + . 2>&1 | tee build.log + +exit 0 diff --git a/platform.sh b/platform.sh new file mode 100644 index 0000000..607ef99 --- /dev/null +++ b/platform.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +# Used in Docker build to set platform dependent variables + +case $TARGETARCH in + + "amd64") + echo "x86_64-unknown-linux-gnu" > /.platform + echo "" > /.compiler + ;; + "arm64") + echo "aarch64-unknown-linux-gnu" > /.platform + echo "gcc-aarch64-linux-gnu" > /.compiler + ;; + "arm") + echo "armv7-unknown-linux-gnueabihf" > /.platform + echo "gcc-arm-linux-gnueabihf" > /.compiler + ;; +esac