11ARG ARCH=amd64
2- # Image for dependencies such as NFS binaries
32ARG DEPS_IMAGE=alpine:3
43
54FROM --platform=linux/${ARCH} $DEPS_IMAGE AS deps
@@ -11,31 +10,74 @@ ARG CHWRAP_BIN=chwrap.tar
1110ARG NODE_PREP_BIN=node_prep
1211ARG SYSWRAP_BIN=syswrap
1312
14- # Installs nfs-utils based on DEPS_IMAGE
13+ ARG BIN_ALLOWLIST="\
14+ /bin/mount \
15+ /bin/umount \
16+ /sbin/mount.nfs \
17+ /sbin/mount.nfs4 \
18+ "
19+
20+ ARG FILE_ALLOWLIST="\
21+ /etc/os-release \
22+ /etc/netconfig \
23+ /etc/protocols \
24+ /etc/ssl/certs/* \
25+ /var/lib/rpm/rpmdb.sqlite \
26+ "
27+
28+ # Install dependencies based on DEPS_IMAGE
1529RUN --mount=type=secret,id=activation_key,env=ACTIVATION_KEY \
1630 --mount=type=secret,id=organization,env=ORGANIZATION \
1731 function unregister() { subscription-manager unregister || true; }; trap unregister EXIT; \
1832 if [[ $DEPS_IMAGE =~ "alpine" ]]; \
1933 then apk add --no-scripts nfs-utils; \
2034 else subscription-manager register --activationkey $ACTIVATION_KEY --org $ORGANIZATION && \
21- yum install --repo=rhel-9-*-baseos-rpms -y nfs-utils || { cat /var/log/rhsm/rhsm.log; exit 1; } \
22- fi;
35+ dnf install \
36+ --repo=rhel-9-*-baseos-rpms -y \
37+ --setopt=tsflags=noscripts \
38+ nfs-utils || { cat /var/log/rhsm/rhsm.log; exit 1; } \
39+ fi
40+
41+ # Get dynamic libs for allowed binaries
42+ RUN for bin in $BIN_ALLOWLIST; do \
43+ ldd $bin | tr -s '[:space:]' '\n ' | grep '^/' ; \
44+ done | sort | uniq > /tmp/ld_allowlist.txt
2345
24- # Copy dependencies to the root filesystem
25- RUN for dep in /bin/mount /bin/umount /sbin/mount.nfs /sbin/mount.nfs4 /etc/netconfig /etc/protocols /etc/ssl/certs/*; do \
26- mkdir -p /rootfs/$(dirname $dep) && cp -L $dep /rootfs/$dep; \
46+ # Minimize RPM database
47+ RUN if [[ $DEPS_IMAGE =~ "alpine" ]]; then exit 0; fi; \
48+ for f in $BIN_ALLOWLIST $FILE_ALLOWLIST $(cat /tmp/ld_allowlist.txt); do \
49+ rpm -qf $f; \
50+ done | sort | uniq > /tmp/rpm_allowlist.txt; \
51+ rpm --justdb -e --nodeps $(rpm -qa | grep -v -f /tmp/rpm_allowlist.txt)
52+
53+ # Copy required files to rootfs
54+ RUN for f in $BIN_ALLOWLIST $FILE_ALLOWLIST $(cat /tmp/ld_allowlist.txt); do \
55+ if [ -e "$f" ]; then \
56+ dest="/rootfs${f}" ; \
57+ mkdir -p "$(dirname " $dest")" ; \
58+ cp -a "$f" "$dest" ; \
59+ fi; \
2760 done
2861
29- # Copy NFS dependencies to the root filesystem
30- RUN for bin in /sbin/mount.nfs /sbin/mount.nfs4; do \
31- ldd $bin | tr -s '[:space:]' '\n ' | grep '^/' | xargs -I % sh -c 'mkdir -p /rootfs/$(dirname %) && cp -L % /rootfs/%' ; \
62+ # Copy symlink targets to rootfs
63+ RUN find /rootfs -type l | while read -r link; do \
64+ target="$(readlink $link)" ; \
65+ if [[ "$target" =~ ^/ ]]; then \
66+ dest="/rootfs$target" ; \
67+ else \
68+ dest="$(dirname $link)/$target" ; \
69+ target=${dest#"/rootfs" }; \
70+ fi; \
71+ mkdir -p "$(dirname $dest)" ; \
72+ cp -a "$target" "$dest" ; \
3273 done
3374
3475COPY ${BIN} /rootfs/trident_orchestrator
3576COPY ${CLI_BIN} /rootfs/bin/tridentctl
3677COPY ${NODE_PREP_BIN} /rootfs/node_prep
3778COPY ${SYSWRAP_BIN} /rootfs/syswrap
3879ADD ${CHWRAP_BIN} /rootfs/
80+ COPY LICENSE NOTICE.txt /rootfs/licenses/
3981
4082FROM scratch
4183
@@ -52,7 +94,5 @@ LABEL maintainer="The NetApp Trident Team" \
5294
5395COPY --from=deps /rootfs /
5496
55- COPY LICENSE NOTICE.txt /licenses/
56-
5797ENTRYPOINT ["/bin/tridentctl" ]
5898CMD ["version" ]
0 commit comments