How to set local charm path in bundle file
fengxia
fxia1 at lenovo.com
Fri Aug 4 14:07:46 UTC 2017
I ended up writing a pytohn script to condition bundle file which
populates charm with its absolute path. Paste here hope it will help
someone running into this:
import os, yaml
def check_charm_path_in_bundle(bundle_yml, dist=None):
"""Parse bundle file and replace charm path with absolute path.
By default `charm build` will create a subfolder `./dist/trusty`
in the charm folder itself. However, $JUJU_REPOSITORY can set to
an arbitrary path in the system even though it says Juju 2.x
doesn't observe this value anymore
(https://github.com/juju/docs/pull/1980). This is problematic for
bundle, because its charm path must be in form of a file path for
Juju to know charms are **local** (otherwise, it will search charm
store). So the only solution is to use absolute path in bundle.
"""
if not os.path.exists(bundle_yml):
print 'bundle YAML not found'
return False
# get absolute path for dist
if dist:
dist = os.path.abspath(dist)
else:
# if no dist path is given, fall back to $JUJU_REPOSITORY
dist = os.path.abspath(os.environ['JUJU_REPOSITORY'])
# parse bundle file and match with charms in /dist
bundle = yaml.load(open(bundle_yml))
machines = bundle['machines']
for charm, detail in bundle['services'].iteritems():
# Detail['to'] is a list. Each machine can then
# be different OS, eg. 1 is xenial, 2 is trusty.
# Here we are ignoring them, and only pick the first one.
m = detail['to'][0]
series = machines[m]['series']
charm_path = os.path.join(dist, series, charm)
if not os.path.exists(charm_path):
print 'charm %s at %s not found:' % (charm, charm_path)
return False
bundle['services'][charm]['charm'] = charm_path
# write back to bundle file
with open(bundle_yml, 'w') as f:
f.write(yaml.dump(bundle))
On 08/03/2017 08:54 PM, fengxia wrote:
>
> Thanks Dmitrii.
>
> This is... not exactly an ideal in my case. The bundle file is a
> static, and charms are built by a CI. So I would rather have a cleaner
> way to decouple the two. In other words, CI can have a /dist somewhere
> it feels so, and bundle only needs know the charms are local, and
> using sth like the OS environment variable (or a Juju config of some
> kind?) to link the two.
>
> Another question then, I know $JUJU_REPOSITORY is still used in `charm
> build` to indicate where the built charms will be. Reading the note,
> does it mean it is not used there either? But in Juju version
> 2.0.2-xenial-amd64 it still is.
>
>
> On 08/03/2017 04:40 PM, Dmitrii Shcherbakov wrote:
>> Hi Feng,
>>
>> Just use an absolute path:
>>
>> https://github.com/juju/docs/pull/1980
>>
>> Best Regards,
>> Dmitrii Shcherbakov
>>
>> Field Software Engineer
>> IRC (freenode): Dmitrii-Sh
>>
>> On Thu, Aug 3, 2017 at 11:34 PM, fengxia <fxia1 at lenovo.com
>> <mailto:fxia1 at lenovo.com>> wrote:
>>
>> Hi Juju,
>>
>> Trying to deploy a bundle which consists of local charms.
>>
>> $JUJU_REPOSITORY=/home/fengxia/workspace/dist
>>
>> in this folder, all charms are in "trusty/"
>>
>> Bundle file is located in /home/fengxia/workspace/project/test.yaml:
>>
>> services:
>> # solution
>> solution:
>> charm: ./trusty/solution
>> num_units: 1
>>
>> But juju deploy tet.yaml yields an error:
>>
>> ERROR the provided bundle has the following errors:
>> charm path in application "solution" does not exist:
>> /home/fengxia/workspace/project/trusty/solution
>>
>> Looks to me that it ignores the $JUJU_REPOSITORY setting, and
>> looking for the charm in local directory instead. I know
>> "./trusty/solution" is pointing it this way.
>>
>> So question now is, what's the right setting in bundle when
>> charms are NOT in the same folder as the bundle file?
>>
>> --
>> Feng xia
>> Engineer
>> Lenovo USA
>>
>> Phone: 5088011794
>> fxia1 at lenovo.com <mailto:fxia1 at lenovo.com>
>>
>> Lenovo.com
>> Twitter | Facebook | Instagram | Blogs | Forums
>>
>>
>> --
>> Juju mailing list
>> Juju at lists.ubuntu.com <mailto:Juju at lists.ubuntu.com>
>> Modify settings or unsubscribe at:
>> https://lists.ubuntu.com/mailman/listinfo/juju
>> <https://lists.ubuntu.com/mailman/listinfo/juju>
>>
>>
>
> --
> Feng xia
> Engineer
> Lenovo USA
>
> Phone: 5088011794
> fxia1 at lenovo.com
>
> Lenovo.com
> Twitter | Facebook | Instagram | Blogs | Forums
>
>
--
Feng xia
Engineer
Lenovo USA
Phone: 5088011794
fxia1 at lenovo.com
Lenovo.com
Twitter | Facebook | Instagram | Blogs | Forums
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/juju/attachments/20170804/7b00db41/attachment.html>
More information about the Juju
mailing list