Skip to content

Instantly share code, notes, and snippets.

@paulomach
Last active December 7, 2022 18:22
Show Gist options
  • Save paulomach/cf2039ad017567afe4b5c6fc58a07e63 to your computer and use it in GitHub Desktop.
Save paulomach/cf2039ad017567afe4b5c6fc58a07e63 to your computer and use it in GitHub Desktop.
Charm cheat sheet

some useful charm dev commands

Info about published charm

> juju info

# basic data
juju info <charm-name>

# parseable output
juju info <charm-name> --format yaml

> charmcraft

# build for specific series
charmcraft pack --bases-index=0 # `0` first base in charmcraft.yaml

# uploaded revision
charmcraft  revisions <charm-name>

# uploaded resource revisions
charmcraft resource-revisions <charm-name> <resource-name>

# status with attached resources
charmcraft status <charm-name>

Charmhub interaction

> upload stuff

# upload charm from the charm directory
charmcraft upload *.charm

# upload a OCI image
charmcraft upload-resource <charm-name> <resource-name> --image=sha256:c8f0dbc0d...
# or
charmcraft upload-resource <charm-name> <resource-name> --image=docker.io/<namespace>/<image>:<tag>

NOTE: when uploading a image, if the image is not available in canonical registries, it must be locally present.

> download stuff

# download the .charm (zip) file
juju download <charm-name> --channel latest/stable --filepath <file_name>.charm
# NOTE: one cannot set a revision

> publishing

# with a previously uploaded charm (identified by the revision number)
charmcraft release mysql --revision=<revision_number> --channel=latest/edge

# publish when uploading
charmcraft upload --release latest/stable ./<local-charm-file>

# publish/update lib from charm directory
charmcraft publish-lib

# publish to a (hidden) branch
charmcraft upload ./mysql_ubuntu-20.04-amd64.charm --release=latest/edge/secret_branch

charmhub app token

per charm token used programatically in ci/cd Note the permissions and channels access

charmcraft login --export output.auth \
        --charm=<charm-name> --permission=package-manage \
        --permission=package-manage-revisions \
        --permission=package-manage-releases \
        --permission=package-view \
        --channel=latest/edge \ # channel permissions
        --channel=latest/candidate \
        --ttl 31536000 # expire time in seconds

To use it, define token content in env var CHARMCRAFT_AUTH, e.g.:

 CHARMCRAFT_AUTH="$(cat output.auth)" charmcraft <your_command>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment