Skip to content

RHOAIENG-10350 feat(Dockerfiles): switch from s2i python images to plain ubi/c9s bases #641

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

jiridanek
Copy link
Member

@jiridanek jiridanek commented Jul 24, 2024

https://issues.redhat.com/browse/RHOAIENG-10350

Description

The main benefit is size and cve exposure, as the python images come with packages we don't use; python and pip is enough for us.

Every image is made approx 300MB smaller by doing this!

Before:

rstudio-c9s-python-3.9-main_dbeac5b  4c5c83479bb2  7 seconds ago      3.44 GB

After:

rstudio-c9s-python-3.9-jd_ubi_base_adedd4a  040b74e5a618  50 minutes ago     3.08 GB

Additionally, using plain ubi makes things more explicit.

How Has This Been Tested?

I'll test this when making this change is planned into a sprint.

Merge criteria:

  • The commits are squashed in a cohesive manner and have meaningful messages.
  • Testing instructions have been added in the PR body (for PRs involving changes that are not immediately obvious).
  • The developer has manually tested the changes and verified that the changes work

Summary by CodeRabbit

  • Chores

    • Updated base images for Python 3.11 containers to use more generic CentOS Stream 9 and UBI9 images, with manual Python environment setup.
    • Improved environment variable usage and added installation of additional OS utilities (patch, wget).
    • Enhanced setup scripts for permissions and virtual environment creation.
  • Tests

    • Improved container test logic for FIPS mode, making it more robust across different host environments.

@jiridanek jiridanek added the tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. label Jul 24, 2024
@openshift-ci openshift-ci bot requested review from atheo89 and dibryant July 24, 2024 15:24
@jiridanek jiridanek changed the title feat(Dockerfiles): switch from s2i python images to plain ubi/cs9 ones feat(Dockerfiles): switch from s2i python images to plain ubi/c9s bases Jul 24, 2024
@@ -1,4 +1,21 @@
FROM registry.access.redhat.com/ubi8/python-38:latest
FROM registry.access.redhat.com/ubi8/ubi:latest
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we use ubi-minimal instead?

Copy link
Member Author

@jiridanek jiridanek Jul 24, 2024

Choose a reason for hiding this comment

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

That would either mean living with microdnf, or installing regular dnf first thing, at which point the benefits or the ubi-minimal base are pretty much lost, me thinks.

In any case, I'd want to do such large changes in multiple steps, across multiple PRs.

So far, I don't even have the modest change in this PR groomed. It's necessary to move slowly and cautiously, and to build consensus.

The disk savings are small, 300mb across three base images.

Copy link
Member Author

Choose a reason for hiding this comment

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

/retest

Copy link
Member

@harshad16 harshad16 left a comment

Choose a reason for hiding this comment

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

/hold

@jiridanek can you share there is JIRA or github issue linked for this work.

This PR is great, definitely will be good to have however
This work has significant impact on the overall product, without changing the architecture , this change would disrupt some flow i believe.

the s2i image bring working dir: /opt/app-root/src
i don't think ubi:latest, has that working dir,
this might work only because, the PVC gets mounted at the path,
As mount would create the path.
however we should thoroughly check these changes.

@jiridanek
Copy link
Member Author

This PR is great, definitely will be good to have however

Great! In that case I'll go forward creating a Jira so this can be groomed. https://issues.redhat.com/browse/RHOAIENG-10350

@jiridanek jiridanek changed the title feat(Dockerfiles): switch from s2i python images to plain ubi/c9s bases RHOAIENG-10350 feat(Dockerfiles): switch from s2i python images to plain ubi/c9s bases Jul 25, 2024
@jiridanek
Copy link
Member Author

the s2i image bring working dir: /opt/app-root/src

our images explicitly set this in the WORKDIR instruction, so we're good in that respect

however we should thoroughly check these changes.

sure, that's why I created a jira for doing all the work in organized manner; the disk space savings are not all that significant, but I like how this removes much of the s2i magic, so that's what makes this seem worth doing to me

