Skip to content

Commit

Permalink
create/init: add init-time env vars and gate and define one for zyppe…
Browse files Browse the repository at this point in the history
…r weak deps

In case one really wants for recommended packages to stay disabled in an
opensuse image, make it possible to control this with an environment
variable. It's called DBX_CONTAINER_INIT_ZYPPER_NORECOMMENDS and must be
defined to either 'false' (i.e., the default, as we do want recommended
packages) or 'true'.

The variable, if present, is defined inside the environment of the
container. Then, in distrobox-init, we can check if it is there, and act
accordingly. So, for keeping recommended packages out, something like
this should be done:

  DBX_CONTAINER_INIT_ZYPPER_NORECOMMENDS=true distrobox create ...

While there, implement this in a bit more of a generic way. Basically,
all variables with a name that starts with DBX_CONTAINER_INIT_* that
distrobox-create finds defined, are included in the environment of the
container, so that distrobox-init can take advantage of them, to further
customize things.

This is somewhat similar to #220, but it's not really the same. In fact,
there, a mechanism for user-provided and generic pre-init customization
is advocated. This one can be used (and is, in the case of zypper's weak
deps) for very specific changes.

Note that, on openSUSE, the package 'parallel-printer-support' is
explicitly locked out of installation. This is because the package, when
installed, tries to creade device files (/dev/lp0, etc), which does not
work for rootless podman.

Signed-off-by: Dario Faggioli <dfaggioli@suse.com>
  • Loading branch information
dfaggioli committed May 6, 2022
1 parent ca1be73 commit 1f55fdd
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
9 changes: 9 additions & 0 deletions distrobox-create
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
# DBX_CONTAINER_MANAGER
# DBX_CONTAINER_NAME
# DBX_NON_INTERACTIVE
# Optional container init variables:
# DBX_CONTAINER_INIT_ZYPPER_NORECOMMENDS

trap '[ "$?" -ne 0 ] && printf "\nAn error occurred\n"' EXIT

Expand Down Expand Up @@ -505,6 +507,13 @@ generate_command() {
# Add additional flags
result_command="${result_command} ${container_manager_additional_flags}"

# Add init-time environment variables. The only requirement is that
# their name begins with DBX_CONTAINER_INIT_. They'll (likely!) be
# consumed by container-init, or ingeneral inside of the distrobox.
for i in $(printenv | grep '=' | grep -Ev ' |"' | grep '^DBX_CONTAINER_INIT_'); do
result_command="${result_command} --env \"${i}\""
done

# Now execute the entrypoint, refer to `distrobox-init -h` for instructions
result_command="${result_command} ${container_image}
/usr/bin/entrypoint -v --name \"${container_user_name}\"
Expand Down
13 changes: 11 additions & 2 deletions distrobox-init
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,15 @@ mount_bind() (
# for users that, for instance, want to run GUI apps in their distroboxes.
# In fact, we expect that most users would want recommended packages (which
# are enabled by default in "regular" openSUSE/SUSE installations) in their
# boxes, so let's re-enable them.
# boxes, so let's re-enable them by default.
#
# If wanting to keep them disabled, the user can define to false the
# DBX_INIT_ZYPPER_NO_RECOMMENDS env variable.
[ "${DBX_CONTAINER_INIT_ZYPPER_NORECOMMENDS:-}" = "" ] && DBX_CONTAINER_INIT_ZYPPER_NORECOMMENDS=false
if [ -f /etc/zypp/zypp.conf ]; then
sed -i 's/.*solver.onlyRequires.*/solver.onlyRequires = false/g' /etc/zypp/zypp.conf
sed -i "s/.*solver.onlyRequires.*/solver.onlyRequires = ${DBX_CONTAINER_INIT_ZYPPER_NORECOMMENDS}/g" /etc/zypp/zypp.conf
fi
unset DBX_CONTAINER_INIT_ZYPPER_NORECOMMENDS

# Extract shell name from the $SHELL environment variable
# If not present as package in the container, we want to install it.
Expand Down Expand Up @@ -418,6 +423,10 @@ if ! command -v find || ! command -v mount || ! command -v passwd ||
SHELL="/bin/bash"
shell_pkg="bash"
fi
# The 'parallel-printer-support' would try to create /dev/lpN
# device file, which may not work. Make sure we keep it out,
# as a workaround for that.
zypper al parallel-printer-support
zypper install -y \
"${shell_pkg}" \
findutils \
Expand Down
8 changes: 8 additions & 0 deletions docs/usage/distrobox-create.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ Supported environment variables:
DBX_CONTAINER_NAME
DBX_CONTAINER_IMAGE

Variables that have a name that starts with `DBX_CONTAINER_INIT_` will be added to the environment
of the container. They are typically used for controlling some initialization time behavior, and/or
for doing some customization of the image, suitable for being done during the init phase.

Supported container-init variables:

DBX_CONTAINER_INIT_ZYPPER_NORECOMMENDS must be either =true or =false (default)

Options:

--image/-i: image to use for the container default: registry.fedoraproject.org/fedora-toolbox:35
Expand Down

0 comments on commit 1f55fdd

Please sign in to comment.