Skip to content

Commit

Permalink
[improve][build] Use jlink to custom Java runtime
Browse files Browse the repository at this point in the history
Signed-off-by: Zixuan Liu <[email protected]>
  • Loading branch information
nodece committed May 31, 2024
1 parent 3c76893 commit 3c8deb5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 43 deletions.
27 changes: 18 additions & 9 deletions docker/pulsar/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,20 @@ RUN for SUBDIRECTORY in conf data download logs; do \
# to create those log directories. This should be removed when presto is removed.
RUN chmod g+w /pulsar/lib/presto

FROM eclipse-temurin:11 as jre-build

# Create a custom Java runtime
RUN $JAVA_HOME/bin/jlink \
--add-modules ALL-MODULE-PATH \
--strip-debug \
--no-man-pages \
--no-header-files \
--compress=2 \
--output /javaruntime

RUN echo networkaddress.cache.ttl=1 >> /javaruntime/conf/security/java.security
RUN echo networkaddress.cache.negative.ttl=1 >> /javaruntime/conf/security/java.security

### Create 2nd stage from Ubuntu image
### and add OpenJDK and Python dependencies (for Pulsar functions)

Expand All @@ -72,15 +86,10 @@ RUN sed -i -e "s|http://archive\.ubuntu\.com/ubuntu/|${UBUNTU_MIRROR:-http://arc
#If not upgraded, it will affect the installation of grpcio.
RUN python3 -m pip install --upgrade pip

# Install Eclipse Temurin Package
RUN mkdir -p /etc/apt/keyrings \
&& wget -O - https://packages.adoptium.net/artifactory/api/gpg/key/public | tee /etc/apt/keyrings/adoptium.asc \
&& echo "deb [signed-by=/etc/apt/keyrings/adoptium.asc] https://packages.adoptium.net/artifactory/deb $(awk -F= '/^VERSION_CODENAME/{print$2}' /etc/os-release) main" | tee /etc/apt/sources.list.d/adoptium.list \
&& apt-get update \
&& apt-get -y dist-upgrade \
&& apt-get -y install temurin-11-jdk \
&& export ARCH=$(uname -m | sed -r 's/aarch64/arm64/g' | awk '!/arm64/{$0="amd64"}1') \
&& echo networkaddress.cache.ttl=1 >> /usr/lib/jvm/temurin-11-jdk-$ARCH/conf/security/java.security
# Copy Eclipse Temurin Package
ENV JAVA_HOME=/opt/java/openjdk
ENV PATH="$PATH:$JAVA_HOME/bin"
COPY --from=jre-build /javaruntime $JAVA_HOME

# Cleanup apt
RUN apt-get -y --purge autoremove \
Expand Down
39 changes: 5 additions & 34 deletions tests/docker-images/java-test-image/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,47 +17,22 @@
# under the License.
#

FROM ubuntu:20.04
ARG PULSAR_IMAGE
FROM $PULSAR_IMAGE

RUN groupadd -g 10001 pulsar
RUN adduser -u 10000 --gid 10001 --disabled-login --disabled-password --gecos '' pulsar

ARG PULSAR_TARBALL=target/pulsar-server-distribution-bin.tar.gz
ADD ${PULSAR_TARBALL} /
RUN mv /apache-pulsar-* /pulsar
RUN chown -R root:root /pulsar
# Base pulsar image is designed not be modified, though we need to add more scripts
USER root

COPY target/scripts /pulsar/bin
RUN chmod a+rx /pulsar/bin/*

WORKDIR /pulsar

ARG DEBIAN_FRONTEND=noninteractive
ARG UBUNTU_MIRROR=http://archive.ubuntu.com/ubuntu/

RUN sed -i "s|http://archive\.ubuntu\.com/ubuntu/|${UBUNTU_MIRROR:-mirror://mirrors.ubuntu.com/mirrors.txt}|g" /etc/apt/sources.list \
&& apt-get update \
&& apt-get -y dist-upgrade \
&& apt-get -y install wget apt-transport-https

# Install Eclipse Temurin Package
RUN mkdir -p /etc/apt/keyrings \
&& wget -O - https://packages.adoptium.net/artifactory/api/gpg/key/public | tee /etc/apt/keyrings/adoptium.asc \
&& echo "deb [signed-by=/etc/apt/keyrings/adoptium.asc] https://packages.adoptium.net/artifactory/deb $(awk -F= '/^VERSION_CODENAME/{print$2}' /etc/os-release) main" | tee /etc/apt/sources.list.d/adoptium.list \
&& apt-get update \
&& apt-get -y dist-upgrade \
&& apt-get -y install temurin-11-jdk \
&& export ARCH=$(uname -m | sed -r 's/aarch64/arm64/g' | awk '!/arm64/{$0="amd64"}1') \
&& echo networkaddress.cache.ttl=1 >> /usr/lib/jvm/temurin-11-jdk-$ARCH/conf/security/java.security

# /pulsar/bin/watch-znode.py requires python3-kazoo
# /pulsar/bin/pulsar-managed-ledger-admin requires python3-protobuf
# gen-yml-from-env.py requires python3-yaml
# make python3 the default
RUN apt-get install -y python3-kazoo python3-protobuf python3-yaml \
&& update-alternatives --install /usr/bin/python python /usr/bin/python3 10

RUN apt-get install -y supervisor procps curl less netcat dnsutils iputils-ping
&& apt-get install -y supervisor

RUN mkdir -p /var/log/pulsar \
&& mkdir -p /var/run/supervisor/ \
Expand All @@ -70,10 +45,6 @@ COPY target/ssl /pulsar/ssl/

COPY target/java-test-functions.jar /pulsar/examples/

ENV PULSAR_ROOT_LOGGER=INFO,CONSOLE

RUN chown -R pulsar:0 /pulsar && chmod -R g=u /pulsar

# cleanup
RUN apt-get -y --purge autoremove \
&& apt-get autoclean \
Expand Down

0 comments on commit 3c8deb5

Please sign in to comment.