Re: [meta-virtualization][PATCH 2/7] recipes-containers/images: add app-container-python
Bruce Ashfield <[email protected]> Tue, 2 Jun 2026 08:02:46 -0400
| Newsgroups | org.yoctoproject.lists.meta-virtualization |
|---|---|
| Message-ID | <CADkTA4M-3-E+EVGrJ6fE3+i25w+mO5=t84dOoqDsT7H44uckJg@mail.gmail.com> |
On Tue, Jun 2, 2026 at 6:02 AM Paul Barker via lists.yoctoproject.org <paul= [email protected]> wrote: > On Fri, 2026-05-29 at 18:31 -0700, Tim Orling via lists.yoctoproject.org > wrote: > > Add OCI container image recipe for Python to use as a base for > > other Python app containers. The image uses multi-layer mode with > > separate base, terminal and python layers. > > > > Add ncurses-terminfo-base to a "terminal" layer to avoid warnings in the > > REPL: > > "Cannot read termcap database; > > using dumb terminal settings." > > > > Add coreutils to "python" layer to provide /usr/bin/env needed by > > python3-idle in python3-modules. > > > > Inherit container-nonroot-user and run a `nonroot` user by default. > > Set PACKAGECONFIG:pn-app-container-python = "dev" in local.conf or > > distro/image config to run as 'root' and include 'pip'. > > > > Signed-off-by: Tim Orling <[email protected]> > > --- > > .../images/app-container-python.bb | 57 +++++++++++++++++++ > > 1 file changed, 57 insertions(+) > > create mode 100644 recipes-containers/images/app-container-python.bb > > > > diff --git a/recipes-containers/images/app-container-python.bb > b/recipes-containers/images/app-container-python.bb > > new file mode 100644 > > index 00000000..a93f1b0f > > --- /dev/null > > +++ b/recipes-containers/images/app-container-python.bb > > @@ -0,0 +1,57 @@ > > +SUMMARY = "Base python3 container image" > > +DESCRIPTION = "OCI container image running Python with non-root user. \ > > +\ > > +In "dev" mode, can optionally run as 'root' and add 'pip' to allow \ > > +developers to simply run 'pip install' on top of this container (Not \ > > +advised for production/hardened use)." > > +LICENSE = "MIT" > > +LIC_FILES_CHKSUM = > "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420" > > + > > +# Multi-layer mode: create explicit layers instead of single rootfs > layer > > +OCI_LAYER_MODE = "multi" > > + > > +# Optional 'dev' mode: > > +# - adds python3-pip to the python layer (enables `pip install` at > runtime) > > +# - runs the container as root (UID 0) so pip can write to > site-packages > > +# Enable with: PACKAGECONFIG:pn-app-container-python = "dev" > > +PACKAGECONFIG ??= "" > > +PACKAGECONFIG[dev] = "" > > + > > +# Define layers: each layer contains specific packages > > +# Format: "name:type:content" where content uses + as delimiter for > multiple items > > +OCI_LAYERS = "\ > > + base:packages:base-files+base-passwd+netbase \ > > Hi Tim, > > I wonder if we should define the base layer contents in image-oci to > ensure that it is consistent across recipes. > > E.g. in image-oci.bbclass: > > OCI_BASE_LAYER = "base:packages:base-files+base-passwd+netbase" > > Then in the recipe: > > OCI_LAYERS = "\ > ${OCI_BASE_LAYER} \ > ... > " > > That gives consistency without forcing all OCI images to use the base > layer definition if it isn't relevant to them. > We can't (and shouldn't) enforce using packages at the base like that, since specifying layers as Tim is using is simply one way of doing it. It could just as easily be another image, or one of the other techniques. > > > + terminal:packages:ncurses-terminfo-base \ > > + > python:packages:python3+coreutils${@bb.utils.contains('PACKAGECONFIG', > 'dev', '+python3-pip', '', d)} \ > > +" > > + > > +# In 'dev' mode, override the nonroot UID inherited from > container-nonroot-user > > +# so the container runs as root (required for `pip install`). > > +OCI_IMAGE_RUNTIME_UID = "${@bb.utils.contains('PACKAGECONFIG', 'dev', > '0', '${NONROOT_UID}', d)}" > > + > > +# Use CMD so `docker run image /bin/sh` works as expected > > +OCI_IMAGE_CMD = "python3" > > + > > +IMAGE_FSTYPES = "container oci" > > +inherit image > > +inherit image-oci > > +inherit container-nonroot-user > > + > > +IMAGE_FEATURES = "" > > +IMAGE_LINGUAS = "" > > +NO_RECOMMENDATIONS = "1" > > + > > +# IMAGE_INSTALL triggers package builds via do_rootfs recrdeptask. > > +# Even for multi-layer mode, list packages here to ensure they're built. > > +# The PM will install them directly to layers from DEPLOY_DIR_IPK. > > +# Note: IMAGE_ROOTFS is still created but ignored for packages layers. > > +IMAGE_INSTALL = "base-files base-passwd netbase" > > Maybe we also need an OCI_BASE_PACKAGES to go with OCI_BASE_LAYER. > Pretty much every image is going to need these three packages installed. > Again, we shouldn't be overly prescriptive here. Factoring things out at this point is premature. Bruce > > > +IMAGE_INSTALL += "ncurses-terminfo-base" > > +IMAGE_INSTALL += "python3 coreutils" > > +IMAGE_INSTALL += "${@bb.utils.contains('PACKAGECONFIG', 'dev', > 'python3-pip', '', d)}" > > + > > +# Allow build with or without a specific kernel > > +IMAGE_CONTAINER_NO_DUMMY = "1" > > + > > +# Note: No ROOTFS_POSTPROCESS_COMMAND needed - IMAGE_ROOTFS is empty > > +# and PM handles installation directly to OCI layers > > Best regards, > > -- > Paul Barker > > > -=-=-=-=-=-=-=-=-=-=-=- > Links: You receive all messages sent to this group. > View/Reply Online (#9842): > https://lists.yoctoproject.org/g/meta-virtualization/message/9842 > Mute This Topic: https://lists.yoctoproject.org/mt/119557386/1050810 > Group Owner: [email protected] > Unsubscribe: https://lists.yoctoproject.org/g/meta-virtualization/unsub [ > [email protected]] > -=-=-=-=-=-=-=-=-=-=-=- > > -- - Thou shalt not follow the NULL pointer, for chaos and madness await thee at its end - "Use the force Harry" - Gandalf, Star Trek II