Help getting started writing charms

Hi. I’m trying to write a charm for Rocket.Chat (just for learning purposes) using the snap layer.

So far I did charm create rocketchat, I edited the layer.yaml file to be:

includes:
  - layer:basic
  - layer:snap
options:
  snap:
      rocketchat-server:
      channel: stable
      devmode: false
      jailmode: false
      dangerous: false
      classic: false
      revision: null

I edited metadata.yaml to be:

name: rocketchat
summary: <Fill in summary here>
maintainer: David Coronel <David.Coronel@davecorelaptop>
description: |
  <Multi-line description here>
tags:
  # Replace "misc" with one or more whitelisted tags from this list:
  # https://jujucharms.com/docs/stable/authors-charm-metadata
  - misc
subordinate: false

I ran charm build and I juju deployed it to my localhost Juju cluster. The install hook fails and I get the following error:

unit-rocketchat-0: 16:20:00 ERROR unit.rocketchat/0.juju-log Hook error:
Traceback (most recent call last):
File “/var/lib/juju/agents/unit-rocketchat-0/.venv/lib/python3.6/site-packages/charms/reactive/init.py”, line 72, in main
hookenv._run_atstart()
File “/var/lib/juju/agents/unit-rocketchat-0/.venv/lib/python3.6/site-packages/charmhelpers/core/hookenv.py”, line 1206, in _run_atstart
callback(*args, **kwargs)
File “/var/lib/juju/agents/unit-rocketchat-0/charm/reactive/snap.py”, line 61, in install
supported_archs = snap_opts.pop(‘supported-architectures’, None)
AttributeError: ‘NoneType’ object has no attribute ‘pop’

I see some mentions of undocumented info in the snap layer at README.md - layer-snap - [no description]

Am I doing this right? Am I at least going in the right direction for someone who would want to charm Rocket.Chat?

Thanks!

It’s mostly correct but it looks like you have an indentation issue in your layer.yaml with the name of the snap:

 includes:
   - layer:basic
   - layer:snap
 options:
   snap:
-      rocketchat-server:
+    rocketchat-server:
       channel: stable
       devmode: false
       jailmode: false
       dangerous: false
       classic: false
       revision: null

The indentation there is important to ensure that the group of options is properly associated with the name of the snap to be installed.

2 Likes

Thanks! That was it.

Here’s what I did so far: https://github.com/davecore82/charm-test-rocketchat

3 Likes

Great work m8!

Did you use the tutorials posted here to get started or did you pick it up yourself?

1 Like

Great work! Do shout out if there’s anything else that pops up.

As your confidence grows, feel free to push charms to the charm store!

I used the tutorials posted here. I thought they were very useful. Thanks!

3 Likes