Charmcraft pack failed

I was following the tutorial here Juju | Building and deploying a mini charm trying to build a minimal charm. However, the pack step failed in the container.

The error log suggests ‘snap’ is not availble in the container created by lxc.

I was able to build the charm using ‘–destructive-mode’, so I’m pretty sure the charm itself has no problem.

Any suggestions would be appreciated. Thanks!

Below is the error log:

2022-09-27 08:41:07.690 Starting charmcraft version 2.0.0
2022-09-27 08:41:07.692 System details: OSPlatform(system='ubuntu', release='20.04', machine='x86_64'); Environment: None
2022-09-27 08:41:07.692 Packing the charm.
2022-09-27 08:41:07.692 Reading '/home/ubuntu/juju-beegfs/metadata.yaml'
2022-09-27 08:41:07.693 Validating metadata format
2022-09-27 08:41:08.180 Executing on host: lxc --project default profile show local:default
2022-09-27 08:41:08.342 Building for 'bases[0]' as host matches 'build-on[0]'.
2022-09-27 08:41:08.342 Building for 'bases[0][0]'.
2022-09-27 08:41:08.343 Launching environment to pack for base name='ubuntu' channel='20.04' architectures=['amd64'] (may take a while the first time but it's reusable)
2022-09-27 08:41:08.343 Executing on host: lxc remote list --format=yaml
2022-09-27 08:41:08.457 Remote 'craft-com.ubuntu.cloud-buildd' already exists.
2022-09-27 08:41:08.458 Executing on host: lxc project list local: --format=yaml
2022-09-27 08:41:08.588 Executing on host: lxc --project charmcraft list local: --format=yaml
2022-09-27 08:41:08.728 Executing on host: lxc --project charmcraft list local: --format=yaml
2022-09-27 08:41:08.902 Executing in container: lxc --project charmcraft exec local:charmcraft-juju-beegfs-1322595-0-0-amd64 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin CHARMCRAFT_MANAGED_MODE=1 cat /etc/os-release
2022-09-27 08:41:09.212 Executing in container: lxc --project charmcraft exec local:charmcraft-juju-beegfs-1322595-0-0-amd64 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin CHARMCRAFT_MANAGED_MODE=1 test -f /etc/craft-instance.conf
2022-09-27 08:41:09.601 Executing on host: lxc --project charmcraft file pull local:charmcraft-juju-beegfs-1322595-0-0-amd64/etc/craft-instance.conf /home/ubuntu/tmpnykordzs.tmp-craft/tmp27yigj4r
2022-09-27 08:41:09.805 Waiting for environment to be ready...
2022-09-27 08:41:09.806 Executing in container: lxc --project charmcraft exec local:charmcraft-juju-beegfs-1322595-0-0-amd64 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin CHARMCRAFT_MANAGED_MODE=1 systemctl is-system-running
2022-09-27 08:41:10.240 Waiting for networking to be ready...
2022-09-27 08:41:10.241 Executing in container: lxc --project charmcraft exec local:charmcraft-juju-beegfs-1322595-0-0-amd64 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin CHARMCRAFT_MANAGED_MODE=1 getent hosts snapcraft.io
2022-09-27 08:41:10.623 Installing snap 'charmcraft' from host (classic=True)
2022-09-27 08:41:10.632 Executing in container: lxc --project charmcraft exec local:charmcraft-juju-beegfs-1322595-0-0-amd64 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin CHARMCRAFT_MANAGED_MODE=1 test -f /etc/craft-instance.conf
2022-09-27 08:41:10.930 Executing on host: lxc --project charmcraft file pull local:charmcraft-juju-beegfs-1322595-0-0-amd64/etc/craft-instance.conf /home/ubuntu/tmpdjktyanj.tmp-craft/tmpj7_3plns
2022-09-27 08:41:11.132 Revisions found: host='1033', target=None
2022-09-27 08:41:11.133 Executing in container: lxc --project charmcraft exec local:charmcraft-juju-beegfs-1322595-0-0-amd64 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin CHARMCRAFT_MANAGED_MODE=1 rm -f /tmp/charmcraft.snap
2022-09-27 08:41:12.492 Executing in container: lxc --project charmcraft exec local:charmcraft-juju-beegfs-1322595-0-0-amd64 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin CHARMCRAFT_MANAGED_MODE=1 test -d /tmp
2022-09-27 08:41:12.767 Executing on host: lxc --project charmcraft file push /home/ubuntu/tmpor2x_i2i.tmp-craft/charmcraft.snap local:charmcraft-juju-beegfs-1322595-0-0-amd64/tmp/charmcraft.snap --gid=0 --uid=0
2022-09-27 08:41:13.617 Executing in container: lxc --project charmcraft exec local:charmcraft-juju-beegfs-1322595-0-0-amd64 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin CHARMCRAFT_MANAGED_MODE=1 snap install /tmp/charmcraft.snap --classic --dangerous
2022-09-27 08:41:13.947 Failed to inject host Charmcraft snap into target environment.
2022-09-27 08:41:13.951 Traceback (most recent call last):
2022-09-27 08:41:13.951   File "/snap/charmcraft/1033/lib/craft_providers/actions/snap_installer.py", line 227, in inject_from_host
2022-09-27 08:41:13.951     executor.execute_run(
2022-09-27 08:41:13.951   File "/snap/charmcraft/1033/lib/craft_providers/lxd/lxd_instance.py", line 221, in execute_run
2022-09-27 08:41:13.951     return self.lxc.exec(
2022-09-27 08:41:13.951   File "/snap/charmcraft/1033/lib/craft_providers/lxd/lxc.py", line 326, in exec
2022-09-27 08:41:13.951     return runner(final_cmd, **kwargs)  # pylint: disable=subprocess-run-check
2022-09-27 08:41:13.951   File "/snap/charmcraft/1033/usr/lib/python3.8/subprocess.py", line 516, in run
2022-09-27 08:41:13.951     raise CalledProcessError(retcode, process.args,
2022-09-27 08:41:13.951 subprocess.CalledProcessError: Command '['lxc', '--project', 'charmcraft', 'exec', 'local:charmcraft-juju-beegfs-1322595-0-0-amd64', '--', 'env', 'PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin', 'CHARMCRAFT_MANAGED_MODE=1', 'snap', 'install', '/tmp/charmcraft.snap', '--classic', '--dangerous']' returned non-zero exit status 127.
2022-09-27 08:41:13.951 
2022-09-27 08:41:13.951 The above exception was the direct cause of the following exception:
2022-09-27 08:41:13.951 Traceback (most recent call last):
2022-09-27 08:41:13.951   File "/snap/charmcraft/1033/lib/charmcraft/providers/_buildd.py", line 81, in _setup_charmcraft
2022-09-27 08:41:13.951     snap_installer.inject_from_host(
2022-09-27 08:41:13.951   File "/snap/charmcraft/1033/lib/craft_providers/actions/snap_installer.py", line 235, in inject_from_host
2022-09-27 08:41:13.951     raise SnapInstallationError(
2022-09-27 08:41:13.951 craft_providers.actions.snap_installer.SnapInstallationError: Failed to inject snap 'charmcraft'.
2022-09-27 08:41:13.951 * Command that failed: 'lxc --project charmcraft exec local:charmcraft-juju-beegfs-1322595-0-0-amd64 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin CHARMCRAFT_MANAGED_MODE=1 snap install /tmp/charmcraft.snap --classic --dangerous'
2022-09-27 08:41:13.951 * Command exit code: 127
2022-09-27 08:41:13.951 * Command standard error output: b'env: \xe2\x80\x98snap\xe2\x80\x99: No such file or directory\n'
2022-09-27 08:41:13.951 
2022-09-27 08:41:13.951 The above exception was the direct cause of the following exception:
2022-09-27 08:41:13.951 Traceback (most recent call last):
2022-09-27 08:41:13.951   File "/snap/charmcraft/1033/lib/charmcraft/providers/_lxd.py", line 180, in launched_environment
2022-09-27 08:41:13.951     instance = lxd.launch(
2022-09-27 08:41:13.951   File "/snap/charmcraft/1033/lib/craft_providers/lxd/launcher.py", line 176, in launch
2022-09-27 08:41:13.951     base_configuration.warmup(executor=instance)
2022-09-27 08:41:13.951   File "/snap/charmcraft/1033/lib/charmcraft/providers/_buildd.py", line 135, in warmup
2022-09-27 08:41:13.951     self._setup_charmcraft(executor=executor)
2022-09-27 08:41:13.951   File "/snap/charmcraft/1033/lib/charmcraft/providers/_buildd.py", line 85, in _setup_charmcraft
2022-09-27 08:41:13.951     raise bases.BaseConfigurationError(
2022-09-27 08:41:13.951 craft_providers.bases.errors.BaseConfigurationError: Failed to inject host Charmcraft snap into target environment.
2022-09-27 08:41:13.951 Full execution log: '/home/ubuntu/snap/charmcraft/common/cache/charmcraft/log/charmcraft-20220927-084107.689056.log'

Hello! We’re chasing spurious errors like this, thanks for the report!

What happens if you do charmcraft clean and then try again? thanks!!