Snap fails to build with needed files

I’ve searched around the forum and can’t find anything specifically related to what I’m experiencing. I’m building this snap for a friend and have run into an issue wherein the snap will build successfully but two files (needed for it to work) aren’t present in the completed snap. Even adding them manually (post snap install) doesn’t work…

I’ve attempted using copy and dump to put the files in the snap but then snapcraft reports that the files “already exist”. This is a bit confusing and I am sure that this is something simple that I’m missing. TIA for your help here.

Current yaml:

name: go-password-generator # check to see if it's available
version: '1.0.3+git' # check versioning
summary: Go based random password generator- experimental. # 79 char long summary
description: |
    Go based random password generator- experimental.
grade: stable # must be 'stable' to release into candidate/stable channels
confinement: strict # use 'strict' once you have the right plugs

apps:
  go-password-generator:
    command: go-password-generator
    #environment: 
      #LC_ALL: C.UTF-8
    plugs:
      - home
parts: 
  my-part:
    source: .
    plugin: go
    go-importpath: github.com/kz6fittycent/go-password-generator
    after: [go]
    
  files:
    plugin: dump
    organize:
      nounlist: nounlist
      adjectivelist: adjectivelist  

Errors when attempting to run (without using dump or copy to build):

go-password-generator 
panic: open nounlist: no such file or directory

goroutine 1 [running]:
main.check(0x4d88e0, 0xc00008e180)
	/build/a68a1aa1e1c13913b730b11da952a95e-xenial/parts/my-part/go/src/github.com/kz6fittycent/go-password-generator/go-password-generator.go:76 +0x4a
main.main()
	/build/a68a1aa1e1c13913b730b11da952a95e-xenial/parts/my-part/go/src/github.com/kz6fittycent/go-password-generator/go-password-generator.go:83 +0x6a

Errors during build WITH copy or dump (same error each time):

Building files 
Trying to organize file 'adjectivelist' to 'adjectivelist', but 'adjectivelist' already exists
Build failed 

The files ARE in the git repo and there is no git ignore. Application works as expected when running from source.

Again, thanks for your help.

here’s a gif of the application actually working:

First thing I see is that you don’t have a source specified for this part. If the files are in the source location in the my-part part then you can create an install scriptlet (soon to be replaced by override-build) which copies the files into place:

my-part:
  ...
  install: |
    install -T nounlist $SNAPCRAFT_PART_INSTALL/nounlist
    install -T adjective list $SNAPCRAFT_PART_INSTALL/adjectivelist

or

my-part:
  ...
  override-build: |
    snapcraftctl build
    install -T nounlist $SNAPCRAFT_PART_INSTALL/nounlist
    install -T adjective list $SNAPCRAFT_PART_INSTALL/adjectivelist
1 Like

well, it successfully builds but the same error persists.

There’s a good chance I didn’t fully understand your advice, so I’ve posted the latest .yaml for review:

name: passbot # check to see if it's available
version: '1.0.4+git' # check versioning
summary: Go based random password generator- experimental. # 79 char long summary
description: |
    Go based random password generator- experimental.
grade: stable # must be 'stable' to release into candidate/stable channels
confinement: strict # use 'strict' once you have the right plugs

apps:
  passbot:
    command: go-password-generator
    #environment: 
      #LC_ALL: C.UTF-8
    plugs:
      - home
parts: 
  my-part:
    source: .
    plugin: go
    go-importpath: github.com/kz6fittycent/go-password-generator
    after: [go]
    install: |
      install -T nounlist $SNAPCRAFT_PART_INSTALL/nounlist
      install -T adjectivelist $SNAPCRAFT_PART_INSTALL/adjectivelist

ERROR:

$ passbot 
panic: open nounlist: no such file or directory

goroutine 1 [running]:
main.check(0x4d88e0, 0xc00008a180)
	/build/a68a1aa1e1c13913b730b11da952a95e-xenial/parts/my-part/go/src/github.com/kz6fittycent/go-password-generator/go-password-generator.go:76 +0x4a
main.main()
	/build/a68a1aa1e1c13913b730b11da952a95e-xenial/parts/my-part/go/src/github.com/kz6fittycent/go-password-generator/go-password-generator.go:83 +0x6a

From https://github.com/kz6fittycent/go-password-generator/blob/master/go-password-generator.go#L82 it looks like the command needs to run from a working directory equal to that of where nounlist lives. There are two options I can thinkg of to get this going:

  • add a parameter to the application where to pickup the noun and adjective lists from.
  • given that, from albeit a quick look, there is no file writing, you can add a wrapper that does cd $SNAP first (provided those files are in the root of the snap).

Here’s the thing; the required files ARE NOT being included in the build. Unless they’ve been installed “somewhere else”, nounlist & adjectivelist are not appearing (hidden or otherwise) in the snap’s folder(s). This may be intentional but this seems to be problematic for simpler applications, such as this.

Additionally, other applications that I’ve snapped in the past have not needed any of these additional build parameters.

I’ll try editing the parameters to compensate for this but I don’t see how this is a true fix; as other devs may want to keep the code consistent across builds.

EDIT:

I stand corrected, the files are in /snap/passbot/ but aren’t being populated in the ~/snap/passbot/ folder(s).

So, what am I missing here? This seems a bit counter intuitive.

This seems wrong…

I have to cd into the /snap/passbot directory to run it (successfully):

/snap/passbot/27 $ passbot
Inqu1$1t1v3Ex@m1n3r 

Just to be clear, as I’m still in the learning phase of snapping.

When you say to “add a wrapper that does cd $SNAP first”, where would the wrapper need to be placed in the .yaml?

And, again my apologies, what would that look like?

I’ve attempted several (and I do mean SEVERAL) ways of doing this based on documentation and examples on github and the snap successfully builds, but still fails to run.

I can cd into the /snap/passbot/current directory and it runs as expected but I’m pretty sure users don’t want that…

Again, TIA!!