Building your Charms with Github Actions

We do hope to introduce our own official Github Actions in the near future to simplify the user experience! In the meantime, there are a couple of options to build your charms with Github Actions (or similar CI systems):

(1) Use Charmcraft’s --destructive-mode on an OS that matches a build-on base configuration in your project’s charmcraft.yaml (for more information, check out Juju | Charmcraft Configuration). Today, this would mean configuring either ubuntu-18.04 or ubuntu-20.04 as the operating system, with a corresponding bases config.

(2) Use Charmcraft’s default, with LXD used to build Charms for all applicable bases. On Github Actions, this means setting up LXD for use by Charmcraft and running charmcraft with the correct permissions. For example:

      - name: Configure LXD
        run: |
          sudo groupadd --force --system lxd
          sudo usermod --append --groups lxd $USER
          sudo snap start lxd
          sudo lxd waitready --timeout=30
          sudo lxd init --auto

      - name: Build my Charm
        run: |
          sg lxd -c "charmcraft -v pack"
1 Like

That’s great! Thanks for sharing!

Could we go one step further and also publish to latest/edge with a CI?

For anyone interested in a concrete, working example for GitLab CI, using approach (1) from above:

# FILE: .gitlab-ci.yml
  stage: build
  - charmcraft pack --destructive-mode
    - '*.charm'

The Dockerfile for the build image used above is very simple, installing charmcraft as described in the README:

FROM ubuntu:22.04

ARG DEBIAN_FRONTEND=noninteractive

RUN apt-get update \
 && apt-get upgrade -y \
 && apt-get install -y \
    curl \
    git \
    libapt-pkg-dev \
    libffi-dev \
    libssl-dev \
    python3 \
    python3-pip \
    python3-venv \
 && apt-get clean \
 && pip3 install \
 && pip3 install charmcraft==$CHARMCRAFT_VERSION

I found helpful background details on --destructive-mode in Charmcraft bases & provider support.