Skip to main content

charmed-analytics-ci

A CLI tool to automate CI-driven integration of updated rock images into consumer Charmed Operator repositories.

This tool is part of Canonical's Charmed Kubeflow stack and enables automated pull request creation after a rock image is built and published. It eliminates manual effort, reduces human error, and supports scalable, reproducible CI/CD pipelines.


✨ Features

  • ✅ Automatically clones target charm repositories
  • 🔁 Updates image references in YAML or JSON configuration files
  • ⚙️ Optionally modifies service-spec fields like user and command
  • 🔧 Validates metadata schemas for correctness before modification
  • 🤖 Opens pull requests with deterministic branches and templated descriptions
  • 🔐 Supports GitHub authentication via token or environment variable
  • 🔗 Optionally links back to triggering PR
  • 📦 Installable via PyPI and usable from CI pipelines
  • 🧪 Supports dry-run mode for previewing changes

🚀 Installation

Install from PyPI:

pip install charmed-analytics-ci

Or install for development:

git clone https://github.com/canonical/charmed-analytics-ci.git
cd charmed-analytics-ci
poetry install

🧪 CLI Usage

After installing, the CLI provides a single command:

chaci integrate-rock METADATA_FILE BASE_BRANCH ROCK_IMAGE [OPTIONS]

Example:

export GH_TOKEN="ghp_abc123..."  # or pass explicitly with --github-token

chaci integrate-rock rock-ci-metadata.yaml main ghcr.io/canonical/my-rock:1.0.0 --dry-run

Arguments:

Argument Description
METADATA_FILE Path to rock-ci-metadata.yaml describing integration targets
BASE_BRANCH Target branch for PRs (e.g. main or develop)
ROCK_IMAGE Full rock image string (e.g. ghcr.io/org/my-rock:1.0.0)

Options:

Option Description
--github-token Optional. GitHub token. Falls back to $GH_TOKEN environment variable if not provided.
--github-username Optional. GitHub username. Defaults to "__token__" if not provided.
--clone-dir PATH Optional. Directory where target repos will be cloned (default: /tmp).
--dry-run Optional. If set, changes are simulated but not committed or pushed. Logs changes to console.
--triggering-pr URL Optional. Link to the PR which triggered this run. Included in the PR body if present.
--team-reviewer SLUG Optional, repeatable. Organization team slug (e.g. mlops) to request a review from on each PR.
--reviewer LOGIN Optional, repeatable. GitHub username to request a review from on each PR.

Review requests are best-effort: if requesting reviewers fails (e.g. the team has no access to the repository or the token lacks permissions), a warning is logged and the command still succeeds. In --dry-run mode, the intended reviewers are logged instead.

chaci integrate-rock rock-ci-metadata.yaml main ghcr.io/canonical/my-rock:1.0.0 \
  --team-reviewer mlops --reviewer some-user

📄 rock-ci-metadata.yaml Format

integrations:
  - consumer-repository: canonical/my-charm
    replace-image:
      - file: "metadata.yaml"
        path: "resources.my-rock.upstream-source"
      - file: "src/images.json"
        path: "config.batcher"
    service-spec:
      - file: "service-spec.json"
        user:
          path: "containers[0].user"
          value: "1001"
        command:
          path: "containers[0].command[1]"
          value: "/start"

registry: "ghcr.io/canonical"
  • All file paths are relative to the repo root
  • Paths can use dot and bracket notation for navigating YAML/JSON
  • registry is optional. It names the container registry the rock is published to, including the host. It is consumed by CI tooling to override its default registry and is ignored by chaci.

🧪 Testing

Unit tests

tox -e unit

🔁 Integration tests

⚠️ These tests interact with a real GitHub repository and require a fine-grained GitHub token with appropriate permissions.

Required GitHub token permissions

The token must be a fine-grained personal access token (PAT) with:

  • Repository access: Select the repository you're testing against
  • Permissions:
    • Contents: Read and write
    • Pull requests: Read and write

These are needed to:

  • Clone the repo
  • Push branches
  • Open and manage pull requests

Setup and run:

export CHACI_TEST_TOKEN=<your_token>
export CHACI_TEST_REPO="org/repo-name"
export CHACI_TEST_BASE_BRANCH="target-branch"

tox -e integration

The integration tests will:

  • Clone the specified repository
  • Create a temporary branch and pull request
  • Validate the PR contents
  • Clean up the branch and PR after execution

🧰 Development & Contributing

This project uses:

To run all checks locally:

tox -e lint,unit,integration

📁 Project Structure

File Purpose
rock_integrator.py Core logic for modifying files with images
git_client.py Git and GitHub abstraction for PR workflow
rock_metadata_handler.py Orchestration for multi-repo integration
rock_ci_metadata_models.py Pydantic model for metadata schema validation
main.py CLI entrypoint via click
templates/pr_body.md.j2 Jinja2 template for pull request bodies

🔒 License

This project is licensed under the Apache 2.0 License.


✍️ Authors

Built by the Canonical Charmed Kubeflow team.

Metadata

Release files for charmed-analytics-ci 1.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for charmed-analytics-ci 1.4.0
File Size Uploaded Provenance Actions
charmed_analytics_ci-1.4.0.tar.gz 19.6 kB Without provenance Details for charmed_analytics_ci-1.4.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for charmed-analytics-ci 1.4.0
File Interpreter ABI Platform Actions
charmed_analytics_ci-1.4.0-py3-none-any.whl Python 3 none any Details for charmed_analytics_ci-1.4.0-py3-none-any.whl

Total release size: 41.2 kB

Release files / charmed_analytics_ci-1.4.0.tar.gz

Download URL charmed_analytics_ci-1.4.0.tar.gz
Size 19.6 kB
Tags Source
SHA-256 checksum
How to use checksums
315ba98944698f7f95988490c3a74d1b1e568fb56034a7aefb550f942ab6d650
BLAKE2b-256 checksum
How to use checksums
0bbd9b47444dda93b7d98e07053b8cea2e96a00e9a23757959e6ec4139086863
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.8

Release files / charmed_analytics_ci-1.4.0-py3-none-any.whl

Download URL charmed_analytics_ci-1.4.0-py3-none-any.whl
Size 21.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
604b6e5ba1511168a917bd0e4cecaffd274137639633ba81d7d63c2cd8d40274
BLAKE2b-256 checksum
How to use checksums
42a9e774cd659494e14706223fa2b6aed2d966a0662fd724f6390afd11dfcf4a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.8

Security for charmed-analytics-ci 1.4.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page