@jstourac
Copy link
Member

jstourac commented Aug 7, 2024

BTW, I was wondering what are the most important changes, so I prepared some basic script for the image comparison (I have a plan to improve it further and put it into our CI/GHA for our convenience). I tried to compare one of the base images you change here with what we have (note that your build is 2 weeks old, I took the quay image from today):

  1. checkout this branch main...jstourac:notebooks:compareImages
  2. run this:
./ci/compare-images.sh quay.io/opendatahub/workbench-images@sha256:e92bf20e127e545bdf56887903dc72ad227082b8bc23f45ff4f0fc67e6430318 ghcr.io/jiridanek/notebooks/workbench-images:base-ubi9-python-3.9-jd_ubi_base_adedd4a943977ecdcb67bc6eb9eda572d10c3ddc

@atheo89
Copy link
Member

atheo89 commented Sep 16, 2024

+1 for this update, I like this. 🙂 As Harshad mentioned, we should thoroughly test everything to ensure there are no issues with the PVCs. Otherwise, it /lgtm

@jiridanek
Copy link
Member Author

jiridanek commented Sep 16, 2024

we should thoroughly test everything

yeah; was just thinking whether nginx gets properly installed after this change; I did not think of it before

https://issues.redhat.com/browse/RHOAIENG-10350 is opened to properly schedule the work

Copy link
Contributor

openshift-ci bot commented Jan 8, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from harshad16. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

…less podman machine

```
base_image_test.py:146: in test_oc_command_runs_fake_fips
    assert ecode == 0, output.decode()
E   AssertionError: assertion failed [!result.is_error]: Unable to open /proc/sys/vm/mmap_min_addr
E     (VMAllocationTracker.cpp:317 init)
E
E   assert 137 == 0
```

```
lima cat /proc/sys/vm/mmap_min_addr
65536
```

```
podman machine ssh cat /proc/sys/vm/mmap_min_addr
65536
```

```
podman run --entrypoint /bin/bash --rm -it ghcr.io/jiridanek/notebooks/workbench-images:base-ubi9-python-3.11-jd_ubi_base_1e8dd3140d980ff573d56d3ae746959f31825d8a
WARNING: image platform (linux/amd64) does not match the expected platform (linux/arm64)
bash-5.1$ cat /proc/sys/vm/mmap_min_addr
65536
```
@openshift-ci openshift-ci bot added size/m and removed size/m labels Feb 6, 2025
Copy link
Contributor

openshift-ci bot commented Feb 6, 2025

