[Tutorial] Using charmcraft to build, upload and release charms

Overview

Duration: 0:10

Through this tutorial we’ll see the whole process of publishing a charm: building it, uploading it to the store, and releasing it. There’s this video version of this content.

NOTE: currently the Store support is under development, so all these actions are done against staging, there are no guarantees over the stored information.

For simplicity we start by having a ready-to-build charm. If you want to start from a previous step, please check this other tutorial on how to build a charm using modern tools.

$ ll
total 16
-rw-rw-r-- 1 facundo facundo  180 jul 23 13:27 metadata.yaml
-rw-rw-r-- 1 facundo facundo    4 jul 23 13:24 requirements.txt
drwxrwxr-x 2 facundo facundo 4096 jul 23 13:25 src
-rw-rw-r-- 1 facundo facundo    4 jul 23 13:38 version
$ ll src/
total 4
-rwxrwxr-x 1 facundo facundo 447 jul 23 13:25 charm.py

Let’s do it!

Duration: 2:00

As I said, the first step is building the charm:

$ charmcraft build
Done, charm left in 'storestory.charm'

As the command indicated, I have my charm binary built:

$ ll storestory.charm 
-rw-rw-r-- 1 facundo facundo 226648 jul 23 14:54 storestory.charm

If this is our first time with this charm, we will need to register this name in the Store:

$ charmcraft register storestory
Congrats! You are now the publisher of 'storestory'

NOTE: All commands to the Store needs for us to be authenticated. This is handled automatically by charmcraft: if the credentials expired or not found a browser page will open for us to authenticate against the Store as we usually do in the web. We can always check how is our authentication status by issuing charmcraft whoami.

If in doubt, we can easily check all our registered names:

$ charmcraft names
Name            Visibility    Status
...
storestory      public        registered
...

Uploading

Duration: 1:00

Now we’re ready to upload the binary. As we’re in our project’s directory the command is very simple (otherwise we would need to use the --charm-file option to specify the binary’s location):

charmcraft upload
Revision 1 of 'storestory' created

Everytime we upload a new binary for the charm we get a new revision in the Store. We can verify its current status easily:

$ charmcraft revisions
Revision    Version    Created at    Status
1           0.1        2020-07-23    approved

Note that we didn’t specify the charm’s name: this is because we’re in the project’s directory, so the name is retrieved automatically; if you want to ask for any other charm you can use the --name option.

Now it’s time to release!

$ charmcraft release beta
Revision 1 of charm 'storestory' released to beta

As before, release uses current project for the naming (you can override it with --name) and releases the last uploaded revision (you can specify a different one with --revision).

Finally, we can see the overall status:

$ charmcraft status
Track    Channel    Version    Revision
latest   stable     -          -
         candidate  -          -
         beta       0.1        1
         edge       ↑          ↑

Enjoy.

2 Likes

Can you change the title of the post to [Tutorial] xxxxx? This is great for spotting them out here in the forum. Sane thing with the referenced “how to build a charm using modern tools”.

I would love to know also about private namespaces for charms and how to remove charms if that’s possible?