How to configure Charmcraft

See also:

You have installed Charmcraft. This document shows you how you can configure it.

Configuring Charmcraft is mandatory for all project-handling commands, though optional for some store-related commands.

Contents:

Find the configuration file

The charmcraft tool configuration is specified in a charmcraft.yaml file located in the project’s root directory.

By default, Charmcraft will try to find that file in the current directory, but in case of needing to run charmcraft outside the project’s directory, it can be specified using the global option --project-dir.

Get acquainted with its contents

See charmcraft.yaml.

Consult some examples

The following illustrate some implementations of the above spec:

type: bundle
charmhub:
  # these fields are set to the default value to illustrate field usage
  # likely not required in most cases
  api-url: https://api.charmhub.io
  storage-url: https://storage.snapcraftcontent.com
parts:
  bundle:
    prime: ["README.md"]

A different example, with a more comprehensive base definition:

type: charm
bases:
    - build-on:
        - name: ubuntu
          channel: "20.04"
          architectures: ["amd64"]
      run-on:
        - name: ubuntu
          channel: "21.04"
          architectures: 
              - amd64
              - aarch64
              - arm64

Start configuring!

Start modifying the examples above to suit your own needs.

1 Like

@facundo without quotation marks I am getting

Bad charmcraft.yaml content:
- string type expected in field 'bases[0].channel'

not sure if it should be a feature (convert to string) or should add quotation marks here

20.04 is a float. While we could convert this one to string automatically (and get "20.04", we do NOT want to get into the situation of converting 20.10 to "20.1".

So please use quotation marks around it. Thanks!

Thanks. Added.

@facundo The dash ("-") should be removed. With the current yaml I get the following error:

ERROR    Bad charmcraft.yaml content:
- field 'run-on' required in 'bases[0]' configuration
- field 'build-on' required in 'bases[1]' configuration
1 Like

Thanks! Fixed.

I understand there’s also a build-packages option to parts/charm. Could that be added here, it’s been asked about a few times by different people on Mattermost ?

1 Like

Unless I misread this, it is not specified under what path, the files listed under prime are included in the charm container. Also in the case of a bundle what path are prime files mapped into and for which charm ?

The files are included in the same path that are in the project (the root of the charm file would be root dir of the project itself).

If it’s a bundle, there are no “charms”. A bundle specifies a collection of charms but those charms are not inside the produced zip file.

Is it possible to have per-base configuration of the charms-python-packages property? See this github discussion for reference, where setuptools needs to be on v58 or lower for support on Bionic charms. It would be nice if charmcraft.yaml could have this specified for each Ubuntu base as needed.

Could this be added, and can anyone confirm if stage-packages should work as a way of installing packages in the charm at run time (or if there’s another way to do that - I’ve tried it without success)?

Is it necessary to specify the bases for a bundle? What happens if the bases in the bundle differ from the charm’s bases? Will the run-on from the charms be overwritten by the values on the bundle file?

No. bases is not needed, and in fact forbidden as a key, when packing a bundle.

Ah, got it! Do you know how to specify that a bundle can run on different OSes? We have charms that run on Ubuntu and Centos, but I can only specify one series in the bundle file, so when I upload to charmhub it shows only one OS in there. The bundle I am working on is: charmhub.io/slurm

Hey there @facundo! I was wondering if we could add override-build as an available key for the charm section of parts? As I had mentioned in my issue on the charmcraft repository, I had no idea override-build was an available option for charmcraft.yaml until you showed me that separate discourse post.

I think it would be beneficial to add override-build to the section I quoted above. This way, folks who have edge cases like myself will know they can inject some custom actions into the charmcraft.yaml file when reading the sdk documentation.

Let me know what your thoughts are!