Bug#985375: vmdb2: add option to 'apt' step for not installing recommends

2021-03-17 Thread Gunnar Wolf
tags -1 + pending,patch
thanks

I have submitted a merge request to the upstream author. I have _not_
yet tested this -- So, Andres, if you can try my proposed patch,
everybody will be happier ;-)

https://gitlab.com/larswirzenius/vmdb2/-/merge_requests/73/diffs

diff --git a/vmdb/plugins/apt.mdwn b/vmdb/plugins/apt.mdwn
index a05922a..e66454c 100644
--- a/vmdb/plugins/apt.mdwn
+++ b/vmdb/plugins/apt.mdwn
@@ -12,6 +12,10 @@ Step keys:
 
 * `packages`  REQUIRED; value is a list of packages to install.
 
+* `recommends`  OPTIONAL; defaults to true. Setting value to a
+  false (i.e. `0`, `null`, `false`) asks apt-get to run with the
+  `--no-install-recommends` option set.
+
 Example (in the .vmdb file):
 
 - apt: install
diff --git a/vmdb/plugins/apt_plugin.py b/vmdb/plugins/apt_plugin.py
index 09b8902..5f11855 100644
--- a/vmdb/plugins/apt_plugin.py
+++ b/vmdb/plugins/apt_plugin.py
@@ -28,7 +28,7 @@ class AptPlugin(vmdb.Plugin):
 
 class AptStepRunner(vmdb.StepRunnerInterface):
 def get_key_spec(self):
-return {"apt": str, "packages": [], "tag": "", "fs-tag": "", "clean": 
True}
+return {"apt": str, "packages": [], "tag": "", "fs-tag": "", "clean": 
True, "recommends": True}
 
 def run(self, values, settings, state):
 operation = values["apt"]
@@ -36,15 +36,16 @@ class AptStepRunner(vmdb.StepRunnerInterface):
 raise Exception('"apt" must always have value "install"')
 
 packages = values["packages"]
+recommends = values["recommends"]
 tag = values.get("tag") or None
 if tag is None:
 tag = values["fs-tag"]
 mount_point = state.tags.get_builder_mount_point(tag)
 
 if not self.got_eatmydata(state):
-self.install_packages(mount_point, [], ["eatmydata"])
+self.install_packages(mount_point, [], recommends, ["eatmydata"])
 state.got_eatmydata = True
-self.install_packages(mount_point, ["eatmydata"], packages)
+self.install_packages(mount_point, ["eatmydata"], recommends, packages)
 
 if values["clean"]:
 self.clean_cache(mount_point)
@@ -52,15 +53,19 @@ class AptStepRunner(vmdb.StepRunnerInterface):
 def got_eatmydata(self, state):
 return hasattr(state, "got_eatmydata") and getattr(state, 
"got_eatmydata")
 
-def install_packages(self, mount_point, argv_prefix, packages):
+def install_packages(self, mount_point, argv_prefix, recommends, packages):
 env = os.environ.copy()
 env["DEBIAN_FRONTEND"] = "noninteractive"
 
 vmdb.runcmd_chroot(mount_point, argv_prefix + ["apt-get", "update"], 
env=env)
 
+rec = ''
+if recommends:
+rec = '--no-install-recommends'
+
 vmdb.runcmd_chroot(
 mount_point,
-argv_prefix + ["apt-get", "-y", "--no-show-progress", "install"] + 
packages,
+argv_prefix + ["apt-get", "-y", "--no-show-progress", rec, 
"install"] + packages,
 env=env,
 )
 



Bug#985375: vmdb2: add option to 'apt' step for not installing recommends

2021-03-16 Thread Andres Salomon
Package: vmdb2
Version: 0.22-1
Severity: wishlist

I'm building a rock64 image using vmdb2, and I need to pull in
the u-boot-rockchip package for some prebuilt u-boot images. That
package has a Recommends on python3, which results in 300MB of bloat to
my install image AND python3-minimal is segfaulting.

Obviously the segfault is a separate problem, but the bloat is also an
issue. It would be nice if there was a way to tell vmdb2 not to install
recommends in the apt step.

Here's what I'm currently doing to work around it in the .yaml file:


  - apt: install
packages:
- ssh
- parted
- dosfstools
- linux-image-arm64
- grub-efi-arm64
#- u-boot-rockchip
tag: /
unless: rootfs_unpacked

  # u-boot-rockchip recommends python3, which bloats the image by 300MB
  # *and* causes a segfault in python3-minimal (something in
  # py3compile?).
  - chroot: /
shell: |
  apt-get install --no-install-recommends u-boot-rockchip
unless: rootfs_unpacked