For anyone interested in a concrete, working example for GitLab CI, using approach (1) from above:
# FILE: .gitlab-ci.yml
charm:
image: registry.gitlab.com/en-ser-public/gitlab-cicd-docker/build-charms-docker
stage: build
script:
- charmcraft pack --destructive-mode
artifacts:
paths:
- '*.charm'
The Dockerfile
for the build image used above is very simple, installing charmcraft as described in the README:
FROM ubuntu:22.04
ARG CHARMCRAFT_VERSION=2.2.0
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 https://launchpad.net/ubuntu/+archive/primary/+sourcefiles/python-apt/2.3.0ubuntu2/python-apt_2.3.0ubuntu2.tar.xz \
&& pip3 install charmcraft==$CHARMCRAFT_VERSION
I found helpful background details on --destructive-mode
in Charmcraft bases & provider support.