charm-tools icon indicating copy to clipboard operation
charm-tools copied to clipboard

Don't embed hooks

Open stub42 opened this issue 10 years ago • 13 comments

Currently, layered charms' hooks are an embedded chunk of Python. This might come from the base layer, or an old version of the base layer, or customized by an included layer, or customized by the main charm. This makes it difficult to propagate fixes, and is a bit of a mess.

Instead, lets not have any hooks in the hooks directory. List the hooks that each layer needs in its layers.yaml file. At composition time, copy hooks/hook.template into place for each hook and set executable permissions, if the hook does not already exist.

This would allow changes in the base layer's hook.template to propagate. It would allow layers and charms to create a new hook.template if necessary. It would allow layers and charms to override the hook template just for those hooks that actually need it.

stub42 avatar Feb 02 '16 05:02 stub42

I like this idea.

johnsca avatar Feb 02 '16 13:02 johnsca

For extra points, by stealing some code from charms.reactive it would be possible to list hooks like {interface:pgsql}-relation-changed and have hooks generated with the correct relation name based on the final composed metadata.yaml.

stub42 avatar Feb 03 '16 03:02 stub42

This would also allow layers to be used by alien charms, such as a Windows charm using the leadership layer.

stub42 avatar Mar 23 '16 04:03 stub42

I don't know if this is at all related, but with charm-tools 2.1.2, it seems like I have to have a hooks/hook.template file even if it's empty. Without this, charm build complains:

build: At least one layer must provide hooks/hook.template

touching hooks/hook.template quiets the warning, but I don't really understand what the file is for.

warsaw avatar Apr 27 '16 21:04 warsaw

Okay, I think I see that hook.template gets copied to data-storage-attached and data-storage-detaching, but then I'm unclear why it won't do the same with the other hooks.

warsaw avatar Apr 27 '16 21:04 warsaw

This bug still causes an error level information to me:

build: At least one layer must provide hooks/hook.template

Its coloured "red" in the charm build output which leads up to a situation where I don't know if its a problem I need to fix or can opt-out to fix.

If there is a better way to remove this error/warning

erik78se avatar Mar 04 '19 23:03 erik78se

@erik78se Do you still get the problem if you build with --no-local-layers? You might have an old version of the base layer pinned, in which case what you see is a valid error report.

stub42 avatar Mar 05 '19 04:03 stub42

@stub42 I've tore down my development environment - sorry, I can't reproduce this easily.

erik78se avatar Mar 16 '19 14:03 erik78se

I ran into this with the haproxy charm on r128: https://bazaar.launchpad.net/~haproxy-team/charm-haproxy/trunk/revision/128

bzr branch lp:charm-haproxy haproxy
Branched 128 revisions.

cd haproxy
charm build --no-local-layers
build: Build dir not specified via command-line or environment; defaulting to /tmp/charm-builds
build: Please add a `repo` key to your layer.yaml, e.g. repo: bzr+ssh://bazaar.launchpad.net/+branch/charm-haproxy/\n'
build: Destination charm directory: /tmp/charm-builds/haproxy
build: The top level layer expects a valid layer.yaml file
build: Processing layer: haproxy (from .)
build: At least one layer must provide hooks/hook.template

Touching the hooks/hook.template file does indeed allow building the charm:

touch hooks/hook.template 
charm build --no-local-layers
build: Build dir not specified via command-line or environment; defaulting to /tmp/charm-builds
build: Please add a `repo` key to your layer.yaml, e.g. repo: bzr+ssh://bazaar.launchpad.net/+branch/charm-haproxy/\n'
build: Destination charm directory: /tmp/charm-builds/haproxy
build: The top level layer expects a valid layer.yaml file
build: Processing layer: haproxy (from .)
proof: OK!

I think I'm running the correct charm snap:

jamon@derp:pts/2: /home/jamon/charms/haproxy  
 0 % charm version
charmstore-client 2.3.0+snap-320+git-47-g44bc628
charm-tools 2.5.2

jamonation avatar Mar 21 '19 19:03 jamonation

The cited haproxy charm is not a reactive charm and has no layer.yaml, and 'charm build' is failing as expected.

Perhaps 'charm build' should fail more obviously if there is no layer.yaml, given that in almost all cases a built charm will fail without one of the base layers included. A missing layer.yaml is either a fatal mistake, or indicates the charm does not need building (not a charms.reactive charm)

stub42 avatar Mar 21 '19 23:03 stub42

Makes total sense now, I didn't realize I was working with a non-reactive charm there. Thanks for explaining that.

jamonation avatar Mar 22 '19 19:03 jamonation

We should report building non-layered charms better and earlier in the process. Created #512 to track that.

johnsca avatar Mar 25 '19 15:03 johnsca

Yes, thats a very good idea. Considering it took me a long time to understand the difference and how it mattered.

I wrote a long "hook" tutorial which tried to emphasize this which I think was a major misstake from my side, not learning that from start before hitting the "reactive" wall.

/Erik

On Mon, Mar 25, 2019 at 4:19 PM Cory Johns [email protected] wrote:

We should report building non-layered charms better and earlier in the process. Created #512 https://github.com/juju/charm-tools/issues/512 to track that.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/juju/charm-tools/issues/98#issuecomment-476244059, or mute the thread https://github.com/notifications/unsubscribe-auth/AAz6qyAVzgaqYcBMNdtZF9KnNg4FtPiOks5vaOjngaJpZM4HRL5M .

erik78se avatar Mar 27 '19 17:03 erik78se