Skip to content

Commit a0e97b3

Browse files
authored
Adds RPM db to container images
1 parent 2210058 commit a0e97b3

3 files changed

Lines changed: 87 additions & 21 deletions

File tree

Dockerfile

Lines changed: 52 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
ARG ARCH=amd64
2-
# Image for dependencies such as NFS binaries
32
ARG DEPS_IMAGE=alpine:3
43

54
FROM --platform=linux/${ARCH} $DEPS_IMAGE AS deps
@@ -11,31 +10,74 @@ ARG CHWRAP_BIN=chwrap.tar
1110
ARG NODE_PREP_BIN=node_prep
1211
ARG 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
1529
RUN --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

3475
COPY ${BIN} /rootfs/trident_orchestrator
3576
COPY ${CLI_BIN} /rootfs/bin/tridentctl
3677
COPY ${NODE_PREP_BIN} /rootfs/node_prep
3778
COPY ${SYSWRAP_BIN} /rootfs/syswrap
3879
ADD ${CHWRAP_BIN} /rootfs/
80+
COPY LICENSE NOTICE.txt /rootfs/licenses/
3981

4082
FROM scratch
4183

@@ -52,7 +94,5 @@ LABEL maintainer="The NetApp Trident Team" \
5294

5395
COPY --from=deps /rootfs /
5496

55-
COPY LICENSE NOTICE.txt /licenses/
56-
5797
ENTRYPOINT ["/bin/tridentctl"]
5898
CMD ["version"]

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ docker_build_windows = $1 build \
280280
docker_build_operator = $1 build \
281281
--platform $2 \
282282
--file operator/Dockerfile \
283+
--build-arg ARCH=$(call arch,$2) \
283284
--build-arg BIN=$(call binary_path,trident-operator,$2) \
284285
--build-arg VERSION=$(VERSION) \
285286
$(if $(TRIDENT_DEPS_IMAGE),--build-arg DEPS_IMAGE=$(TRIDENT_DEPS_IMAGE)) \

operator/Dockerfile

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,39 @@
1-
# Image for dependencies such as CA certificates
1+
ARG ARCH=amd64
22
ARG DEPS_IMAGE=alpine:3
33

4-
FROM $DEPS_IMAGE AS deps
4+
FROM --platform=linux/${ARCH} $DEPS_IMAGE AS deps
55

6-
RUN mkdir /real-certs; \
7-
cp -L /etc/ssl/certs/* /real-certs/
6+
ARG FILE_ALLOWLIST="\
7+
/etc/os-release \
8+
/etc/ssl/certs/* \
9+
"
10+
11+
ARG BIN=trident-operator
12+
13+
# Copy required files to rootfs
14+
RUN for f in $FILE_ALLOWLIST; do \
15+
if [ -e "$f" ]; then \
16+
dest="/rootfs${f}"; \
17+
mkdir -p "$(dirname "$dest")"; \
18+
cp -a "$f" "$dest"; \
19+
fi; \
20+
done
21+
22+
# Copy symlink targets to rootfs
23+
RUN find /rootfs -type l | while read -r link; do \
24+
target="$(readlink $link)"; \
25+
if [[ "$target" =~ ^/ ]]; then \
26+
dest="/rootfs$target"; \
27+
else \
28+
dest="$(dirname $link)/$target"; \
29+
target=${dest#"/rootfs"}; \
30+
fi; \
31+
mkdir -p "$(dirname $dest)"; \
32+
cp -a "$target" "$dest"; \
33+
done
34+
35+
COPY LICENSE NOTICE.txt /rootfs/licenses/
36+
COPY ${BIN} /rootfs/trident-operator
837

938
FROM scratch
1039

@@ -19,10 +48,6 @@ LABEL maintainer="The NetApp Trident Team" \
1948
version="${VERSION}" \
2049
release="${VERSION}"
2150

22-
ARG BIN=trident-operator
23-
24-
COPY --from=deps /real-certs/ /etc/ssl/certs/
25-
COPY LICENSE NOTICE.txt /licenses/
26-
COPY ${BIN} /trident-operator
51+
COPY --from=deps /rootfs /
2752

2853
ENTRYPOINT ["/trident-operator"]

0 commit comments

Comments
 (0)