Charm development (Beginner, part 3)
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.
includes: - 'layer:basic' - 'layer:apt' - 'interface:mysql' options: apt: packages: - hello repo: firstname.lastname@example.org: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 <email@example.com> description: | This is a charm I built as part of my beginner charming tutorial. tags: - misc - tutorial requires: database: interface: mysql series: - 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:
Login to Ubuntu SSO
Press return to select a default value.
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: https://api.jujucharms.com/identity/v1/login?waitid=839719e2f3668e4224549ae5384ba083 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!