@jiridanek: The following tests 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/habana-notebooks-e2e-tests adedd4a link true /test habana-notebooks-e2e-tests
ci/prow/notebooks-ubi8-e2e-tests adedd4a link true /test notebooks-ubi8-e2e-tests
ci/prow/runtime-rocm-tensorflow-ubi9-python-3-11-pr-image-mirror adedd4a link true /test runtime-rocm-tensorflow-ubi9-python-3-11-pr-image-mirror
ci/prow/runtime-rocm-pytorch-ubi9-python-3-11-pr-image-mirror adedd4a link true /test runtime-rocm-pytorch-ubi9-python-3-11-pr-image-mirror
ci/prow/notebook-cuda-jupyter-tf-ubi9-python-3-9-pr-image-mirror 41741e4 link true /test notebook-cuda-jupyter-tf-ubi9-python-3-9-pr-image-mirror
ci/prow/notebook-jupyter-pytorch-ubi9-python-3-9-pr-image-mirror 41741e4 link true /test notebook-jupyter-pytorch-ubi9-python-3-9-pr-image-mirror
ci/prow/intel-notebooks-e2e-tests 41741e4 link true /test intel-notebooks-e2e-tests
ci/prow/rocm-runtimes-ubi9-e2e-tests 41741e4 link true /test rocm-runtimes-ubi9-e2e-tests
ci/prow/rocm-notebooks-e2e-tests 41741e4 link true /test rocm-notebooks-e2e-tests
ci/prow/notebook-jupyter-trustyai-ubi9-python-3-11-pr-image-mirror 57f2e8f link true /test notebook-jupyter-trustyai-ubi9-python-3-11-pr-image-mirror
ci/prow/notebook-jupyter-datascience-ubi9-python-3-11-pr-image-mirror 57f2e8f link true /test notebook-jupyter-datascience-ubi9-python-3-11-pr-image-mirror
ci/prow/notebook-jupyter-pytorch-ubi9-python-3-11-pr-image-mirror 57f2e8f link true /test notebook-jupyter-pytorch-ubi9-python-3-11-pr-image-mirror
ci/prow/runtime-cuda-tensorflow-ubi9-python-3-11-pr-image-mirror 57f2e8f link true /test runtime-cuda-tensorflow-ubi9-python-3-11-pr-image-mirror
ci/prow/notebook-cuda-jupyter-tf-ubi9-python-3-11-pr-image-mirror 57f2e8f link true /test notebook-cuda-jupyter-tf-ubi9-python-3-11-pr-image-mirror
ci/prow/notebook-cuda-jupyter-min-ubi9-python-3-11-pr-image-mirror 57f2e8f link true /test notebook-cuda-jupyter-min-ubi9-python-3-11-pr-image-mirror
ci/prow/notebook-cuda-jupyter-ds-ubi9-python-3-11-pr-image-mirror 57f2e8f link true /test notebook-cuda-jupyter-ds-ubi9-python-3-11-pr-image-mirror
ci/prow/notebook-cuda-ubi9-python-3-11-pr-image-mirror 57f2e8f link true /test notebook-cuda-ubi9-python-3-11-pr-image-mirror
ci/prow/notebook-rocm-jupyter-min-ubi9-python-3-11-pr-image-mirror 57f2e8f link true /test notebook-rocm-jupyter-min-ubi9-python-3-11-pr-image-mirror
ci/prow/rstudio-notebook-e2e-tests 57f2e8f link true /test rstudio-notebook-e2e-tests
ci/prow/notebooks-ubi9-e2e-tests 57f2e8f link true /test notebooks-ubi9-e2e-tests
ci/prow/codeserver-notebook-e2e-tests 57f2e8f link true /test codeserver-notebook-e2e-tests
ci/prow/runtimes-ubi9-e2e-tests 57f2e8f link true /test runtimes-ubi9-e2e-tests
ci/prow/notebook-rocm-ubi9-python-3-11-pr-image-mirror 57f2e8f link true /test notebook-rocm-ubi9-python-3-11-pr-image-mirror
ci/prow/images 57f2e8f link true /test images

Full PR test history. Your PR dashboard.

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.

@jiridanek
Copy link
Member Author

@coderabbitai review

Copy link
Contributor

coderabbitai bot commented Jun 19, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Contributor

coderabbitai bot commented Jun 19, 2025

Walkthrough

The Dockerfiles for Python 3.11 base images were updated to use more generic CentOS Stream 9 and UBI9 images, with manual setup of the Python environment and utilities. The test for FIPS mode in containers was adjusted for better compatibility across host environments, refining volume mounts and output assertions.

Changes

Files/Groups Change Summary
base/c9s-python-3.11/Dockerfile,
base/ubi9-python-3.11/Dockerfile
Switched base images to generic CentOS/UBI9, manually set up Python 3.11 environment, added utilities, improved env vars, and package installs.
tests/containers/base_image_test.py Updated FIPS test to conditionally mount files based on host OS, changed verification command and output assertions.

Sequence Diagram(s)

sequenceDiagram
    participant Host
    participant Container
    participant OS
    participant PythonEnv

    Host->>Container: Start container from base image
    Container->>OS: Install Python 3.11 & utilities via dnf
    Container->>OS: Create user, set env variables
    Container->>PythonEnv: Create virtual environment
    Container->>OS: Install additional packages (patch, wget, mesa-libGL)
    Container->>PythonEnv: Install micropipenv and dependencies
    Host->>Container: Run FIPS test (mount fips_enabled or /proc/sys)
    Container->>OS: cat /proc/sys/crypto/fips_enabled
    Container->>Host: Return FIPS status
