How build charm for multiple bases with charmcraft 3.1+

I have a “hooks only” charm which uses the old charmcraft layout. It can be seen here: GitHub - erik78se/tiny-bash: A tiny bash juju charm for educational purposes

This charm is also used in documentation here: https://juju.is/docs/sdk/pack-a-hooks-based-charm-with-charmcraft so I would like it to work and be accurate.

I was trying to update this charm to build for the new 24.04 - which wasn’t supported by the above mentioned charm.

After some major trial and error:s going through the docs. I managed to get it to build for a single base ubuntu@24.04:

name: tiny-bash
type: charm
title: A tiny bash charm.
summary: |
  The tiny-bash deploys very fast.
description: |
  The tiny-bash charm that use "hooks only" to deploy.
  Since its super small and only uses hooks, it deploys very fast

base: ubuntu@24.04

platforms:
  amd64:
    build-on: amd64
    build-for: amd64

config:
  options: {}

parts:
  tiny-bash:
    plugin: dump
    source: .
    prime:
      - LICENSE
      - README.md
      - copyright
      - hooks
      - icon.svg

But as soon as I try to add any other bases or anything, I run into various of errors. For example, like this:

name: tiny-bash
type: charm
title: A tiny bash charm.
summary: |
  The tiny-bash deploys very fast.
description: |
  The tiny-bash charm that use "hooks only" to deploy.
  Since its super small and only uses hooks, it deploys very fast

bases:
  - build-on:
    - name: ubuntu
      channel: "24.04"
    run-on:
    - name: ubuntu
      channel: "24.04"
    - name: ubuntu
      channel: "22.04"


config:
  options: {}

parts:
  tiny-bash:
    plugin: dump
    source: .
    prime:
      - LICENSE
      - README.md
      - copyright
      - hooks
      - icon.svg

Bad charmcraft.yaml content: base requires ‘platforms’ definition: {‘name’: ‘ubuntu’, ‘channel’: ‘24.04’} (in field ‘bases[0]’)

Presently, I’m basically not able to add the support for multiple bases and at the same time swap to the new charmcraft.yaml format for charmcraft 3.0+.

Building on or for Ubuntu 24.04 requires single-base charms. There’s an open issue about support for multi-base charms, but no conclusion yet.

As of right now, the best way to do this is to have two charmcraft.yaml files: One with bases for older Ubuntu versions and a second with base and platforms for noble.

But how can I publish to charmhub my multiple versions of the same charm?

Could you give a specific example of how this would work? This is a blocker for the Observability team currently who are looking to add support for 24.04 to the grafana-agent subordinate charm.

Where would you envisage the two charmcraft.yaml files living, and how would you run charmcraft pack for each? Would you recommend leaving the existing charmcraft.yaml and adding a new directory charmcraft_24.04 with its own charmcraft.yaml and then running charmcraft pack --project-dir=.. to build the charm for 24.04, for instance?

1 Like

I tried symlinking into a sibling dir just for fun, but it didn’t work :slight_smile:

-> charm_24.04 $ ls -l
total 4
-rw-rw-r-- 1 ubuntu ubuntu 1255 Aug 23 07:40 charmcraft.yaml
lrwxrwxrwx 1 ubuntu ubuntu   20 Aug 23 07:41 config.yaml -> ../charm/config.yaml
lrwxrwxrwx 1 ubuntu ubuntu   12 Aug 23 07:41 lib -> ../charm/lib
lrwxrwxrwx 1 ubuntu ubuntu   22 Aug 23 07:41 metadata.yaml -> ../charm/metadata.yaml
lrwxrwxrwx 1 ubuntu ubuntu   23 Aug 23 07:42 pyproject.toml -> ../charm/pyproject.toml
lrwxrwxrwx 1 ubuntu ubuntu   25 Aug 23 07:42 requirements.txt -> ../charm/requirements.txt
lrwxrwxrwx 1 ubuntu ubuntu   12 Aug 23 07:41 src -> ../charm/src
lrwxrwxrwx 1 ubuntu ubuntu   16 Aug 23 07:42 tox.ini -> ../charm/tox.ini

-> charm_24.04 $ charmcraft pack
...
charm entry point must be inside the project: '/root/charm/src/charm.py' in field 'charm-entrypoint'

And how about if charm_24.04 only has the charmcraft.yaml file (no symlinks to the other files) and you run charmcraft pack --project-dir=..?

It takes charmcraft.yaml from project-dir.