I am currently checking in charms to a code repository without checking in lib/charmhelpers. After I check out a charm, I need to run scripts/charm_helpers_sync.py before the charm can be deployed to a machine in order to populate the lib/charm_helpers directory. Is there a way I can ask juju to do this for me before it bundles and pushes the files to the machine?
1 Answer
Since you want to run charm_helpers_sync.py
everytime you deploy the charm, I suspect you want to always have the latest version of python-charmhelpers
. There is a much easyer way to accomplish this:
Automatically install charmhelpers using python-pip
The following function installs the charmhelpers using the repository and python-pip.
def install_charmhelpers():
"""
Install the charmhelpers library, if not present.
"""
try:
import charmhelpers # noqa
except ImportError:
import subprocess
subprocess.check_call(['apt-get', 'install', '-y', 'python-pip'])
subprocess.check_call(['pip', 'install', 'charmhelpers'])
Call this function on the top of your hook scripts, above the charm-helper imports. Juju's python charm template shows a clean way to do this.
Write a Juju plugin to download charmhelpers source
If you really want Juju to download the charmhelpers code and include it in the charms, you'll have to write a Juju plugin.
- There was a talk about writing plugins on the Ubuntu Online Summit
- You can find other Juju plugins on the Juju plugin github page