Skip to content

Commit

Permalink
ioc: prune shared libraries from non-static builds.
Browse files Browse the repository at this point in the history
Shared libraries may be installed either in /opt or /usr/local/lib but
may not be used by the target binaries from the IOC image. Remove them
during the prune phase before copying both directories to resulting
image to shrink the final image size.

A regular expression is needed to filter the existing libraries, as
Solaris configuration files match the trivial ".so*" expression.
  • Loading branch information
henriquesimoes committed Oct 14, 2024
1 parent ce906fe commit b147087
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions base/lnls-prune-artifacts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ set -eu

target_paths=$@

get_linked_libraries() {
targets=$@

executables=$(find $targets -type f -executable -print)

libs="$(ldd $executables 2>/dev/null | grep '=>' | cut -d'=' -f 1)"
for lib in $libs; do
echo ${lib%.so*}.so
done | sort | uniq
}

get_used_epics_modules() {
targets=$@
Expand Down Expand Up @@ -40,6 +50,26 @@ remove_static_libs() {
done
}

remove_unused_shared_libs() {
targets=$@

remove_libs=$(find /opt /usr/local -type f -executable -name *.so* -print)
remove_libs=$(echo "$remove_libs" | grep -E "*.so(.[0-9]+)*$" | sort | uniq)

used_libs=$(get_linked_libraries $targets)

for lib in $used_libs; do
remove_libs=$(echo "$remove_libs" | grep -v $lib)
done

for lib in $remove_libs; do
size=$(du -hs $lib | cut -f 1)

echo "Removing shared library '$lib' ($size)"
rm -f $lib
done
}

remove_unused_epics_modules() {
targets=$@

Expand All @@ -57,3 +87,4 @@ remove_unused_epics_modules() {

remove_unused_epics_modules $target_paths
remove_static_libs /opt
remove_unused_shared_libs $target_paths

0 comments on commit b147087

Please sign in to comment.