From 667709b52663c129c10dfc1a3379f320161c88ed Mon Sep 17 00:00:00 2001 From: nyyu Date: Sun, 30 Mar 2025 09:52:32 +0200 Subject: [PATCH] feat: init --- Dockerfile_base | 54 ++++++++++++++++++++++++++++++++++++++++++++++ Dockerfile_java | 36 +++++++++++++++++++++++++++++++ build.sh | 11 ++++++++++ rootdir/etc/group | 3 +++ rootdir/etc/passwd | 3 +++ 5 files changed, 107 insertions(+) create mode 100644 Dockerfile_base create mode 100644 Dockerfile_java create mode 100755 build.sh create mode 100644 rootdir/etc/group create mode 100644 rootdir/etc/passwd diff --git a/Dockerfile_base b/Dockerfile_base new file mode 100644 index 0000000..31e2f9b --- /dev/null +++ b/Dockerfile_base @@ -0,0 +1,54 @@ +# Stage 1: Build the base system +FROM busybox:1.37.0 AS builder + +# Set working directory +WORKDIR /build + +# Define build arguments +ARG BASE_FILES_VERSION=13.7 +ARG LIBGCC_VERSION=14.2.0-19 +ARG GLIBC_VERSION=2.41-6 +ARG TZDATA_VERSION=2025b-1 + +# Download required Debian packages +RUN wget -q \ + https://ftp.debian.org/debian/pool/main/b/base-files/base-files_${BASE_FILES_VERSION}_amd64.deb \ + https://ftp.debian.org/debian/pool/main/g/gcc-14/libgcc-s1_${LIBGCC_VERSION}_amd64.deb \ + https://ftp.debian.org/debian/pool/main/g/glibc/libc6_${GLIBC_VERSION}_amd64.deb \ + https://ftp.debian.org/debian/pool/main/g/glibc/libc-bin_${GLIBC_VERSION}_amd64.deb \ + https://ftp.debian.org/debian/pool/main/t/tzdata/tzdata_${TZDATA_VERSION}_all.deb + +# Extract and clean up the downloaded packages +RUN mkdir -p var/lib/dpkg && \ + for deb in *.deb; do \ + echo "Processing $deb" && \ + ar x $deb control.tar.xz data.tar.xz && \ + tar xf data.tar.xz && tar xf control.tar.xz ./control && \ + (cat control; echo) >> var/lib/dpkg/status && \ + rm -f $deb control.tar.xz data.tar.xz control; \ + done && \ + # Create a non-root user directory + mkdir -p /home/nonroot && \ + chown 65532:65532 /home/nonroot && \ + # Copy nsswitch.conf for proper name resolution + cp usr/share/libc-bin/nsswitch.conf etc/nsswitch.conf && \ + # Remove unnecessary files to reduce image size + rm -rf usr/bin usr/sbin usr/share/base-files usr/share/common-licenses usr/share/doc \ + usr/share/libc-bin usr/share/lintian usr/share/man usr/lib/x86_64-linux-gnu/gconv && \ + find usr/share/zoneinfo ! -name "Paris" ! -name "UTC" ! -name "New_York" -delete + +# Stage 2: Temporary scratch image +FROM scratch AS tmp + +# Copy root directory and extracted files from the builder stage +COPY rootdir/ / +COPY --from=builder /build/ / + +# Stage 3: Final minimal image +FROM scratch + +# Set environment variables +ENV LANG=C.utf8 + +# Copy everything from the temporary stage +COPY --from=tmp / / diff --git a/Dockerfile_java b/Dockerfile_java new file mode 100644 index 0000000..7391611 --- /dev/null +++ b/Dockerfile_java @@ -0,0 +1,36 @@ +# Define build arguments +ARG JAVA_VERSION=21.0.6+7 + +FROM busybox:1.37.0 AS builder + +# Set working directory +WORKDIR /build + +# Define build arguments +ARG JAVA_VERSION +ARG JAVA_HOME=opt/java/openjdk + +# Download and extract OpenJDK +RUN MAJOR=$(echo ${JAVA_VERSION} | cut -d'.' -f1) && \ + VERSION_UNDERSCORE=$(echo ${JAVA_VERSION} | sed 's/+/_/') && \ + wget -q https://github.com/adoptium/temurin${MAJOR}-binaries/releases/download/jdk-${JAVA_VERSION}/OpenJDK${MAJOR}U-jre_x64_linux_hotspot_${VERSION_UNDERSCORE}.tar.gz && \ + mkdir -p $JAVA_HOME && \ + tar xf OpenJDK${MAJOR}U-jre_x64_linux_hotspot_${VERSION_UNDERSCORE}.tar.gz -C $JAVA_HOME --strip-components 1 --no-same-owner && \ + rm -rf $JAVA_HOME/legal OpenJDK${MAJOR}U-jre_x64_linux_hotspot_${VERSION_UNDERSCORE}.tar.gz + +# Use a minimal base image +FROM base + +# Define build arguments +ARG JAVA_VERSION + +# Set environment variables +ENV JAVA_HOME=/opt/java/openjdk +ENV JAVA_VERSION=$JAVA_VERSION +ENV PATH=$JAVA_HOME/bin:$PATH + +# Copy Java runtime from the builder stage +COPY --from=builder /build / + +# Set the default command +ENTRYPOINT ["java"] \ No newline at end of file diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..2b493ad --- /dev/null +++ b/build.sh @@ -0,0 +1,11 @@ +#!/bin/sh +set -e + +docker build -t base -f Dockerfile_base . +docker run --rm -it --entrypoint /lib64/ld-linux-x86-64.so.2 base --version + +#docker build --build-arg JAVA_VERSION=17.0.14+7 -t java17 -f Dockerfile.java . +#docker run --rm -it java17 java --version + +docker build -t java21 -f Dockerfile_java . +docker run --rm -it java21 --version diff --git a/rootdir/etc/group b/rootdir/etc/group new file mode 100644 index 0000000..bca0870 --- /dev/null +++ b/rootdir/etc/group @@ -0,0 +1,3 @@ +root:x:0: +nobody:x:65534: +nonroot:x:65532: \ No newline at end of file diff --git a/rootdir/etc/passwd b/rootdir/etc/passwd new file mode 100644 index 0000000..9484cf6 --- /dev/null +++ b/rootdir/etc/passwd @@ -0,0 +1,3 @@ +root:x:0:0:root:/root:/sbin/nologin +nobody:x:65534:65534:nobody:/nonexistent:/sbin/nologin +nonroot:x:65532:65532:nonroot:/home/nonroot:/sbin/nologin \ No newline at end of file