Pack a reactive based charm with Charmcraft

:construction: Available on Charmcraft’s edge channel

Charms can be created in different ways. By default, Charmcraft will use the Charmed Operator SDK, but by defining the appropriate parts it can be also used to pack other types of charms.

Step 1: Setting up a reactive charm project

Install the required tools

snap install charm --classic

And create a new project:

charm create tutorial

Change to the tutorial directory and modify metadata.yaml so it looks like the following:

name: tutorial
summary: test
maintainer: maintainer <maintainer@maintenance.com>
description: |
    Longer description than summary
tags:
  - misc
subordinate: false
series: [focal]

Step 2: Create charmcraft.yaml

Create a charmcraft.yaml file with the part definition for the reactive-based charm. The file contents should be:

type: "charm"
bases:
  - build-on:
      - name: "ubuntu"
        channel: "20.04"
    run-on:
      - name: "ubuntu"
        channel: "20.04"
parts:
  charm:
    source: .
    plugin: reactive
    build-snaps: [charm]

Step 3: Pack

To create the charm run the following:

$ charmcraft pack

The final output should look something like the following:

Charms packed:
    tutorial_ubuntu-20.04-amd64.charm

Step 4: Inspecting

The charm can be analyzed to verify everything is correct, to do so run:

$ charmcraft analyze tutorial_ubuntu-20.04-amd64.charm

The result should look something like the following:

Attributes:                                                                                                      
- language: unknown (https://juju.is/docs/sdk/charmcraft-analyze#heading--language)                              
- framework: reactive (https://juju.is/docs/sdk/charmcraft-analyze#heading--framework)                           
Lint OK:                                                                                                         
- juju-actions: no issues found (https://juju.is/docs/sdk/charmcraft-analyze#heading--juju-actions)              
- juju-config: no issues found (https://juju.is/docs/sdk/charmcraft-analyze#heading--juju-config)                
- metadata: no issues found (https://juju.is/docs/sdk/charmcraft-analyze#heading--metadata)