Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[improve] Removed unnecessary native libraries from Docker images #22230

Merged
merged 2 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion docker/pulsar/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,19 @@
#

# First create a stage with just the Pulsar tarball and scripts
FROM busybox as pulsar
FROM alpine as pulsar

RUN apk add zip

ARG PULSAR_TARBALL

ADD ${PULSAR_TARBALL} /
RUN mv /apache-pulsar-* /pulsar
RUN rm -rf /pulsar/bin/*.cmd

COPY build-scripts /build-scripts/
RUN /build-scripts/remove-unnecessary-native-binaries.sh

COPY scripts/* /pulsar/bin/

# The final image needs to give the root group sufficient permission for Pulsar components
Expand Down
51 changes: 51 additions & 0 deletions docker/pulsar/build-scripts/remove-unnecessary-native-binaries.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env sh
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#

set -e

# Retain only native libraries for the architecture of this
# image
ARCH=$(uname -m)

# Remove extra binaries for Netty TCNative
if [ "$ARCH" = "aarch64" ]
then
TC_NATIVE_TO_KEEP=linux-aarch_64
else
TC_NATIVE_TO_KEEP=linux-$ARCH
fi
ls /pulsar/lib/io.netty-netty-tcnative-boringssl-static*Final-*.jar | grep -v $TC_NATIVE_TO_KEEP | xargs rm

# Prune extra libs from RocksDB JAR
mkdir /tmp/rocksdb
cd /tmp/rocksdb
ROCKSDB_JAR=$(ls /pulsar/lib/org.rocksdb-rocksdbjni-*.jar)
unzip $ROCKSDB_JAR > /dev/null

if [ "$ARCH" = "x86_64" ]
then
ROCKSDB_TO_KEEP=linux64-musl
else
ROCKSDB_TO_KEEP=linux-$ARCH-musl
fi

ls librocksdbjni-* | grep -v librocksdbjni-${ROCKSDB_TO_KEEP}.so | xargs rm
rm $ROCKSDB_JAR
zip -r -9 $ROCKSDB_JAR * > /dev/null
Loading