Skip to content

Commit ca9be4c

Browse files
committed
Distgen generated content
1 parent 479404b commit ca9be4c

File tree

140 files changed

+3865
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

140 files changed

+3865
-0
lines changed

3.14-minimal/Dockerfile.fedora

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
FROM quay.io/fedora/fedora-minimal:43
2+
3+
4+
EXPOSE 8080
5+
6+
ENV PYTHON_VERSION=3.14 \
7+
PYTHONUNBUFFERED=1 \
8+
PYTHONIOENCODING=UTF-8 \
9+
LC_ALL=en_US.UTF-8 \
10+
LANG=en_US.UTF-8 \
11+
CNB_STACK_ID=com.redhat.stacks.ubi-python-314 \
12+
CNB_USER_ID=1001 \
13+
CNB_GROUP_ID=0 \
14+
PIP_NO_CACHE_DIR=off \
15+
# The following variables are usually available from parent s2i images \
16+
STI_SCRIPTS_PATH=/usr/libexec/s2i \
17+
APP_ROOT=/opt/app-root \
18+
HOME=/opt/app-root/src \
19+
PLATFORM="el"
20+
21+
# /opt/app-root/bin - the main venv
22+
# /opt/app-root/src/bin - app-specific binaries
23+
# /opt/app-root/src/.local/bin - tools like pipenv
24+
ENV PATH=$APP_ROOT/bin:$HOME/bin:$HOME/.local/bin:$PATH
25+
26+
# Ensure the virtual environment is active in interactive shells
27+
ENV BASH_ENV=${APP_ROOT}/bin/activate \
28+
ENV=${APP_ROOT}/bin/activate \
29+
PROMPT_COMMAND=". ${APP_ROOT}/bin/activate"
30+
31+
ENV SUMMARY="Minimal platform for building and running Python $PYTHON_VERSION applications" \
32+
DESCRIPTION="Python $PYTHON_VERSION available as container is a base platform for \
33+
building and running various Python $PYTHON_VERSION applications and frameworks. \
34+
Python is an easy to learn, powerful programming language. It has efficient high-level \
35+
data structures and a simple but effective approach to object-oriented programming. \
36+
Python's elegant syntax and dynamic typing, together with its interpreted nature, \
37+
make it an ideal language for scripting and rapid application development in many areas \
38+
on most platforms."
39+
40+
LABEL summary="$SUMMARY" \
41+
description="$DESCRIPTION" \
42+
io.k8s.description="$DESCRIPTION" \
43+
io.k8s.display-name="Python 3.14" \
44+
io.openshift.expose-services="8080:http" \
45+
io.openshift.tags="builder,python,python314,python-314,rh-python314" \
46+
com.redhat.component="python-314-container" \
47+
name="fedora/python-314-minimal" \
48+
usage="s2i build https://github.com/sclorg/s2i-python-container.git --context-dir=3.14-minimal/test/setup-test-app/ ubi/python-314-minimal python-sample-app" \
49+
com.redhat.license_terms="https://www.redhat.com/en/about/red-hat-end-user-license-agreements#UBI" \
50+
io.buildpacks.stack.id="com.redhat.stacks.ubi-python-314-minimal" \
51+
maintainer="SoftwareCollections.org <[email protected]>"
52+
53+
# Very minimal set of packages
54+
# Python is obvious in the Python container :)
55+
# glibc-langpack-en is needed to set locale to en_US and disable warning about it
56+
# findutils - find command is needed for fix-permissions script
57+
# nss_wrapper - used in generate_container_user script
58+
RUN INSTALL_PKGS="python3.14 glibc-langpack-en findutils nss_wrapper-libs" && \
59+
microdnf -y --setopt=tsflags=nodocs --setopt=install_weak_deps=0 install $INSTALL_PKGS && \
60+
microdnf -y clean all --enablerepo='*'
61+
62+
# Copy the S2I scripts from the specific language image to $STI_SCRIPTS_PATH.
63+
COPY 3.14-minimal/s2i/bin/ $STI_SCRIPTS_PATH
64+
65+
# Copy extra files to the image.
66+
COPY 3.14-minimal/root/ /
67+
68+
# Python 3.7+ only
69+
# Yes, the directory below is already copied by the previous command.
70+
# The problem here is that the wheels directory is copied as a symlink.
71+
# Only if you specify symlink directly as a source, COPY copies all the
72+
# files from the symlink destination.
73+
COPY 3.14-minimal/root/opt/wheels /opt/wheels
74+
75+
# This command sets (and also creates if necessary)
76+
# the home directory - it has to be done here so the latter
77+
# fix-permissions fixes this directory as well.
78+
WORKDIR ${HOME}
79+
80+
# - Create a Python virtual environment for use by any application to avoid
81+
# potential conflicts with Python packages preinstalled in the main Python
82+
# installation.
83+
# - In order to drop the root user, we have to make some directories world
84+
# writable as OpenShift default security model is to run the container
85+
# under random UID.
86+
RUN \
87+
python3.14 -m venv ${APP_ROOT} && \
88+
# We have to upgrade pip to a newer version because \
89+
# pip < 19.3 does not support manylinux2014 wheels. Only manylinux2014 (and later) wheels \
90+
# support platforms like ppc64le, aarch64 or armv7 \
91+
# We are newly using wheel from one of the latest stable Fedora releases (from RPM python-pip-wheel) \
92+
# because it's tested better then whatever version from PyPI and contains useful patches. \
93+
# We have to do it here so the permissions are correctly fixed and pip is able \
94+
# to reinstall itself in the next build phases in the assemble script if user wants the latest version \
95+
${APP_ROOT}/bin/pip install /opt/wheels/pip-* && \
96+
rm -r /opt/wheels && \
97+
chown -R 1001:0 ${APP_ROOT} && \
98+
fix-permissions ${APP_ROOT} -P && \
99+
rpm-file-permissions
100+
101+
USER 1001
102+
103+
# Set the default CMD to print the usage of the language image.
104+
CMD $STI_SCRIPTS_PATH/usage

