How to ensure charm apt dependencies
See original GitHub issueBefore a charm does ‘import yaml’ or ‘import psycopg2’, we need to ensure that these non-core dependencies are installed on the host system.
Currently, it looks like we need a stanza like this at the start of src/charm.py:
EDIT(niemeyer): Please don’t do that as it’s an ugly hack. See notes below.
import subprocess
try:
import yaml
import psycopg2
except ImportError:
subprocess.check_call([
'apt-get', '--assume-yes', '--option=Dpkg::Options::=--force-confold', 'install',
'python3-yaml', 'python3-psycopg2',
])
import yaml
import psycopg2
I don’t think we can hide this uglyness in hooks/install, as it is expected to be a symlink.
It would be best if this could somehow be bootstrapped using code in the operator framework, so that the ‘apt-get installs’ get run in a consistent manner with any OS release specific settings.
Perhaps the operator framework could detect at import time that it is a) being imported from a script in hooks/* b) in a hook environment, and if so run platform specific bootstrapping to install apt packages listed in a .txt or .yaml file. Extra points if we can support PPAs, but they are much more likely to contain application dependencies that the charm should be installing, rather than charm dependencies needed for the charm code to run.
Issue Analytics
- State:
- Created 4 years ago
- Comments:11 (9 by maintainers)
Top GitHub Comments
Ah indeed, I should learn to read the title of issues before replying to them (apt dependencies).
I believe that this is addressed well by charmcraft, or by charmcraft plans.