Skip to content

ROX-30858: Migrate scanner DB image from ubi8-minimal to ubi8-micro#17431

Open
janisz wants to merge 8 commits intomasterfrom
ubi-micro-scanner-db
Open

ROX-30858: Migrate scanner DB image from ubi8-minimal to ubi8-micro#17431
janisz wants to merge 8 commits intomasterfrom
ubi-micro-scanner-db

Conversation

@janisz
Copy link
Copy Markdown
Contributor

@janisz janisz commented Oct 22, 2025

This commit migrates the scanner database (PostgreSQL) container image from ubi8-minimal to ubi8-micro, completing the migration of all scanner images.

🤖 Generated with Claude Code

@janisz janisz requested a review from a team as a code owner October 22, 2025 08:01
@janisz janisz changed the title ROX-30858: Migrate scanner DB image from ubi8-minimal to ubi8-micro WIP: ROX-30858: Migrate scanner DB image from ubi8-minimal to ubi8-micro Oct 22, 2025
@rhacs-bot
Copy link
Copy Markdown
Contributor

rhacs-bot commented Oct 22, 2025

Images are ready for the commit at b5ecb82.

To use with deploy scripts, first export MAIN_IMAGE_TAG=4.11.x-531-gb5ecb82f6b.

@codecov
Copy link
Copy Markdown

codecov bot commented Oct 22, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 49.59%. Comparing base (be4bae3) to head (b5ecb82).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #17431      +/-   ##
==========================================
- Coverage   49.60%   49.59%   -0.01%     
==========================================
  Files        2756     2756              
  Lines      208036   208036              
==========================================
- Hits       103189   103184       -5     
- Misses      97187    97192       +5     
  Partials     7660     7660              
Flag Coverage Δ
go-unit-tests 49.59% <ø> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@janisz janisz changed the title WIP: ROX-30858: Migrate scanner DB image from ubi8-minimal to ubi8-micro ROX-30858: Migrate scanner DB image from ubi8-minimal to ubi8-micro Oct 29, 2025
@janisz janisz requested review from a team and rhacs-bot as code owners March 11, 2026 13:34
@janisz janisz force-pushed the ubi-micro-scanner-db branch from 99024b2 to dd7d925 Compare March 11, 2026 13:43
@github-actions github-actions bot added the konflux-build Run Konflux in PR. Push commit to trigger it. label Mar 11, 2026
@janisz janisz force-pushed the ubi-micro-scanner-db branch from dd7d925 to 61618ff Compare March 11, 2026 13:54
@janisz janisz force-pushed the ubi-micro-scanner-db branch 2 times, most recently from fe8b45c to 292c59d Compare March 24, 2026 16:31
@janisz janisz force-pushed the ubi-micro-scanner-db branch 2 times, most recently from f09ff53 to 4d44c29 Compare March 31, 2026 15:15
@openshift-ci
Copy link
Copy Markdown

openshift-ci bot commented Mar 31, 2026

@janisz: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/ocp-4-20-scanner-v4-install-tests 292c59d link false /test ocp-4-20-scanner-v4-install-tests

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@janisz janisz force-pushed the ubi-micro-scanner-db branch from 4d44c29 to d6f9e04 Compare April 1, 2026 12:08
janisz and others added 8 commits April 1, 2026 14:12
This commit migrates the scanner database (PostgreSQL) container image from
ubi8-minimal to ubi8-micro, completing the migration of all scanner images.

- Changed base image from ubi8-minimal to ubi8-micro
- Introduced dependency_builder stage for all runtime dependencies
- PostgreSQL DB requires many packages for operation
- Uses chroot to run user/group creation and locale setup

- **PostgreSQL**: 4 RPMs (libs, server, client, contrib) via rpm --root
- **System packages**: shadow-utils, ca-certificates, glibc-langpack-en,
  glibc-locale-source, libicu, libxslt, lz4, perl-libs, python3,
  systemd-sysv, zstd, tzdata, uuid (RHEL 9+)
- **User setup**: postgres user (70:70) created via chroot
- **Locale**: en_US.UTF-8 configured via chroot

- Base image: ubi8-minimal → ubi8-micro
- Builder stage: Uses ubi8 (full) for dnf --installroot
- PostgreSQL: 4 RPMs installed via rpm --root
- User creation: Uses chroot to run groupadd/adduser in /out/
- Locale setup: Uses chroot to run localedef in /out/
- No package managers in final image

- **Size reduction**: ~60-70 MB smaller base image
- **Security**: No package managers in runtime
- **Consistency**: Same ubi8-micro pattern as other images
- **Complete**: All scanner images now use ubi8-micro

This is the most complex migration due to:
- PostgreSQL server requirements (not just client)
- User/group creation in builder (requires chroot)
- Locale generation (requires chroot)
- Many runtime dependencies for PostgreSQL operation

Tested-by: Local analysis and pattern validation
Relates-to: ROX-30858

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
The PostgreSQL RPMs automatically create the postgres user and group during
installation with their default UID/GID (26). However, the Dockerfile requires
UID/GID 70 to match the USER directive.

