Manage resources

Declare a resource

To declare a resource required by your charm, set the resources key in its recipe.

See more: resources

See next: How to manage resources

Tip

During development, it may be useful to specify the resource at deploy time to facilitate faster testing without the need to publish a new charm/resource in between minor fixes. For example, assuming the resource is a /tmp/somefile.txt file, you could pack and the deploy with juju deploy --resource:

echo "TEST" > /tmp/somefile.txt
charmcraft pack
juju deploy ./my-charm.charm --resource my-resource=/tmp/somefile.txt

Publish a resource on Charmhub

Note

You must have already published the charm. See more: Publish a charm on Charmhub.

To publish a resource on its charm’s Charmhub page, run charmcraft upload-resource followed by the name of the charm, the name of the resource (cf. charmcraft.yaml), and --filepath=<path to file resource> / --image=<OCI image>. For example:

Note

The option --image must indicate an OCI image’s digest, being it in the short or long form (e.g.: 70aa8983ec5c or sha256:64aa8983ec5cea7bc143af18829836914fa405184d56dcbdfd9df672ade85249). When using the “short form” of the digest, the image needs to be present locally so its proper ID (the “long form”) can be retrieved.

charmcraft upload-resource my-super-charm someresource --filepath=/tmp/superdb.bin
Revision 1 created of resource 'someresource' for charm 'my-super-charm'
charmcraft upload-resource my-super-charm redis-image --image=sha256:64aa8983ec5cea7bc143af18829836914fa405184d56dcbdfd9df672ade85249
Revision 1 created of resource 'redis-image' for charm 'my-super-charm'

Charmcraft will first check if that specific image is available in Canonical’s Registry, and just use it if that’s the case. If not, it will try to get it from the developer’s local OCI repository (needs dockerd to be installed and running), push it to the Canonical’s Registry, and then use it. Either way, when the upload has completed, you end up with a resource revision.

To update a pre-uploaded resource, run the upload-resource command again. The result will be a new revision.

See more: upload-resource

View all the resources published on Charmhub

To view all the resources published on Charmhub for a charm, run charmcraft resources followed by the charm name:

Important

If you’re not logged in to Charmhub, the command will open up a web browser and ask you to log in.

charmcraft resources mycharm

See more: resources

Manage resource revisions

List all the available resource revisions

To view all the revisions for a resource associated with a charm you’ve uploaded to Charmhub, run charmcraft resource-revisions followed by the charm name and the resource name. For example:

charmcraft resource-revisions mycharm myresource

Set the architectures for a resource revision

To set the architectures for a revision of a resource associated with a charm you’ve uploaded to Charmhub, run charmcraft set-resource-architectures followed by the name of the charm, the name of the resource, and the architecture(s), using the --resources flag to specify the target resource revision. For example:

charmcraft set-resource-architectures mycharm myresource --revision=1 arm64,armhf