canonical / charmcraft

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

charmcraft snap doesn't work with snap parallel installs #1770

Closed samuelallan72 closed 3 weeks ago

samuelallan72 commented 3 months ago

Bug Description

Now that charms are beginning to be upgraded to use charmcraft 3, I want to have charmcraft v2 and v3 installed so I can work with all the charms I need to. I tried to do this for the snap using the "parallel installs" feature:

sudo snap install charmcraft --channel latest/stable --classic
sudo snap install charmcraft_3 --channel 3.x/beta --classic

But this failed (see logs section). It appears that charmcraft is trying to access a hardcoded path that doesn't exist on the parallel install?

To Reproduce

  1. install charmcraft 2 and 3 snaps with the parallel install feature (note the underscore postfix):
sudo snap install charmcraft --channel latest/stable --classic
sudo snap install charmcraft_3 --channel 3.x/beta --classic
  1. try to use charmcraft_3 to build a charm.

Environment

Ubuntu 24.04 LTS

charmcraft.yaml

type: charm

parts:
  charm:
    plugin: dump
    source: .

base: ubuntu@24.04
platforms:
  amd64:
    build-on: amd64
    build-for: amd64
  arm64:
    build-on: arm64
    build-for: arm64
  ppc64el:
    build-on: ppc64el
    build-for: ppc64el
  s390x:
    build-on: s390x
    build-for: s390x

Relevant log output

# here I already have charmcraft 2.7 installed:
$ sudo snap install charmcraft --channel latest/stable --classic

---

$ sudo snap install charmcraft_3 --channel 3.x/beta --classic
charmcraft_3 (3.x/candidate) 3.1.1 from Canonical✓ installed
Channel 3.x/beta for charmcraft_3 is closed; temporarily forwarding to 3.x/candidate.

$ charmcraft_3 -v pack
Starting charmcraft, version 3.1.1
Logging execution to '/home/ubuntu/.local/state/charmcraft/log/charmcraft-20240730-111057.635886.log'
Launching managed ubuntu 24.04 instance...
Creating new instance from remote
Creating new base instance from remote
Creating new instance from base instance
Starting instance
Starting charmcraft version 2.7.1
Logging execution to '/tmp/charmcraft.log'
Bad charmcraft.yaml content:
- extra field 'base' not permitted in top-level configuration
- extra field 'platforms' not permitted in top-level configuration
Failed to execute charmcraft in instance.
Full execution log: '/home/ubuntu/.local/state/charmcraft/log/charmcraft-20240730-111057.635886.log'

$ sudo snap remove charmcraft
charmcraft removed

$ charmcraft_3 -v pack
Starting charmcraft, version 3.1.1
Logging execution to '/home/ubuntu/.local/state/charmcraft/log/charmcraft-20240730-112715.840030.log'
Launching managed ubuntu 24.04 instance...
Creating new instance from remote
Creating new base instance from remote
charmcraft internal error: HTTPError('404 Client Error: Not Found for url: http+unix://%2Frun%2Fsnapd.socket/v2/snaps/charmcraft')
Full execution log: '/home/ubuntu/.local/state/charmcraft/log/charmcraft-20240730-112715.840030.log'

$ sudo snap remove charmcraft_3
charmcraft_3 removed

$ sudo snap install charmcraft --channel 3.x/beta --classic
charmcraft (3.x/candidate) 3.1.1 from Canonical✓ installed
Channel 3.x/beta for charmcraft is closed; temporarily forwarding to 3.x/candidate.

$ charmcraft clean

$ charmcraft -v pack
Starting charmcraft, version 3.1.1
Logging execution to '/home/ubuntu/.local/state/charmcraft/log/charmcraft-20240730-114924.278890.log'
Launching managed ubuntu 24.04 instance...
Creating new instance from remote
Creating new base instance from remote
Creating new instance from base instance
Starting instance
Starting charmcraft, version 3.1.1
Logging execution to '/tmp/charmcraft.log'
Starting charmcraft, version 3.1.1
Logging execution to '/tmp/charmcraft.log'
Initialising lifecycle
Installing build-packages
Pulling charm
Building charm
:: + cp --archive --link --no-dereference . /root/parts/charm/install
Staging charm
Priming charm
Packing...
Packing charm ceph-osd_amd64.charm
Packed ceph-osd_amd64.charm
lengau commented 3 months ago

Thanks for the report!

@mr-cal I wonder if this could explain some of @NucciTheBoss's issues with parallel-installed snapcrafts?

It appears that requesting /v2/snaps/<snap_name> from snapd.socket doesn't take into account the snap's instance key. I guess that makes sense, as snapd doesn't know where it's getting that call from. So instead it's always installing the un-instanced name. Here @samuelallan72 saw a different error (404) because they didn't have an un-instanced charmcraft installed.

If I'm correct here, would it make sense in craft-providers to check the environment for SNAP_NAME == snap_name and if so, append _{SNAP_INSTANCE_KEY} to the URL if the snap is there? Or is it more appropriate for something higher level (probably craft-application) to adjust the name?

lengau commented 2 months ago

Thinking more about this, I think craft-application is probably the better place since craft-providers probably shouldn't be aware of the application context.

syncronize-issues-to-jira[bot] commented 2 months ago

Thank you for reporting us your feedback!

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

This message was autogenerated

sergiusens commented 2 months ago

Use SNAP_REVISION and maybe SNAP_INSTANCE to corroborate

sergiusens commented 2 months ago

https://github.com/canonical/snapcraft/blob/0d06f8006827c7e82345ad4ac13214c58671a19a/snapcraft/providers.py#L188

lengau commented 1 month ago

Blocked by https://github.com/canonical/craft-providers/issues/622