canonical / charmcraft

Collaborate, build and publish charmed operators for Kubernetes, Linux and Windows.
Apache License 2.0
65 stars 69 forks source link

`charmcraft pack` does not handle updating a file's execution permissions without a `charmcraft clean` #907

Open ca-scribner opened 1 year ago

ca-scribner commented 1 year ago

What happened

charmcraft pack will error out if you try to pack a charm with a src/charm.py that does not have execution permission on the file. If you fix the permissions and then pack again, it will respond with the same message. You need to clean the charmcraft env before packing for this to work as expected.

What did you expect

If I change the permissions on a file locally, I expect charmcraft pack to either reproduce those changes in my container or error specifically telling me it cannot do that. Instead, the current implementation quietly ignores some differences between my local files and container, leading users to continue debugging things they've already fixed just because it is not transparent whether the fix made it into the container.

Reproduction

git clone https://github.com/canonical/template-operator
cd template-operator
chmod a-x src/charm.py

charmcraft pack  # Fails with an error saying the charm file is not executable

chmod a+x src/charm.py
charmcraft pack  # Still fails with an error saying the charm file is not executable

charmcraft clean
charmcraft pack  # Works

Additional comments

A mitigation is to use charmcraft clean liberally whenever you're not sure if something will propagate to the container, but that is a poor user experience. Cold-start for charmcraft is slow (minutes vs 10's of seconds) and very disruptive to an iterative workflow

facundobatista commented 1 year ago

Hello @ca-scribner , thanks for the report!

I reproduced the problem, and opened a new issue in the Craft Parts library which is the one that should be improved for this behaviour.

As a workaround, after modifying the permission of the file, run touch on it, which will change its mtime, and the file will be re-picked just fine.

rsyring commented 1 year ago

Posting the full error message since googling for the exact error message did not find this issue:

Lint Errors:

carlcsaposs-canonical commented 1 year ago

Similar issue: moving charmcraft's LXC container between machines causes some files to not be detected as "updated"

Workaround that we used: https://github.com/canonical/data-platform-workflows/blob/f2556f7c75d47d51322404b15ba4818185f2f2dd/.github/workflows/build_charms_with_cache.yaml#L121-L127

(force charmcraft to update all files)

Also might be related to https://github.com/canonical/charmcraft/issues/736

syncronize-issues-to-jira[bot] commented 1 month ago

Thank you for reporting us your feedback!

The internal ticket has been created: https://warthogs.atlassian.net/browse/CRAFT-3250.

This message was autogenerated