| name | charmcraft |
| description | Expert assistant for developing Juju charms using charmcraft. Use when initializing charm projects, building charms, managing charm libraries, publishing to Charmhub, running tests, or working with charmcraft.yaml configuration. Keywords include charmcraft, Juju, charm development, Charmhub publishing, charm libraries, pack, build, upload, release, init, extensions. |
| license | Apache-2.0 |
| compatibility | Requires charmcraft 4.0+ installed locally. Network access needed for Charmhub operations. |
| allowed-tools | Bash(charmcraft:*) Read |
Charmcraft Development Assistant
Expert guidance for developing, building, testing, and publishing Juju charms using charmcraft.
Core Workflows
Project Initialization
charmcraft init --profile=kubernetes
charmcraft init --profile=machine
charmcraft init --profile=django-framework
charmcraft init --profile=fastapi-framework
charmcraft init --profile=flask-framework
charmcraft init --name=my-charm --author="Your Name"
charmcraft list-extensions
charmcraft expand-extensions
After init:
- Customize
charmcraft.yaml (metadata, bases, relations, config)
- Edit
README.md (becomes Charmhub documentation)
- Implement
src/charm.py (using Ops framework)
- Update tests in
tests/unit/ and tests/integration/
For detailed charmcraft.yaml configuration, see references/charmcraft-yaml-reference.md
Building and Packaging
charmcraft pack
charmcraft pack -o ./build/
charmcraft pack --bases-index=0
charmcraft analyse ./my-charm_ubuntu-22.04-amd64.charm
charmcraft analyse --format=json ./my-charm.charm
charmcraft clean
charmcraft remote-build
Build lifecycle: pack handles everything automatically. Only use individual steps (pull, build, stage, prime) for debugging.
Always run charmcraft analyse before uploading to catch:
- Missing/malformed metadata
- File permission issues
- Deprecated patterns
Testing
charmcraft test
charmcraft test --shell
charmcraft test --debug
tox -e format
tox -e lint
tox -e unit
tox -e integration
Publishing to Charmhub
charmcraft login
charmcraft whoami
charmcraft register my-charm
charmcraft upload ./my-charm.charm --release=edge
charmcraft status my-charm
charmcraft revisions my-charm
charmcraft release my-charm --revision=5 --channel=stable
charmcraft promote my-charm --from=beta --to=stable
charmcraft close my-charm edge
Channel structure: [track/]risk[/branch]
- Risks:
edge → beta → candidate → stable
- Examples:
stable, edge, 2.0/candidate, beta/hotfix-123
Always: Upload to edge first, test thoroughly, then promote through channels.
Resources
charmcraft resources my-charm
charmcraft upload-resource my-charm my-resource --filepath=./file.tar.gz
charmcraft resource-revisions my-charm my-resource
charmcraft release my-charm --revision=5 --channel=stable --resource=my-resource:3
Library Management
charmcraft fetch-libs
charmcraft list-lib postgresql
charmcraft create-lib my-charm my_library
charmcraft publish-lib charms.my_charm.v0.my_library
In charmcraft.yaml:
charm-libs:
- lib: postgresql.postgres_client
version: "0"
- lib: mysql.client
version: "0.57"
Library versioning:
v0, v1 = breaking changes (API changes)
- Patch auto-increments for non-breaking changes
- Libraries go in
lib/charms/{charm_name}/v{X}/{lib_name}.py
Essential Files
charmcraft.yaml
Core configuration defining:
- Charm metadata (
name, title, summary, description)
- Base OS (
bases)
- Build config (
parts)
- Relations (
provides, requires, peers - always use optional: true for requires!)
- Config options (
config)
- Actions (
actions)
- Resources (
resources)
- Containers (K8s charms)
See references/charmcraft-yaml-reference.md for complete specification.
src/charm.py
Main charm implementation:
Best Practices
Development Workflow
- Write integration tests first - define expected behavior
- Implement incrementally - get basic functionality working
- Run quality checks -
tox -e lint and tox -e format frequently
- Analyse before upload -
charmcraft analyse on every build
- Test locally -
charmcraft pack then juju deploy ./my-charm.charm
Documentation
Keep updated:
README.md - Main docs (appears on Charmhub)
CONTRIBUTING.md - Development workflow
CHANGELOG.md - User-facing changes
SECURITY.md - Security reporting
TUTORIAL.md - Basic usage guide
Version Control
Commit: charmcraft.yaml, all source, uv.lock, pyproject.toml, tests, docs
Ignore: *.charm, __pycache__/, .tox/, venv/, .claude/settings.local.json
Common Patterns
Multi-Base Builds
bases:
- build-on:
- name: ubuntu
channel: "22.04"
run-on:
- name: ubuntu
channel: "22.04"
- build-on:
- name: ubuntu
channel: "24.04"
run-on:
- name: ubuntu
channel: "24.04"
Pack for specific base: charmcraft pack --bases-index=0
Database Integration Example
requires:
database:
interface: postgresql_client
optional: true
charm-libs:
- lib: data_platform_libs.data_interfaces
version: "0"
from charms.data_platform_libs.v0.data_interfaces import DatabaseRequires
class MyCharm(CharmBase):
def __init__(self, *args):
super().__init__(*args)
self.database = DatabaseRequires(self, "database", "myapp")
self.framework.observe(
self.database.on.database_created,
self._on_database_created
)
Troubleshooting
Build fails:
- Check
charmcraft.yaml syntax
- Verify required files exist (
src/charm.py, uv.lock)
- Run
charmcraft -v pack for verbose output
Upload fails:
- Login:
charmcraft login
- Register name:
charmcraft register my-charm
- Analyse first:
charmcraft analyse ./my-charm.charm
Library errors:
- Fetch:
charmcraft fetch-libs
- Check library definitions in
charmcraft.yaml
Runtime issues:
- Check Juju logs:
juju debug-log
- Verify resources uploaded:
charmcraft resources my-charm
- Test base compatibility
For comprehensive troubleshooting, see references/troubleshooting.md
Quick Reference
charmcraft init --profile=kubernetes
charmcraft login
charmcraft pack
charmcraft analyse ./my-charm.charm
tox -e lint
tox -e unit
charmcraft upload ./my-charm.charm --release=edge
charmcraft status my-charm
charmcraft promote my-charm --from=edge --to=beta
charmcraft fetch-libs
charmcraft publish-lib charms.my_charm.v0.my_library
juju deploy ./my-charm.charm
juju status
juju debug-log
Resources
Additional References
When you need detailed information:
Key reminders:
- Always run
charmcraft analyse before uploading
- Test on
edge before promoting to stable
- Use
optional: true for all requires relations
- Keep
uv.lock in version control
- Follow conventional commits for changelogs