Skip to content

Commit b0ca635

Browse files
Add file filtering in UBI docker image
Signed-off-by: faizanahmad055 <faizan.ahmad55@outlook.com>
1 parent 8b64c9b commit b0ca635

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

Dockerfile.ubi

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,25 @@ RUN mkdir /image && \
2020
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
23-
RUN tar cf /tmp/files.tar -T /tmp/ubi-build-files-${TARGETARCH}.txt && tar xf /tmp/files.tar -C /image/
23+
# 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+
while IFS= read -r file; do \
27+
[ -n "$file" ] && ([ -e "$file" ] || [ -L "$file" ]) && echo "$file"; \
28+
done < /tmp/ubi-build-files-${TARGETARCH}.txt > /tmp/existing-files.txt && \
29+
# Create tarball if we have files to archive
30+
if [ -s /tmp/existing-files.txt ]; then \
31+
tar -chf /tmp/files.tar \
32+
--exclude='etc/pki/entitlement-host*' \
33+
-T /tmp/existing-files.txt 2>&1 | grep -vE "(File removed before we read it|Cannot stat)" || true; \
34+
# Extract only if tarball was created successfully
35+
if [ -f /tmp/files.tar ]; then \
36+
tar -xf /tmp/files.tar -C /image/ && \
37+
rm -f /tmp/files.tar; \
38+
fi; \
39+
fi && \
40+
# Clean up temporary file list
41+
rm -f /tmp/existing-files.txt
2442

2543
# Generate a rpm database which contains all the packages that you said were needed in ubi-build-files-*.txt
2644
RUN rpm --root /image --initdb \

0 commit comments

Comments
 (0)