3.14-minimal/README.md

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
Python 3.14 container image - minimal version
2+
============================================
3+
4+
This container image is a special version of the [full Python 3.14 container image](https://github.com/sclorg/s2i-python-container/tree/master/3.14)
5+
provided as a [S2I](https://github.com/openshift/source-to-image) base image for your Python 3.14 applications.
6+
7+
Because the minimal and full images work similarly, we document here only the differences and limitations
8+
of the minimal container image. For the documentation of common features see the [full container image docs](https://github.com/sclorg/s2i-python-container/tree/master/3.14).
9+
10+
The Python 3.14 minimal container image is currently considered a tech-preview and only available on quay.io.
11+
The image is built on top of the [official CentOS Stream base containers](quay.io/centos/centos).
12+
13+
To pull the Python 3.14 minimal container image to build on, run
14+
15+
```
16+
podman pull quay.io/fedora/python-314-minimal
17+
```
18+
19+
Description
20+
-----------
21+
22+
The full container image is a universal base image to build your containerized applications on top of. However, its universal nature
23+
means that the resulting containers it produces consume a lot of disk space. This is caused mainly by the fact that the image contains
24+
npm, compilers, header files and some other packages one might need to install and deploy their applications.
25+
26+
Because size does matter for us and our customers, we have prepared this minimal container image with very limited subset
27+
of installed packages. There are no compilers, no header files, no npm etc and the yum package manager is replaced with a minimalistic
28+
reimplementation called microdnf, making the resulting container images much smaller. This creates some limitations
29+
but we provide ways to workaround them.
30+
31+
Limitations
32+
-----------
33+
34+
1. There is only a very limited subset of packages installed. They are choosen carefully to satisfy most of the Python apps but your app might have some special needs.
35+
1. There is no npm and nodejs.
36+
1. There are no compilers and header files. Installation from Python wheels should still work but compilation from a source code is not supported out of the box.
37+
38+
In the next chapter, we provide three possible workarounds for the mentioned limitations of the minimal container image.
39+
40+
Possible solutions for the limitations
41+
--------------------------------------
42+
43+
### Use the full container image
44+
45+
It's easy at that. If you don't want to write your own Dockerfile and disk space is not a problem, use
46+
the full universal container image and you should be fine.
47+
48+
### Build your own container image on top of the minimal container image
49+
50+
Let's say that your application depends on uwsgi. uwsgi cannot be installed from Python wheel and has to be
51+
compiled from source which requires some additional packages to be installed - namely gcc for the compilation
52+
itself and python3.14-devel containing Python header files.
53+
54+
To solve that problem, you can use all the pieces provided by the minimal container image and just add one more
55+
step to install the missing dependencies:
56+
57+
```
58+
FROM python-314-minimal
59+
60+
# Add application sources to a directory that the assemble script expects them
61+
# and set permissions so that the container runs without root access
62+
USER 0
63+
ADD app-src /tmp/src
64+
RUN /usr/bin/fix-permissions /tmp/src
65+
66+
# Install packages necessary for compiling uwsgi from source
67+
RUN microdnf install -y gcc python3.14-devel
68+
USER 1001
69+
70+
# Install the dependencies
71+
RUN /usr/libexec/s2i/assemble
72+
73+
# Set the default command for the resulting image
74+
CMD /usr/libexec/s2i/run
75+
```
76+
77+
If you do it this way, your problem with the missing packages is solved. But there is also one disadvantage: the resulting
78+
runtime image contains unnecessary compiler and Python header files. How to solve this? Uninstalling them at the end
79+
of the Dockerfile is not really a solution but we have one. Keep reading.
80+
81+
### Build on full image, run on minimal image
82+
83+
Did you know that you can copy files from one image to another one during a build? That's the feature we are gonna use now.
84+
We use the full container image with all compilers and other usefull packages installed to build our app and its dependencies
85+
and we then move the result including the whole virtual environemnt to the minimal container image.
86+
87+
This app needs mod_wsgi and to install (compile it from source) it, we'll need: httpd-devel for header files, gcc and redhat-rpm-config
88+
as a compiler and configuratuion and finally python3.14-devel containing Python header files. There is no need to install those packages
89+
manually because the full container image already contains them. However, the application needs httpd as a runtime dependency
90+
so we need to install it to the minimal container image as well.
91+
92+
```
93+
# Part 1 - build
94+
95+
FROM python-314 as builder
96+
97+
# Add application sources to a directory that the assemble script expects them
98+
# and set permissions so that the container runs without root access
99+
USER 0
100+
ADD app-src /tmp/src
101+
RUN /usr/bin/fix-permissions /tmp/src
102+
USER 1001
103+
104+
# Install the application's dependencies from PyPI
105+
RUN /usr/libexec/s2i/assemble
106+
107+
# Part 2 - deploy
108+
109+
FROM python-314-minimal
110+
111+
# Copy app sources together with the whole virtual environment from the builder image
112+
COPY --from=builder $APP_ROOT $APP_ROOT
113+
114+
# Install httpd package - runtime dependency of our application
115+
USER 0
116+
RUN microdnf install -y httpd
117+
USER 1001
118+
119+
# Set the default command for the resulting image
120+
CMD /usr/libexec/s2i/run
121+
```
122+
123+
This way, the resulting container image does contain only necessary dependencies and it's much lighter.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Set current user in nss_wrapper
2+
USER_ID=$(id -u)
3+
GROUP_ID=$(id -g)
4+
5+
if [ x"$USER_ID" != x"0" -a x"$USER_ID" != x"1001" ]; then
6+
7+
NSS_WRAPPER_PASSWD=/opt/app-root/etc/passwd
8+
NSS_WRAPPER_GROUP=/etc/group
9+
10+
cat /etc/passwd | sed -e 's/^default:/builder:/' > $NSS_WRAPPER_PASSWD
11+
12+
echo "default:x:${USER_ID}:${GROUP_ID}:Default Application User:${HOME}:/bin/bash" >> $NSS_WRAPPER_PASSWD
13+
14+
export NSS_WRAPPER_PASSWD
15+
export NSS_WRAPPER_GROUP
16+
17+
LD_PRELOAD=libnss_wrapper.so
18+
export LD_PRELOAD
19+
fi

3.14-minimal/root/opt/wheels

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../src/root/opt/wheels/

0 commit comments

Comments
 (0)