This commit fixes the user creation logic to:
- Check if postgres user/group already exist (created by RPM post-install)
- If they exist with wrong IDs, use usermod/groupmod to change to UID/GID 70
- If they don't exist, create them with UID/GID 70

This resolves the build failure:
  > [dependency_builder 6/8] RUN chroot /out /bin/sh -c "groupadd -g 70 postgres && adduser postgres..."
  groupadd: group 'postgres' already exists

Tested: Local build verified postgres user has UID/GID 70 in final image

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
The scanner-v4-db container was crashing with exit code 127 (command not
found) because the migration to ubi8-micro removed essential shell utilities
that the entrypoint scripts depend on.

Root cause:
- docker-entrypoint.sh uses #!/usr/bin/env bash
- ubi8-micro has no utilities pre-installed (unlike ubi8-minimal)
- The chroot commands for user creation need /bin/sh, id, etc.

This fix adds the missing packages that PR #17406 correctly included for
the main image:
- bash: Required for entrypoint scripts
- coreutils: Basic commands (id, mkdir, cat, etc.)
- findutils: File operations
- util-linux: System utilities

These packages enable the existing chroot user creation and locale setup
commands to execute successfully.

Fixes: ROX-30858
Related: #17406

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
The scanner-v4-db was still crashing with exit code 127 because PostgreSQL
binaries require the OpenLDAP runtime library (libldap_r-2.4.so.2).

Image inspection revealed:
```
$ docker run scanner-v4-db:4.10.x-81-gcc55af9924 initdb --version
initdb: error while loading shared libraries: libldap_r-2.4.so.2:
cannot open shared object file: No such file or directory
```

PostgreSQL is compiled with LDAP support and requires these libraries at
runtime even if LDAP authentication is not actively used.

This adds the openldap package which provides libldap_r-2.4.so.2 and other
LDAP client libraries needed by PostgreSQL.

Fixes: ROX-30858

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Create /var/run/postgresql with proper ownership and permissions in the
dependency_builder stage. PostgreSQL requires this directory to create
lock files (.s.PGSQL.5432.lock) during startup.

Without this directory, PostgreSQL fails with:
  FATAL: could not create lock file "/run/postgresql/.s.PGSQL.5432.lock": Permission denied

The fix uses chroot to run chown/chmod in the /out/ context where the
postgres user (UID/GID 70:70) exists, following the same pattern used
for locale setup and user creation.

Fixes scanner-v4-install-tests CI failure.
Tested locally - PostgreSQL starts successfully and accepts connections.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Simplify comments to match style from other ubi-micro migrations:
- Remove verbose section separators and header comments
- Consolidate locale setup into user creation RUN command
- Keep only meaningful comments explaining intent, not mechanics
- Remove redundant comments that duplicate what code already shows

No functional changes, only comment cleanup and minor consolidation.

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Following the pattern from collector PR #3021, this commit:
- Adds ubi-micro-base stage and copies it to /out/ before package installation to preserve rpmdb
- Removes bash and coreutils from dnf install (already included in ubi-micro)

The previous implementation installed packages to /out/ without first copying the ubi-micro base, which could break the RPM database. This pattern ensures the minimal ubi-micro base is preserved correctly.

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Signed-off-by: Tomasz Janiszewski <[email protected]>
PostgreSQL requires /usr/share/zoneinfo directory for timezone configuration.
ubi9-micro ships with tzdata pre-installed in the RPM database but with an
empty /usr/share/zoneinfo directory. Regular `dnf install tzdata` won't work
because the package is already present - we must use `dnf reinstall` to force
repopulation of timezone files. Use --setopt=reposdir to access build host
repos since /out/etc/yum.repos.d doesn't exist yet.

Fixes scanner-v4-db CrashLoopBackOff with error:
"could not open directory /usr/share/zoneinfo: No such file or directory"

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
@janisz janisz force-pushed the ubi-micro-scanner-db branch from d6f9e04 to b5ecb82 Compare April 1, 2026 12:12
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 1, 2026

/konflux-retest operator-bundle-on-push

2 similar comments
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 1, 2026

/konflux-retest operator-bundle-on-push

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 1, 2026

/konflux-retest operator-bundle-on-push

@janisz janisz requested review from dcaravel and msugakov April 2, 2026 11:35
Copy link
Copy Markdown
Contributor

@dcaravel dcaravel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few minor items.

CI does not run Scanner V4 outside of those install tests (work is in progress to address this) - for now, if possible, would recommend testing this image outside of CI and sharing results.

Comment on lines +53 to +54
if [[ $(awk -F'=' '/VERSION_ID/{ gsub(/"/,""); print substr($2,1,1)}' /etc/os-release) -gt 8 ]]; then \
dnf install --installroot=/out/ --releasever=8 --setopt=install_weak_deps=0 --nodocs -y uuid; \
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This conditional still needed? given that --releasever is hardcoded to 9 above it doesn't seem like the dockerfile needs to be able to support both 8 and 9 anymore?

COPY --from=ubi-micro-base / /out/

# If this is updated, be sure to update postgres_major in download.sh and the signature file.
ENV PG_MAJOR=15
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one may be unnecessary? Is repeated in a later stage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/scanner konflux-build Run Konflux in PR. Push commit to trigger it.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants