Skip to content

Commit

Permalink
Use alpine
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangpengcheng committed May 7, 2024
1 parent c0c37ec commit 0a26bfe
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 61 deletions.
26 changes: 10 additions & 16 deletions images/pulsar-functions-base-runner/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
ARG PULSAR_IMAGE
ARG PULSAR_IMAGE_TAG
FROM ${PULSAR_IMAGE}:${PULSAR_IMAGE_TAG} as pulsar
FROM ubuntu:24.04 as functions-runner
FROM alpine:3.19 as functions-runner

ENV GID=10001
ENV UID=10000
ENV USER=pulsar
RUN groupadd -g $GID pulsar
RUN useradd -u $UID -G pulsar -N -m $USER
RUN addgroup -g $GID pulsar
RUN adduser -u $UID -G pulsar -D -g '' $USER

RUN mkdir -p /pulsar/bin/ \
&& mkdir -p /pulsar/lib/ \
Expand All @@ -28,30 +28,24 @@ RUN echo "VERSION_TAG=${VERSION_TAG}" && \
VERSION_PATCH=$(echo $VERSION_TAG | cut -d. -f3) && \
if [ $VERSION_MAJOR -eq 2 ] && [ $VERSION_MINOR -eq 7 ]; then \
echo "Pulsar version is 2.7, use java 1.8" && \
export JRE_PACKAGE_NAME=openjdk-8-jre-headless; \
export JRE_PACKAGE_NAME=openjdk8; \
elif [ $VERSION_MAJOR -eq 2 ] && [ $VERSION_MINOR -eq 8 ]; then \
echo "Pulsar version is 2.8, use java 1.8" && \
export JRE_PACKAGE_NAME=openjdk-8-jre-headless; \
export JRE_PACKAGE_NAME=openjdk8; \
elif [ $VERSION_MAJOR -eq 2 ] && [ $VERSION_MINOR -eq 9 ]; then \
echo "Pulsar version is 2.9, use java 11" && \
export JRE_PACKAGE_NAME=openjdk-11-jre-headless; \
export JRE_PACKAGE_NAME=openjdk11; \
elif [ $VERSION_MAJOR -eq 2 ] && [ $VERSION_MINOR -eq 10 ]; then \
echo "Pulsar version is 2.10, use java 11" && \
export JRE_PACKAGE_NAME=openjdk-11-jre-headless; \
export JRE_PACKAGE_NAME=openjdk11; \
elif [ $VERSION_MAJOR -eq 2 ] && [ $VERSION_MINOR -eq 11 ]; then \
echo "Pulsar version is 2.11, use java 17" && \
export JRE_PACKAGE_NAME=openjdk-17-jre-headless; \
export JRE_PACKAGE_NAME=openjdk11; \
else \
echo "Pulsar version is not in the list, use java 17 instead" && \
export JRE_PACKAGE_NAME=openjdk-17-jre-headless; \
export JRE_PACKAGE_NAME=openjdk17; \
fi && \
apt-get update \
&& apt-get -y dist-upgrade \
&& apt-get -y install $JRE_PACKAGE_NAME \
&& apt-get -y --purge autoremove \
&& apt-get autoclean \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
apk update && apk add --no-cache $JRE_PACKAGE_NAME bash

COPY --from=pulsar --chown=$UID:$GID /pulsar/conf /pulsar/conf
COPY --from=pulsar --chown=$UID:$GID /pulsar/bin /pulsar/bin
Expand Down
14 changes: 4 additions & 10 deletions images/pulsar-functions-base-runner/pulsarctl.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
ARG PULSAR_IMAGE
ARG PULSAR_IMAGE_TAG
FROM ${PULSAR_IMAGE}:${PULSAR_IMAGE_TAG} as pulsar
FROM ubuntu:24.04 as functions-runner
FROM alpine:3.19 as functions-runner

ENV GID=10001
ENV UID=10000
ENV USER=pulsar
RUN groupadd -g $GID pulsar
RUN useradd -u $UID -G pulsar -N -m $USER
RUN addgroup -g $GID pulsar
RUN adduser -u $UID -G pulsar -D -g '' $USER

RUN mkdir -p /pulsar/bin/ \
&& mkdir -p /pulsar/lib/ \
Expand All @@ -19,13 +19,7 @@ RUN mkdir -p /pulsar/bin/ \
&& mkdir -p /pulsar/examples/ \
&& chown -R $UID:$GID /pulsar \
&& chmod -R g=u /pulsar \
&& apt-get update \
&& apt-get -y dist-upgrade \
&& apt-get -y install wget \
&& apt-get -y --purge autoremove \
&& apt-get autoclean \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* \
&& apk update && apk add --no-cache wget bash \
&& wget https://github.com/streamnative/pulsarctl/releases/latest/download/pulsarctl-amd64-linux.tar.gz -P /pulsar/bin/ \
&& tar -xzf /pulsar/bin/pulsarctl-amd64-linux.tar.gz -C /pulsar/bin/ \
&& rm -rf /pulsar/bin/pulsarctl-amd64-linux.tar.gz \
Expand Down
20 changes: 7 additions & 13 deletions images/pulsar-functions-java-runner/pulsarctl.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,24 @@ RUN echo "VERSION_TAG=${VERSION_TAG}" && \
VERSION_PATCH=$(echo $VERSION_TAG | cut -d. -f3) && \
if [ $VERSION_MAJOR -eq 2 ] && [ $VERSION_MINOR -eq 7 ]; then \
echo "Pulsar version is 2.7, use java 1.8" && \
export JRE_PACKAGE_NAME=openjdk-8-jre-headless; \
export JRE_PACKAGE_NAME=openjdk8; \
elif [ $VERSION_MAJOR -eq 2 ] && [ $VERSION_MINOR -eq 8 ]; then \
echo "Pulsar version is 2.8, use java 1.8" && \
export JRE_PACKAGE_NAME=openjdk-8-jre-headless; \
export JRE_PACKAGE_NAME=openjdk8; \
elif [ $VERSION_MAJOR -eq 2 ] && [ $VERSION_MINOR -eq 9 ]; then \
echo "Pulsar version is 2.9, use java 11" && \
export JRE_PACKAGE_NAME=openjdk-11-jre-headless; \
export JRE_PACKAGE_NAME=openjdk11; \
elif [ $VERSION_MAJOR -eq 2 ] && [ $VERSION_MINOR -eq 10 ]; then \
echo "Pulsar version is 2.10, use java 11" && \
export JRE_PACKAGE_NAME=openjdk-11-jre-headless; \
export JRE_PACKAGE_NAME=openjdk11; \
elif [ $VERSION_MAJOR -eq 2 ] && [ $VERSION_MINOR -eq 11 ]; then \
echo "Pulsar version is 2.11, use java 17" && \
export JRE_PACKAGE_NAME=openjdk-17-jre-headless; \
export JRE_PACKAGE_NAME=openjdk17; \
else \
echo "Pulsar version is not in the list, use java 17 instead" && \
export JRE_PACKAGE_NAME=openjdk-17-jre-headless; \
export JRE_PACKAGE_NAME=openjdk17; \
fi && \
apt-get update \
&& apt-get -y dist-upgrade \
&& apt-get -y install $JRE_PACKAGE_NAME \
&& apt-get -y --purge autoremove \
&& apt-get autoclean \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
apk update && apk add --no-cache $JRE_PACKAGE_NAME

COPY --from=pulsar --chown=$UID:$GID /pulsar/conf /pulsar/conf
COPY --from=pulsar --chown=$UID:$GID /pulsar/bin /pulsar/bin
Expand Down
14 changes: 3 additions & 11 deletions images/pulsar-functions-python-runner/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,15 @@ COPY --from=pulsar --chown=$UID:$GID /pulsar/README /pulsar/cpp-clien* /tmp/puls
RUN if [ -d "/tmp/pulsar/cpp-client" ]; then mv /tmp/pulsar/cpp-client /pulsar/cpp-client || true ; fi

