How to pack your charm

See also:

You’ve initialised your charm and configured all the necessary files. This document shows you how you can now pack your charm. You can again do this with Charmcraft.

With a correct metadata.yaml and with ops in requirements.txt, packing your charm is as easy as running the following inside your charm directory:

$ charmcraft pack
Created 'my-new-charm.charm'.

In older docs you might find this given as charmcraft build. This is an alias maintained for backwards compatibility.

This will fetch any dependencies, compile any modules, check that all the key files are in place, and produce a compressed archive with the operator code and metadata as the charm.

The charm is just a zipfile with metadata and the operator code itself:

$ unzip -l my-new-charm.charm
Archive:  my-new-charm.charm
  Length      Date    Time    Name
---------  ---------- -----   ----
      221  2020-11-15 08:10   metadata.yaml
    25304  2020-11-15 08:14   venv/yaml/__pycache__/scanner.cpython-38.pyc
---------                     -------
   812617                     84 files

When the charm is packed, a series of analysis and lintings will happen, you may receive warnings and even errors to help improving the quality of the charm. To find out more, see Analyzers and linters.

This should be charmcraft pack, build is an alias for backwards compatibility

1 Like

Thanks, @sergiusens, I’ll update it. Does the output change in any way, or is just the command name?

1 Like

Just the command name :slight_smile: although that output is a little dated, the filename likely includes the base with later versions…


Fixed :smiley:

1 Like


If running charmcraft pack without LXD first being initialized, the packing process will fail and result in the following error message:

LXD has not been properly initialized.                                                       
Execute 'lxd init --auto' to initialize LXD. 

The error gets resolved after running ‘lxd init --auto’ as instructed.

I think it’s worth mentioning in this how-to guide.

Or maybe we could mention this in the doc on installing Charmcraft?

1 Like