juju / charm-tools

Tools for charm authors and maintainers
Other
42 stars 64 forks source link

charm build fails with AttributeError: 'WheelhouseTactic' object has no attribute '_layer_refs' #594

Closed mthaddon closed 3 years ago

mthaddon commented 3 years ago

What version am I running?

I ran the following command: snap info charm and got the following ouput:

name:      charm
summary:   charm and charm-tools
publisher: Canonical✓
store-url: https://snapcraft.io/charm
contact:   https://discourse.juju.is/c/charming
license:   unset
description: |
  charmstore-client and charm-tools
commands:
  - charm
snap-id:      2Rryoc2ylScfbFl4eQtpntHD9iuZuMvt
tracking:     latest/stable
refresh-date: today at 09:19 CET
channels:
  latest/stable:    2.8.1 2021-01-27 (602) 119MB classic
  latest/candidate: 2.8.1 2021-01-27 (602) 119MB classic
  latest/beta:      2.8.1 2021-01-27 (602) 119MB classic
  latest/edge:      2.8.1 2021-01-27 (602) 119MB classic
installed:          2.8.1            (602) 119MB classic

I am using: ubuntu 20.04

Running the following:

git clone lp:charm-k8s-mariadb
cd charm-k8s-mariadb
tox -e build

I get this error:

Traceback (most recent call last):
  File "/snap/charm/602/bin/charm-build", line 33, in <module>
    sys.exit(load_entry_point('charm-tools==2.8.1', 'console_scripts', 'charm-build')())
  File "/snap/charm/602/lib/python3.6/site-packages/charmtools/build/builder.py", line 1173, in main
    build()
  File "/snap/charm/602/lib/python3.6/site-packages/charmtools/build/builder.py", line 821, in __call__
    self.generate()
  File "/snap/charm/602/lib/python3.6/site-packages/charmtools/build/builder.py", line 759, in generate
    self.formulate_plan(layers)
  File "/snap/charm/602/lib/python3.6/site-packages/charmtools/build/builder.py", line 583, in formulate_plan
    self.plan = self.plan_layers(layers, output_files)
  File "/snap/charm/602/lib/python3.6/site-packages/charmtools/build/builder.py", line 419, in plan_layers
    wh_tactic.combine(existing_tactic)
  File "/snap/charm/602/lib/python3.6/site-packages/charmtools/build/tactics.py", line 1066, in combine
    self._layer_refs.update(existing._layer_refs)
AttributeError: 'WheelhouseTactic' object has no attribute '_layer_refs'
ERROR: InvocationError for command /snap/bin/charm build . --build-dir /tmp (exited with code 1)
johnsca commented 3 years ago

Because that charm is using layer:caas-base, this error is actually coming from that layer's custom WheelhouseTactic implementation. Interestingly, the approach that that layer's tactic uses is more similar to the way charmcraft pre-builds the venv rather than building it at deploy time the way the default WheelhouseTactic does, but it has also gotten out of sync with the default tactic and missed some fixes and improvements made to that tactic.

The charmcraft / layer:caas-base approach has significant performance advantages during install and upgrade, but has the downside of opening the charm up to architecture-specific binaries ending up in the charm. This will be addressed with Metadata v2 and CharmHub via the extended architecture info, but it might be worth considering adding that type of build as an option in the current default tactic and fold layer:caas-base's custom tactic back into the default.

johnsca commented 3 years ago

Upon further review, this actually came in from https://github.com/juju/charm-tools/pull/585 (specifically, this section).

johnsca commented 3 years ago

This could (and probably should) still be fixed in the caas-base layer (by at least porting over the improvements to combine the wheelhouse.txt file from each layer and doing the install at the end rather than per-layer, which came in #569), but in the meantime, you can work around it by adding the --ignore-lock-file option to your charm build call when building k8s charms.

johnsca commented 3 years ago

Ok, closing this in favor of https://github.com/juju-solutions/layer-caas-base/issues/27 and https://github.com/juju/charm-tools/issues/596