From 49a654170c36b5ea5144ade47f0f9fca6501ab86 Mon Sep 17 00:00:00 2001 From: Frode Nordahl Date: Thu, 29 Sep 2022 06:15:34 +0200 Subject: [PATCH] Add workaround for missing build packages (#639) The bare minimum of build packages may be missing following commit 2482f0f and commit 725d2cb. While the resolution may belong in charmcraft, we need a workaround. Fixes #638 --- charmtools/build/builder.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/charmtools/build/builder.py b/charmtools/build/builder.py index 76b5109..a0749ec 100755 --- a/charmtools/build/builder.py +++ b/charmtools/build/builder.py @@ -7,6 +7,7 @@ import logging import os import requests +import subprocess import sys import uuid import yaml @@ -773,6 +774,20 @@ def generate_python_modules_from_lock_file(self): lines.append(line) return lines + def workaround_charmcraft_maybe_ensure_build_packages(self): + """Workaround for missing build packages when in charmcraft build. + + The charmcraft reactive plugin ought to provide the bare minimum + of build package dependencies, however until it does let's help + here under the right circumstances. + """ + if (os.geteuid() == 0 + and (os.environ.get('CRAFT_PART_NAME', None) + or os.environ.get('CHARMCRAFT_PART_NAME', None))): + log.warning('Probably running as root in charmcraft, proactively ' + 'installing the `git` and `virutalenv` packages.') + subprocess.run(('apt', '-y', 'install', 'git', 'virtualenv'), check=True) + def generate(self): layers = self.fetch() self.formulate_plan(layers) @@ -1219,6 +1234,7 @@ def main(args=None): build.normalize_cache_dir() build.check_paths() build.maybe_read_lock_file() + build.workaround_charmcraft_maybe_ensure_build_packages() build()