.. _charmcraft-yaml-file: ``charmcraft.yaml`` file ======================== .. AUTHOR NOTE: The full list of keys is defined in the Charmcraft project (but this implies upstream keys from craft-application): https://github.com/canonical/charmcraft/blob/3.2.0/charmcraft/models/project.py#L381-L1070 Technically, the only key required upfront is type. But then, depending on what you choose, other keys become required as well. (The required keys are the ones that are set to a value, unless that value is a pydantic.Field that doesn't have either a default or a default_factory parameter) The parts key connects to an external library. The plugin properties are defined here: https://canonical-craft-parts.readthedocs-hosted.com/en/latest/reference/part_properties.html This test file shows the full spec at once: https://github.com/canonical/charmcraft/blob/main/tests/unit/models/valid_charms_yaml/full.yaml .. important:: ``charmcraft.yaml`` file is the only ``yaml`` file generated by ``charmcraft init`` and the only ``yaml`` file in a charm project that a charm author should edit directly. Charmcraft will use the information you provide here to generate :ref:`actions-yaml-file`, :ref:`config-yaml-file`, and :ref:`metadata-yaml-file`, as well as all the other files it usually does. ``charmcraft.yaml`` is a file in your charm project that contains keys that allow you to declare information about the project in a form that can be used by Charmcraft. .. note:: If you're starting from an empty file, the only required key is the ``type`` key. However, depending on what value you set it to (``charm`` or ``bundle``), other keys become required as well. .. collapse:: Expand to view a full charm with sample content all at once .. literalinclude:: charmcraft-sample-charm.yaml :language: yaml .. _recipe-key-actions: ``actions`` ----------- Definition owned by `Juju`_. Used by `Charmcraft`_, `Charmhub`_, `Juju`_. **Status:** Optional. **Purpose:** Defines actions the charm can take. **Name:** String = user-defined action name. **Value:** Mapping. The value of this key is the contents of :ref:`actions-yaml-file`. .. collapse:: Example .. literalinclude:: charmcraft-sample-charm.yaml :language: yaml :start-at: actions: :end-before: analysis: .. _recipe-key-analysis: ``analysis`` ------------ Definition owned by `Charmcraft`_. Used by `Charmcraft`_. **Status:** Optional. **Purpose:** Defines how the analysis done on the package will behave. This analysis is run implicitly as part of the ``pack`` command but can be called explicitly with the ``charmcraft analyse`` command. **Structure:** .. code-block:: yaml analysis: ignore: attributes: [,...] linters: [,...] .. collapse:: Example .. literalinclude:: charmcraft-sample-charm.yaml :start-at: analysis: :end-before: assumes: .. _recipe-key-assumes: ``assumes`` ----------- **Status:** Optional. Recommended for Kubernetes charms. **Purpose:** Allows charm authors to explicitly state in the metadata of a charm various features that a Juju model must be able to provide to ensure that the charm can be successfully deployed on it. When a charm comes preloaded with such requirements, this enables Juju to perform a pre-deployment check and to display user-friendly error messages if a feature requirement cannot be met by the model that the user is trying to deploy the charm to. If the assumes section of the charm metadata is omitted, Juju will make a best-effort attempt to deploy the charm, and users must rely on the output of ``juju status`` to figure out whether the deployment was successful. **Structure:** The key consists of a list of features that can be given either directly or, depending on the complexity of the condition you want to enforce, nested under one or both of the boolean expressions ``any-of`` or ``all-of``, as shown below. In order for a charm to be deployed, all entries in the ``assumes`` block must be satisfied. .. code-block:: yaml assumes: - - any-of: - - - all-of: - - .. This should really go into the Juju docs, as they are the ones who parse it. .. list-table:: Supported features * - Structure - Description - Examples - Juju versions * - ``juju `` - The charm deploys iff the model runs agent binaries with the specified Juju version(s). - ``juju >= 3.0`` ``juju < 4.0`` - Since 2.9.23 * - ``k8s-api`` - The charm deploys iff the `backing cloud `_ for the model is Kubernetes. - ``k8s-api`` - Since Juju 2.9.23 .. collapse:: Simple example .. code-block:: yaml assumes: - juju >= 2.9.23 - k8s-api .. collapse:: Complex example .. literalinclude:: charmcraft-sample-charm.yaml :start-at: assumes: :end-before: base: .. _recipe-key-base: ``base`` -------- **Status:** Required in most cases if `type`_ is ``charm``. **Purpose:** Specifies the operating system on which the charm will build and run. **Structure:** .. code-block:: yaml base: @ **Example:** .. code-block:: yaml base: ubuntu@24.04 .. _recipe-key-bases: ``bases`` --------- .. note:: ``bases`` is deprecated, replaced by `base`_, `build-base`_, and platforms. .. collapse:: See more The ``bases`` key is only accepted for bases supported before 2024-01-01. .. code-block:: yaml # The run time base, the base format is @, # accepted bases are: # - ubuntu@22.04 # - ubuntu@24.04 base: # The build time base. Only used if the runtime base is not stable. # Accepts all runtime bases and ``ubuntu@devel`` build-base: # The supported platforms platforms: : build-on: | build-for: | **Status:** Deprecated. Conflicts with the `base`_, `build-base`_, and platforms keys. Not allowed if `type`_ is ``bundle``. **Purpose:** Specifies a list of environments (OS version and architecture) where the charm must be built on and run on. **Structure:** This key supports a list of bases where the charm can be built, and where that build can run. Each item can be expressed using two different internal structures, a short and a long form. The long one is more explicit: .. code-block:: yaml bases: - build-on: - name: channel: architectures: - run-on: - name: channel: architectures: - The ``run-on`` part of each entry is optional and defaults to what's specified in the corresponding ``build-on``. In both structures the list of architecture strings is also optional, defaulting to the architecture of the current machine. The short form is more concise and simple (at the cost of being less flexible): .. code-block:: yaml bases: - name: channel: architectures: - It implies that the specified base is to be used for both ``build-on`` and ``run-on``. As above, the list of architecture strings is also optional, defaulting to the machine architecture. .. collapse:: Example .. code-block:: yaml bases: - build-on: - name: ubuntu channel: '22.04' architectures: - amd64 - riscv64 - name: ubuntu channel: '20.04' architectures: - amd64 - arm64 run-on: - name: ubuntu channel: '22.04' architectures: - amd64 - name: ubuntu channel: '22.04' architectures: - riscv64 - name: ubuntu channel: '22.04' architectures: - arm64 - build-on: - name: ubuntu channel: '24.04' run-on: - name: ubuntu channel: '24.04' architectures: - amd64 - arm64 - riscv64 - s390x - ppc64el - armhf .. _recipe-key-build-base: ``build-base`` -------------- **Status:** Only valid if `base`_ is a development base. **Purpose:** Specifies the operating system on which the charm will be built. **Structure:** .. code-block:: yaml build-base: @ **Example:** .. code-block:: yaml base: ubuntu@devel .. _recipe-key-charm-libs: ``charm-libs`` -------------- **Status:** Optional. **Purpose:** Declares charm libraries for Charmcraft to include in the charm project. For each lib, include both the lib name (in ``.`` format) and the lib version (in ``"[.]"`` string format). **Structure:** .. code-block:: yaml charm-libs: - lib: . version: "[.]" # Must be a string, not a number. **Example:** .. literalinclude:: charmcraft-sample-charm.yaml :start-at: charm-libs: :end-before: config: .. _recipe-key-charmhub: ``charmhub`` ------------ .. caution:: This key is only meaningful in Charmcraft 2. Use the environment variables ``CHARMCRAFT_STORE_API_URL``, ``CHARMCRAFT_UPLOAD_URL`` and ``CHARMCRAFT_REGISTRY_URL`` for newer versions of Charmcraft. **Status:** Deprecated and nonfunctional in Charmcraft 3. **Purpose:** Configures Charmcraft's interaction with store servers. **Structure:** This key allows for the configuration of three values---the base URL for the Charmhub API, the base URL to push binaries to Charmhub and the URL of the container registry for OCI image uploads. These keys are also optional. .. code-block:: yaml charmhub: api-url: storage-url: registry-url: The key is used mostly in the context of "private" charm stores, defaulting to the standard Canonical services to operate with charms. .. collapse:: Example .. code-block:: yaml charmhub: api-url: https://api.staging.charmhub.io storage-url: https://storage.staging.snapcraftcontent.com .. _recipe-key-config: ``config`` ---------- See first: `Juju | Application configuration `_ **Status:** Optional. **Purpose:** Creates user-facing configuration options for the charm. **Structure:** .. code-block:: yaml config: options: # Each option name is the name by which the charm will query the option.