"Could not find snap/snapcraft.yaml" with --use-lxd when source dir changes

When the directory in which I run snapcraft has changed compared to the directory in which snapcraft ran the first time, snapcraft.yaml can’t be found.

$ snap version
snap    2.42.4
snapd   2.42.4
series  16
ubuntu  18.04
kernel  4.15.0-70-generic
$ snapcraft version
snapcraft, version 3.9.3
$ snap list | grep snap
snapcraft     3.9.3                 3792   beta      canonical*  classic
snapd         2.42.4                5643   beta      canonical*  snapd
snappy-debug  0.34-snapd2.39.3+git  414    stable    canonical*  -
$ snapcraft snap --use-lxd
The LXD provider is offered as a technology preview for early adopters.
The command line interface, container names or lifecycle handling may change in upcoming releases.
Launching a container.
/snap/snapcraft/3792/lib/python3.6/site-packages/pylxd/models/_model.py:116: UserWarning: Attempted to set unknown attribute "type" on instance of "Container"
  key, self.__class__.__name__
Waiting for cloud-init
status: done
Could not find snap/snapcraft.yaml. Are you sure you are in the right directory?
To start a new project, use `snapcraft init`
Run the same command again with --debug to shell into the environment if you wish to introspect this failure.
An error occurred when trying to execute 'snapcraft snap' with 'LXD': returned exit code 2.
$ lxc config show snapcraft-bitcoind | grep -B2 source:
    path: /root/project
    source: /root/provision.KFH0uCA8k2/snap-bitcoind
$ pwd

I tar+cz+ssh my snap directory over to my build machine in a different directory every time i run my deployment command.

I tried updating the device ‘source’ key to match the new directory where I’m located when running the snapcraft command on the remote machine, to see if it helps:

$ lxc config device set snapcraft-bitcoind snapcraft-project source=/root/provision.zv8zgbMFW9/snap-bitcoind

But I still get the same error. So I’m confused.

The simplest solution is to lxc delete your container after you’re finished with it. This will ensure it is recreated with the correct settings the next time you run your build. Though this is really a hack - the correct way to use snapcraft is to run it from the same folder each time.

Currently snapcraft binds the build environment to the project name, we are going to start creating environments using the directory being worked on soon to better support working on snaps that target different tracks. That said, if your intention is throw away environments, you will need to clean.

The problem is that I don’t want to delete the container since it takes so long to bring up on the first run. In my example, the /root/provision.KFH0uCA8k2/snap-bitcoind and /root/provision.zv8zgbMFW9/snap-bitcoind might differ by just one line in snapcraft.yml, in which case I’d like the build container to be reused.