[Tutorial] Charm development (Beginner, part 3)

Charm development (Beginner, part 3)

Difficulty: Beginner Author: Erik Lönroth

This tutorial builds on the previous Charm development (Beginner, Part 2):

What you will learn

  • Make your charm proper to be shared with the community
  • Target a specific version (series) of ubuntu for the charm.
  • Push a charm to your account in the charmstore
  • Deploy your example charm from the charmstore

Adding a repo to ‘layer.yaml’

Having a repo key helps others contribute to your charm.

Go ahead and a link to your repo last in the ** layer.yaml ** file. It should look like this where you replace the link to your own code.

  - 'layer:basic'
  - 'layer:apt'
  - 'interface:mysql'
     - hello 
repo: git@github.com:erik78se/layer-example.git

Define a “series” in metadata.yaml

To help juju know which version of ubuntu your charm works best for, add a series tag to metadata.yaml.

Lets add an entry for both Ubuntu 16.04 (xenial) and 18.04 (bionic):

name: example
summary: A very basic example charm
maintainer: Your Name <your.name@mail.com>
description: |
  This is a charm I built as part of my beginner charming tutorial.
  - misc
  - tutorial
    interface: mysql
  - xenial
  - bionic

Rebuild the charm.

cd ~/charms/layers
charm proof layer-example
charm build layer-example

build: Composing into /home/erik/charms
build: Destination charm directory: /home/erik/charms/builds/example
build: Processing layer: layer:basic
build: Processing layer: layer:apt
build: Processing layer: example (from layer-example)
build: Processing interface: mysql
proof: I: Includes template icon.svg file.
proof: W: Includes template README.ex file
proof: W: README.ex includes boilerplate: - Upstream mailing list or contact information
proof: W: README.ex includes boilerplate: - Feel free to add things if it's useful for users
proof: I: all charms should provide at least one thing

Your charm now ends up in the “Destination charm directory”. In my case /home/erik/charms/builds/example

This is what we will push up to charmstore soon.

Your account on charmstore

Before you can push, you need a private Ubunu One account.

Go ahead and create your Ubuntu One account here.

Remember your account name, we are going to use it below. In my case its ‘erik-lonroth’.

Test to login via a browser

Your Ubuntu One account gives you a private namespace for your charms.

It will be accessible in a URL something like this:


Go ahead and browse your private namespace a bit. It will likely be feeling a bit empty, but we’ll soon add the charm in there.

Lets log in to charmstore from your build environment so we can push.

Log in to charmstore

Run this to login:

cd ~/charms/layers charm login Login to Ubuntu SSO Press return to select a default value. E-Mail: erik.lonroth@gmail.com Password: Two-factor auth (Enter for none):

After your have mangaged to login, you can now ‘push’ the compiled charm to it.

Push to charmstore

Lets push the example charm to charmstore:

cd ~/charms/builds/example
charm push .
url: cs:~erik-lonroth/example-0
channel: unpublished

The charm is now pushed to a namespace in charmstore private to you. (Note: Nobody else can use it but you.)

Lets try deploy it!

Deploy from charmstore

Once a charm is uploaded to charmstore, it can be deployed with the url given by the output for the push command (in my case: cs:~erik-lonroth/example-0 )

Lets try deploy, but remember to remove any previous example charm you have in your model before you try deploying.

juju remove-application example

removing application example

juju deploy cs:~erik-lonroth/example-0

Opening an authorization web page in your browser.
If it does not open, please open this URL:
Created new window in existing browser session.
Located charm "cs:~erik-lonroth/example-0".
Deploying charm "cs:~erik-lonroth/example-0".

You should now be able to watch your example charm being deployed.

watch -c juju status --color

Congratulations! You have completed the beginner level tutorial series on juju charming!

You are now ready to take on intermediate level development, starting with a tutorial on relations here: [Tutorial] Relations with Juju


Good stuff.

watch juju -c juju status --color

Should be:

watch -c juju status --color

1 Like

Thanks for the typo fix!

1 Like

@erik-lonroth Sir the hooks part is missing in this tutorial series. Hooks are important in charm writing and whole charm’s relations are defined in hooks.
i would like to suggest that do make a tutorial on hooks and complete this series. there are many other things that need to be addressed.
hope you’ll look forward to it and will give positive response…
Thanking in advance.


@munir12 Very good input. However, I’ve come to believe that hooks are a legacy way of implementing charms. I think that writing charms with the “hooks” method is somewhat different to “reactive” method. I’m happy to discuss this in a separate thread if you like? Perhaps ask a few gurus for advice on this if you are not one such =)

@erik-lonroth as far as my knowledge is concerned about charms, i only know that, the reactive programming is based on hooks. correct me if i’m wrong?
yes sure i would like to discuss it with you, knowledge sharing will be helpful & effective.

i don’t know such gurus that you’re suggesting me about, let me know if you know any of such guru(s).
when you’ll be able to complete this series? if i may ask.

Feel free to open up a new thread on the topic ‘reactive’ vs ‘hooks’. I’m happy to get that cleared out myself as I see many different styles of developing charms today.

1 Like