Skip to main content

Fast first-time builds for charmcraft

Project description

charmcraftcache

Reinventing the wheel

Fast first-time builds for charmcraft—on a local machine or CI

Installation

Install pipx: https://pipx.pypa.io/stable/installation/

pipx install charmcraftcache

Usage

For best results, use charmcraft's Poetry plugin or add charm-strict-dependencies: true to your charmcraft.yaml.

Step 1: Update charmcraft.yaml to supported syntax

Only "multi-base shorthand notation" syntax is supported

Example

platforms:
  ubuntu@22.04:amd64:
  ubuntu@22.04:arm64:
  ubuntu@24.04:amd64:
  ubuntu@24.04:arm64:

Under the charmcraft.yaml platforms key, build-on and build-for syntax are not supported

The base and bases charmcraft.yaml keys are not supported

Step 2: Add your charm to the cache

ccc add

Step 3: Pack your charm

ccc pack

How it works

Why are charmcraft builds slow?

Instead of downloading wheels from PyPI (which pip does by default), charmcraft builds Python package wheels from source (i.e. with pip install --no-binary).

Caching mechanism

charmcraft builds each charm platform in a separate LXC container[^1]. Within each container, pip has an internal cache for wheels built from source & for HTTP responses.

charmcraft 2.5 moved the pip internal cache to the LXC host machine, so that one pip cache is used for all LXC containers. (This increases the chance of a cache hit—a faster build.)

However, charmcraft builds are still slow the first time the wheel is built. This happens on CI runners, when you use a new machine/VM, or when you contribute to a new charm.

charmcraftcache solves the slow first build.

charmcraftcache-hub maintains a list of charms. For each charm, charmcraft pack is used to build Python dependencies from source and the pip wheel cache is uploaded to a GitHub release.

ccc pack downloads these pre-built wheels to charmcraft's pip cache (and then runs charmcraft pack).

Note: Within the GitHub release, each charm has an isolated cache. If the same charm (same GitHub repository and relative path to charmcraft.yaml) is added to the list of charms more than once (with different git refs), the wheels are combined into a single cache. If there are duplicate wheels, the wheel is selected from the ref that is earlier in the list.

Isn't this just a worse version of PyPI?

Pretty much. The only difference is charmcraftcache-hub wheels are built from source on our runners, instead of built by the package maintainer.

Why does charmcraftcache only support "shorthand notation" syntax in charmcraft.yaml platforms?

"Shorthand notation" is used when build-on is identical to build-for. (For example, "ubuntu@22.04:amd64" means build on Ubuntu 22.04 amd64 and build for Ubuntu 22.04 amd64.)

For charms that depend (directly or indirectly) on Python packages with C extensions (e.g. pyyaml), charmcraft will build wheels where the C extensions only work on build-on.

For example, if a charm is built with

platforms:
  foo:
    build-on: ubuntu@22.04:amd64
    build-for:
      - ubuntu@22.04:amd64
      - ubuntu@22.04:arm64

the wheels in the *.charm file will contain C extensions that only work on amd64, not arm64.

The vast majority of charms have at least one Python dependency with C extensions, so the vast majority of charms should use "shorthand notation".

[^1]: Unless --destructive-mode is enabled

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

charmcraftcache-0.8.4.tar.gz (14.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

charmcraftcache-0.8.4-py3-none-any.whl (15.5 kB view details)

Uploaded Python 3

File details

Details for the file charmcraftcache-0.8.4.tar.gz.

File metadata

  • Download URL: charmcraftcache-0.8.4.tar.gz
  • Upload date:
  • Size: 14.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for charmcraftcache-0.8.4.tar.gz
Algorithm Hash digest
SHA256 34b348141b7cb91d6a1cadf00e7b9be2bd40f0c9d6a207eff6d4b2f7b61a1e1c
MD5 f48939bd472d697319a83f0487b805e6
BLAKE2b-256 74c3b441944dae9c4b0c1a65d8378b56b08fc9636e52c37a7583981a9c6bc630

See more details on using hashes here.

Provenance

The following attestation bundles were made for charmcraftcache-0.8.4.tar.gz:

Publisher: release.yaml on canonical/charmcraftcache

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file charmcraftcache-0.8.4-py3-none-any.whl.

File metadata

File hashes

Hashes for charmcraftcache-0.8.4-py3-none-any.whl
Algorithm Hash digest
SHA256 b0d26413cc608384d589fd4f266fd9aaed64e6559ee78af6fbf87b068a0e402d
MD5 a5bad07c84e7003061e7b3c230f22845
BLAKE2b-256 7c518176c715c58d215cce052b5934097a1e7bd06995b02ee37f5854e9844b2d

See more details on using hashes here.

Provenance

The following attestation bundles were made for charmcraftcache-0.8.4-py3-none-any.whl:

Publisher: release.yaml on canonical/charmcraftcache

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page