# Install some utilities
RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y python3 python3-dev python3-setuptools python3-yaml python3-kazoo \
libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev curl ca-certificates\
&& apt-get clean autoclean && apt-get autoremove --yes && rm -rf /var/lib/apt/lists/* \
&& mv /usr/lib/python3.12/EXTERNALLY-MANAGED /usr/lib/python3.12/EXTERNALLY-MANAGED.old
RUN apk update \
&& apk add --no-cache python3 python3-dev tk-dev curl ca-certificates\
&& mv /usr/lib/python3.11/EXTERNALLY-MANAGED /usr/lib/python3.11/EXTERNALLY-MANAGED.old

RUN mkdir -p /etc/pki/tls/certs && cp /etc/ssl/certs/ca-certificates.crt /etc/pki/tls/certs/ca-bundle.crt

RUN curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
RUN python3 get-pip.py

RUN update-alternatives --install /usr/bin/python python /usr/bin/python3 10

RUN if [ -d "/pulsar/cpp-client" ]; then apt-get update \
&& apt install -y /pulsar/cpp-client/*.deb \
&& apt-get clean autoclean && apt-get autoremove --yes && rm -rf /var/lib/apt/lists/* ; fi

WORKDIR /pulsar

RUN if [ -f "/pulsar/bin/install-pulsar-client-37.sh" ]; then /pulsar/bin/install-pulsar-client-37.sh || true ; fi
Expand Down
15 changes: 4 additions & 11 deletions images/pulsar-functions-python-runner/pulsarctl.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,13 @@ COPY --from=pulsar --chown=$UID:$GID /pulsar/README /pulsar/pulsar-clien* /pulsa
# Below is a hacky way to copy /pulsar/cpp-client if exist in pulsar image
COPY --from=pulsar --chown=$UID:$GID /pulsar/README /pulsar/cpp-clien* /pulsar/cpp-client/

RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y python3 python3-dev python3-setuptools python3-yaml python3-kazoo \
libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev curl ca-certificates\
&& apt-get clean autoclean && apt-get autoremove --yes && rm -rf /var/lib/apt/lists/* \
RUN apk update \
&& apk add --no-cache python3 python3-dev tk-dev curl ca-certificates\
&& mkdir -p /etc/pki/tls/certs && cp /etc/ssl/certs/ca-certificates.crt /etc/pki/tls/certs/ca-bundle.crt \
&& update-alternatives --install /usr/bin/python python /usr/bin/python3 10 \
&& curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py \
&& mv /usr/lib/python3.12/EXTERNALLY-MANAGED /usr/lib/python3.12/EXTERNALLY-MANAGED.old \
&& mv /usr/lib/python3.11/EXTERNALLY-MANAGED /usr/lib/python3.11/EXTERNALLY-MANAGED.old \
&& python3 get-pip.py && pip3 install --upgrade pip

RUN if [ -d "/pulsar/cpp-client" ]; then apt-get update \
&& apt install -y /pulsar/cpp-client/*.deb || true \
&& apt-get clean autoclean && apt-get autoremove --yes && rm -rf /var/lib/apt/lists/* ; fi

RUN if [ -f "/pulsar/bin/install-pulsar-client-37.sh" ]; then /pulsar/bin/install-pulsar-client-37.sh || pip3 install 'pulsar-client[all]==3.5.0' ; fi
RUN if [ -f "/pulsar/bin/install-pulsar-client.sh" ]; then /pulsar/bin/install-pulsar-client.sh || pip3 install 'pulsar-client[all]==3.5.0' ; fi

Expand All @@ -45,4 +38,4 @@ USER $USER
# a temp solution from https://github.com/apache/pulsar/pull/15846 to fix python protobuf version error
RUN pip3 install protobuf==3.20.1 --user
# to make the python runner could print json logs
RUN pip3 install python-json-logger --user
RUN pip3 install python-json-logger --user

0 comments on commit 0a26bfe

Please sign in to comment.