Loading

Suggested labels

lgtm, ok-to-test

Poem

In the warren of containers, a change hops by,
New base images chosen, old ones say goodbye.
Python’s home is crafted with a careful paw,
FIPS tests now smarter, without a flaw.
🐇 With patch and wget, our tools are complete—
This rabbit’s Dockerfiles can’t be beat!

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@openshift-merge-robot
Copy link
Contributor

PR needs rebase.

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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🔭 Outside diff range comments (1)
base/c9s-python-3.11/Dockerfile (1)

60-60: Use environment variable for consistency.

Line 60 uses hardcoded "python3.11" while the UBI9 version (line 62) uses ${PYTHON_VERSION}. This inconsistency could cause maintenance issues.

Apply this diff for consistency:

-    chmod -R g+w /opt/app-root/lib/python3.11/site-packages && \
+    chmod -R g+w /opt/app-root/lib/python${PYTHON_VERSION}/site-packages && \
🧹 Nitpick comments (1)
tests/containers/base_image_test.py (1)

153-155: Fix Yoda condition for better readability.

The change from sysctl to cat command is more direct and appropriate. However, the assertion uses a Yoda condition which should be corrected.

Apply this diff to fix the Yoda condition:

-                    assert "1\n" == output.decode(), f"Unexpected crypto/fips_enabled content: {output.decode()}"
+                    assert output.decode() == "1\n", f"Unexpected crypto/fips_enabled content: {output.decode()}"
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c0c64e0 and 57f2e8f.

📒 Files selected for processing (3)
  • base/c9s-python-3.11/Dockerfile (2 hunks)
  • base/ubi9-python-3.11/Dockerfile (3 hunks)
  • tests/containers/base_image_test.py (2 hunks)
🧰 Additional context used
🪛 Ruff (0.11.9)
tests/containers/base_image_test.py

155-155: Yoda condition detected

Rewrite as output.decode() == "1\n"

(SIM300)

🔇 Additional comments (8)
base/ubi9-python-3.11/Dockerfile (4)

1-18: Excellent manual Python environment setup.

The transition from s2i python image to plain UBI9 with manual environment setup is well-implemented. The setup correctly replicates the s2i behavior:

  • Proper environment variables and paths
  • Correct user/group setup (UID 1001, GID 0) for OpenShift compatibility
  • Appropriate directory permissions (0771)
  • Virtual environment creation

This aligns perfectly with the PR objectives to reduce image size while maintaining functionality.


40-40: Minor text refinement in echo statement.

The text change from "softwares" to "software" improves grammar consistency.


46-50: Good addition of essential utilities.

Adding patch and wget packages enhances the base image functionality for development workflows.


62-62: Improved use of environment variable.

Using ${PYTHON_VERSION} instead of hardcoded version number makes the Dockerfile more maintainable and consistent.

base/c9s-python-3.11/Dockerfile (2)

1-18: Well-implemented manual Python environment setup.

The transition to CentOS Stream 9 base with manual environment setup correctly replicates the s2i functionality, following the same pattern as the UBI9 version.


44-48: Good addition of essential utilities.

Adding patch and wget packages enhances the base image functionality, consistent with the UBI9 version.

tests/containers/base_image_test.py (2)

8-8: Good addition for cross-platform compatibility.

Adding the platform import enables better handling of Darwin vs Linux environments in the FIPS test.


139-145: Improved FIPS file mounting logic.

The conditional volume mounting approach is more robust, handling both macOS and Linux environments appropriately by mounting only the specific FIPS file when possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
do-not-merge/hold needs-rebase size/m tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Trivy and Aqua Enterprise vulnerability scan results critical and high
6 participants