[Tutorial] Charm development (Beginner, part 1)

Right, I will remove the JUJU_REPOSITORY variable entirely then to reduce any implicit needs for a beginner.

@munir12 I’ve taken your advice and if you like to have a look at my new thread here: https://discourse.jujucharms.com/t/charm-problems-with-bash-hooks/1229

when you run charm create layer-example, it will actually use layer-example as the final charm name, which is not as expected.
After charm build layer-example, you will get:

  • a charm named layer-example in ~/charms/builds/
  • In metadata.yaml of the charm, you will see name: layer-example
  • in reactive dir, you wil see file layer-example.py, and apt.py for layer-apt, which are inconsistent in names.
  • in layer-example.py, you will see flag layer-example.installed and hook func def install_layer_example(), while apt layer doesn’t work with names like that.

There are more examples like above, in which the prefix layer- should not exist. I think the prefix layer- should only be used for repo name. So a smooth process to create a layered charm will be:

cd ~/charms/layers
charm create example
# edit files in example/
# create git repo `layer-example` and push
charm build example
cd ~/charms/builds/example
# deploy or push to charm store

You are probably right here. Its probably worth fixing too.

1 Like

I got:

sudo juju deploy ./example
ERROR invalid charm “example”: has no hooks

Any suggestion how to fix it?

Hello and welcome to the community.

To be able to help, could you provide a bit more context?

A separate suggestion is to avoid running juju as the root user. Sudo is a powerful tool, and it can (and will) create problems for you.