[Java] 基于Debian和SDKMan制作Java GraalVM 基础编译镜像

debian上安装可以用来编译GraalVM的工具镜像,因为GraalVM编译出二进制可执行文件, 被用作中间编译工具(Docker From),用完就丢,编译出的二进制放入alpine或者bellsoft的librca,2款镜像体积小,有特别优化.

FROM debian:stable-slim
# 替换为aliyun 源
# RUN sed -i s/archive.ubuntu.com/mirrors.aliyun.com/g /etc/apt/sources.list && \
# sed -i s/security.ubuntu.com/mirrors.aliyun.com/g /etc/apt/sources.list && \
# sed -i s/cn.archive.ubuntu.com/mirrors.aliyun.com/g /etc/apt/sources.list && \
# sed -i s/ports.ubuntu.com/mirrors.aliyun.com/g /etc/apt/sources.list && \
# sed -i s/deb.debian.org/mirrors.aliyun.com/g /etc/apt/sources.list

RUN apt update 
RUN apt install -y libssl-dev \
    autoconf \
    re2c \
    bison \
    libsqlite3-dev \
    libpq-dev \
    libonig-dev \
    libfcgi-dev \
    libfcgi0ldbl \
    libjpeg-dev \
    libpng-dev \
    libssl-dev \
    libxml2-dev \
    libcurl4-openssl-dev \
    libxpm-dev \
    libgd-dev \
    libmariadb-dev \
    libfreetype6-dev \
    libxslt1-dev \
    libpspell-dev \
    libzip-dev \
    libgccjit-10-dev \
    zlib1g-dev libz-dev lib32z1-dev \
    zip unzip curl wget \
    build-essential && \
	rm -rf /var/lib/apt/lists/* && \
	rm -rf /tmp/*

RUN curl -s "https://get.sdkman.io" | bash


ENV SDK_MAN=/root/.sdkman
ENV SDK_MAN_CAN=${SDK_MAN}/candidates
ARG JAVA_VERSION="23.1.1.r21-nik"

RUN bash -c "source ${SDK_MAN}/bin/sdkman-init.sh && \
    yes | sdk install java $JAVA_VERSION &&  \
    yes | sdk use java $JAVA_VERSION && \
    yes | sdk default java $JAVA_VERSION && \
    yes | sdk install maven && \
    yes | sdk install gradle && \
    rm -rf ${SDK_MAN}/archives/* && \
    rm -rf ${SDK_MAN}/tmp/*"
    
ENV JAVA_HOME=${SDK_MAN_CAN}/java/current
ENV PATH="${PATH}:${SDK_MAN_CAN}/gradle/current/bin/"
ENV PATH="${PATH}:${SDK_MAN_CAN}/maven/current/bin/"

# Create appuser
ENV USER=app
ENV UID=10001

RUN adduser \
    --disabled-password \
    --gecos "" \
    --home "/nonexistent" \
    --shell "/sbin/nologin" \
    --no-create-home \
    --uid "${UID}" \
    "${USER}"