The new release of Charmcraft 2.0, currently in beta (planned for candidate in some days, stable a week after that) brings several new features, but also as you can expect from a major version update (and the title of this post) some backwards compatibility is not fully maintained.
The following are the breaking changes and alternatives to keep everything nice and green, but before getting into those details let me remind you that if you want to stay out of this update, and keep the Charmcraft as you know it today, you only need to follow the 1.x track; if you’re not there already it’s easy to switch:
sudo snap switch charmcraft --channel=1.x/stable
So, the changes:
-
A
basesconfiguration is now required incharmcraft.yaml(so far it was optional, deprecated since Charmcraft 1.1). If you still don’t have this key, the following was the default until now (so probably what you want to keep):... bases: - build-on: - name: "ubuntu" channel: "20.04" run-on: - name: "ubuntu" channel: "20.04" ... -
Use
charm-entrypointincharmcraft.yamlparts to define the entry point. The--entrypointcommand line option was deprecated in Charmcraft 1.2 and now it’s not available anymore. Note that if the option is not included in the file, the defaultsrc/charm.pyis still valid and used.Example configuration:
... parts: charm: charm-entrypoint: "src/my_entrypoint.py" ... -
Use
charm-requirementsincharmcraft.yamlparts to specify any particular Python requirements file. The--requirementscommand line option was deprecated in Charmcraft 1.2 and it’s no longer present. Note that if the option is not included, and arequirements.txtfile is present in the project’s root, it will be used.Example configuration:
... parts: charm: charm-requirements: ["reqs1.txt", "reqs2.txt"] ... -
Use the
packcommand to pack the project into a.charmfile. Thebuildcommand was deprecated in Charmcraft 1.5 and is now removed (this verb will have a different meaning in the future).$ charmcraft help pack Usage: charmcraft pack [options] Summary: Build and pack a charm operator package or a bundle. ... -
The
--traceoption to set a verbosity level was removed after the introduction of Craft CLI 1.0. The--quietand--verboseoptions still remain available, and you also can use the new--verbosity=LEVELoption (allowed levels arequiet,brief,verbose,debugandtrace).E.g.:
$ charmcraft pack --verbosity=trace ... (a **very** verbose output) ... -
After starting to use the new version of Craft CLI, several progress and output messages were improved. If you were using charmcraft programmatically and parsing those messages, you should start using the
--format=jsonoption (introduced in Charmcraft 1.7) to get commands results in an easier way to consume from other programs.E.g.:
$ charmcraft revisions mycharm --format=json | jq .[0].revision 4 -
The JSON-formatted output for the
statuscommand was improved: thechannelskey (that holds everything released for a track) was renamed tomappings, and thechannelvalue in each release now properly includes the track (fixed the bug of showing only the risk or risk/branch).