Skip to content

Instantly share code, notes, and snippets.

@facundobatista
Last active July 23, 2020 18:13
Show Gist options
  • Save facundobatista/e279a6e5adac93bb6b048cbf5a9fe96f to your computer and use it in GitHub Desktop.
Save facundobatista/e279a6e5adac93bb6b048cbf5a9fe96f to your computer and use it in GitHub Desktop.

Using charmcraft to build, upload and release charms

Through this tutorial we'll see the whole process of publishing a charm: building it, uploading it to the store, and releasing it.

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!

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

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 (can override 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment