Skip to content

Commit

Permalink
Add workaround for missing build packages (#639)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
fnordahl authored Sep 29, 2022
1 parent d56d76b commit 49a6541
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions charmtools/build/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import logging
import os
import requests
import subprocess
import sys
import uuid
import yaml
Expand Down Expand Up @@ -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.')

This comment has been minimized.

Copy link
@facundobatista

facundobatista Sep 30, 2022

Note the typo in "virutalenv"

This comment has been minimized.

Copy link
@fnordahl

fnordahl Oct 1, 2022

Author Collaborator

Note the typo in "virutalenv"

Ah, thank you for pointing that out. Will fix in next iteration.

subprocess.run(('apt', '-y', 'install', 'git', 'virtualenv'), check=True)

def generate(self):
layers = self.fetch()
self.formulate_plan(layers)
Expand Down Expand Up @@ -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()

Expand Down

0 comments on commit 49a6541

Please sign in to comment.