Skip to content

Commit 3fd7f9c

Browse files
Add check-runtime-libs.sh
Signed-off-by: Roman Nikitenko <rnikiten@redhat.com>
1 parent e64c779 commit 3fd7f9c

3 files changed

Lines changed: 85 additions & 0 deletions

File tree

build/dockerfiles/assembly.Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ RUN chmod -R g-w /mnt/rootfs/etc/passwd
3737

3838
COPY --from=machine-exec --chown=0:0 /go/bin/che-machine-exec /mnt/rootfs/bin/machine-exec
3939
COPY --chmod=755 /build/scripts/*.sh /mnt/rootfs/
40+
COPY --chmod=755 /build/scripts/helper/check-runtime-libs.sh /mnt/rootfs/bin/check-runtime-libs.sh
4041
COPY --chmod=755 /build/remote-config /mnt/rootfs/remote/data/Machine/
4142

4243
# Create all-in-one image

build/scripts/entrypoint-init-container.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ cp -r /checode-* /checode/
1616
# Copy machine-exec as well
1717
mkdir -p /checode/bin
1818
cp /bin/machine-exec /checode/bin/
19+
# Copy helper script for runtime dependency checks
20+
if [ -f /bin/check-runtime-libs.sh ]; then
21+
cp /bin/check-runtime-libs.sh /checode/bin/
22+
fi
1923
# Copy entrypoint
2024
cp /entrypoint-volume.sh /checode/
2125
# Copy remote configuration
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#!/bin/sh
2+
set -eu
3+
4+
RUNTIME_DIR="${1:-/checode/checode-linux-libc/ubi9}"
5+
LIBS_DIR="${RUNTIME_DIR}/ld_libs"
6+
NODE_BIN="${RUNTIME_DIR}/node"
7+
8+
echo "Runtime: ${RUNTIME_DIR}"
9+
echo "Libs: ${LIBS_DIR}"
10+
echo "Node: ${NODE_BIN}"
11+
echo
12+
13+
if [ ! -x "${NODE_BIN}" ]; then
14+
echo "ERROR: node binary not found: ${NODE_BIN}" >&2
15+
exit 1
16+
fi
17+
18+
if [ ! -d "${LIBS_DIR}" ]; then
19+
echo "ERROR: libs dir not found: ${LIBS_DIR}" >&2
20+
exit 1
21+
fi
22+
23+
if ! command -v objdump >/dev/null 2>&1; then
24+
echo "ERROR: objdump is required (install binutils in the container)." >&2
25+
exit 1
26+
fi
27+
28+
TMP_NEEDS="$(mktemp)"
29+
TMP_HAVE="$(mktemp)"
30+
TMP_MISS="$(mktemp)"
31+
trap 'rm -f "$TMP_NEEDS" "$TMP_HAVE" "$TMP_MISS"' EXIT
32+
33+
# Collect what we have in ld_libs (basename only).
34+
find "${LIBS_DIR}" -maxdepth 1 -type f -name '*.so*' -exec basename {} \; | sort -u > "${TMP_HAVE}"
35+
36+
scan_needed() {
37+
f="$1"
38+
objdump -p "$f" 2>/dev/null | awk '/NEEDED/ {print $2}' || true
39+
}
40+
41+
# Scan node and all native addons.
42+
scan_needed "${NODE_BIN}" >> "${TMP_NEEDS}"
43+
find "${RUNTIME_DIR}" -type f -name '*.node' 2>/dev/null | while read -r so; do
44+
# Ignore non-linux prebuilt addons to reduce noise.
45+
case "$so" in
46+
*win32*|*windows*|*darwin*|*macos*) continue ;;
47+
esac
48+
scan_needed "$so" >> "${TMP_NEEDS}"
49+
done
50+
51+
sort -u "${TMP_NEEDS}" -o "${TMP_NEEDS}"
52+
53+
echo "=== NEEDED (unique) ==="
54+
cat "${TMP_NEEDS}"
55+
echo
56+
57+
echo "=== HAVE in ld_libs ==="
58+
cat "${TMP_HAVE}"
59+
echo
60+
61+
# Ignore glibc core, usually expected from the host/container base.
62+
grep -Ev '^(linux-vdso\.so\.1|libc\.so\.6|libm\.so\.6|libpthread\.so\.0|libdl\.so\.2|librt\.so\.1|ld-linux-.*\.so.*)$' "${TMP_NEEDS}" > "${TMP_MISS}" || true
63+
64+
echo "=== MISSING in ld_libs (excluding glibc core) ==="
65+
MISSING_COUNT=0
66+
while read -r need; do
67+
[ -z "$need" ] && continue
68+
if ! grep -qx "$need" "${TMP_HAVE}"; then
69+
echo "$need"
70+
MISSING_COUNT=$((MISSING_COUNT + 1))
71+
fi
72+
done < "${TMP_MISS}"
73+
74+
echo
75+
if [ "${MISSING_COUNT}" -eq 0 ]; then
76+
echo "OK: no missing non-glibc SONAMEs in ld_libs"
77+
else
78+
echo "FAIL: missing ${MISSING_COUNT} SONAME(s)"
79+
exit 2
80+
fi

0 commit comments

Comments
 (0)