Skip to content

Commit 6fd7c82

Browse files
Update filtering in UBI image
Signed-off-by: faizanahmad055 <faizan.ahmad55@outlook.com>
1 parent 703319e commit 6fd7c82

1 file changed

Lines changed: 11 additions & 25 deletions

File tree

Dockerfile.ubi

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,33 +21,19 @@ COPY ubi-build-files-${TARGETARCH}.txt /tmp
2121
# Copy all the required files from the base UBI image into the image directory
2222
# As the go binary is not statically compiled this includes everything needed for CGO to work, cacerts, tzdata and RH release files
2323
# Filter existing files and exclude temporary entitlement files that may be removed during build
24-
RUN set -e && \
25-
# Filter files that actually exist (files, directories, or symlinks)
26-
# This ensures we only copy files that are present, avoiding "Cannot stat" errors
27-
while IFS= read -r file; do \
28-
[ -n "$file" ] && ([ -e "$file" ] || [ -L "$file" ]) && echo "$file"; \
24+
RUN while IFS= read -r file; do \
25+
[ -z "$file" ] && continue; \
26+
if [ -e "$file" ] || [ -L "$file" ]; then \
27+
echo "$file"; \
28+
fi; \
2929
done < /tmp/ubi-build-files-${TARGETARCH}.txt > /tmp/existing-files.txt && \
30-
# Verify we have files to copy (fail if list is empty to catch configuration issues)
31-
if [ ! -s /tmp/existing-files.txt ]; then \
32-
echo "ERROR: No files found to copy from ubi-build-files-${TARGETARCH}.txt" >&2; \
33-
echo "This indicates the base image may be missing required files or the file list is incorrect." >&2; \
34-
echo "Expected files from ubi-build-files-${TARGETARCH}.txt:" >&2; \
35-
cat /tmp/ubi-build-files-${TARGETARCH}.txt >&2; \
36-
exit 1; \
30+
if [ -s /tmp/existing-files.txt ]; then \
31+
tar -chf /tmp/files.tar --exclude='etc/pki/entitlement-host*' -T /tmp/existing-files.txt 2>&1 | grep -vE "(File removed before we read it|Cannot stat)" || true; \
32+
if [ -f /tmp/files.tar ]; then \
33+
tar xf /tmp/files.tar -C /image/ 2>/dev/null || true; \
34+
rm -f /tmp/files.tar; \
35+
fi; \
3736
fi && \
38-
# Create tarball, excluding only temporary entitlement files (safe to exclude)
39-
# Note: --exclude only affects files within directories being archived, not the directories themselves
40-
tar -chf /tmp/files.tar \
41-
--exclude='etc/pki/entitlement-host*' \
42-
-T /tmp/existing-files.txt 2>&1 | grep -vE "(File removed before we read it|Cannot stat)" || true; \
43-
# Extract tarball (critical files like libc.so.6, ld-linux, etc/ssl/certs are included)
44-
if [ -f /tmp/files.tar ]; then \
45-
tar -xf /tmp/files.tar -C /image/ && \
46-
rm -f /tmp/files.tar; \
47-
else \
48-
echo "WARNING: Tarball was not created, but continuing..." >&2; \
49-
fi && \
50-
# Clean up temporary file list
5137
rm -f /tmp/existing-files.txt
5238

5339
# Generate a rpm database which contains all the packages that you said were needed in ubi-build-files-*.txt

0 commit comments

Comments
 (0)