Charm packing will not include all files by default anymore

In charmcraft 1.2.0 we’ll release a long-waited feature: the charm packing will stop including all the project’s files and directories by default.

This is done both for security reasons (avoid publishing by mistake a file with secrets that happened to be in the project’s directory) and for convenience (don’t include other leftovers, like log files, or even previously packed charms).

Since 1.2.0 only well known mandatory and optional files will be included by default:

  • mandatory files metadata.yaml and dispatch; and hooks directory.
  • optional files config.yaml, metrics.yaml, actions.yaml, lxd-profile.yaml, version; and directories: templates, lib and mod.
  • also, if the entrypoint is at the project’s root, just include it, but if it’s inside a directory, all the subtree starting in that directory will be included.
  • finally, if the charm specifies requirements with dependencies, a venv directory will be included with those.

If the charm needs other files, they can be specified in the charmcraft.yaml config, using the parts key. For example:

parts:
  charm:
    prime: 
      - stuff.bin
      - extra/*.txt

Please explore the config reference for further details about this.

3 Likes

This sounds like a good idea; does it essentially deprecate the .jujuignore file?

What about icon.svg , and LICENSE ? Are these not included by default ? I presume src is also included by default (of course). It will be good to explicitly mention it in the mandatory list.

Not included by default. Surely we’ll spot some new files to include by default in time. If you think that these two are common enough, please open an issue so we can discuss them properly and not forget them. Thanks!!!

Yes and no :). The src directory is only included by default if the entrypoint is inside it. As the default entrypoint is src/charm.py, the whole tree under src will be included, yes. But if in your project the entrypoint is elsewhere, src will not be included.

Yes. I opened this issue to track it, planned for 1.3.

1 Like

Great, thanks for clarifying!

I have some questions:

  1. When I add a directory in the parts.charm.prime entry, is it added recursively?

  2. If I prime the file foo/bar/bla/ble/bli.blo, where does it go in the charm code? If there are other files in this foo/ tree, they are added or not?

  3. Lets say I have a huge tree of python codes in src/, and when running the tests it creates all those __pycache__ folders and *.pycfiles. How to ignore those directories and files specifically? If .jujuignore is going away, this could be a nightmare to maintain.

  4. Please add by default the LICENSE in final *.charm file. Removing it might be a violation of some licenses. I filled an issue about it

any particular reason for not packing charmcraft.yaml?

Aaaaaaaand we changed plans. We recognized the value of keeping a generic filter (thanks @heitor) . For now we’ll keep the jujuignore functionality for that (in the future it may mutate for other configuration more in line with the rest of charmcraft config, but for now it stays as it is now).

1 Like

What about the syntax that is used to add/ignore files and dirs in snapcraft parts? We used it at one point in our snap here. @heitor, @facundo how do you feel about this as an alternative to .jujuignore?

It is really awesome to see the community’s feedback shaping charmcraft and Juju! Thanks @facundo!

I can see how useful the prime directive is, but the .jujuignore allows us to have a pattern matching to not prime some files. If there’s no alternative to it in the prime field, removing it would be a loss to the ecosystem.

Hello!

Let me answer one by one…

  1. Yes

  2. It goes in the same foo/bar/bla/ble/bli.blo location. Other files in those directories (e.g. foo/bar/whatever.txt) will NOT be included.

  3. We’re not dropping the jujuignore filtering (it may mutate in the future, but for now it stays the same); sorry for the noise

  4. Thank’s for the issue, we will include it.

1 Like

We’ve just created a PR to include them if the files exist in the project directory. This should be effective in Charmcraft 1.2.1.

1 Like

As @facundo mentioned, we’ll stay with .jujuignore for now until we implement a filtering mechanism in craft-parts to ignore certain file patterns such as *.pyc. This would prevent these files to be pulled into parts processing (which is not the same as priming, since files matching these patterns created during the build process would still be allowed to be part of the final payload). Entries for the new filtering system would then be specified in charmcraft.yaml instead of having a separate file for that purpose.

3 Likes