Snap for assistant-relay

I’m trying to snapify Google Assistant Relay 2.0 so I can easily install it on my pi running ubuntu core.

This is the snapcraft.yaml that I wrote:

name: assistant-relay
version: '0.0.1'
summary: Send commands to the Google Assistant.
description: >
  Assistant Relay is a Node.js server. It's exposed with an Express Web Server that allows for commands to be sent to the Google Assistant.
    
grade: stable
confinement: strict

parts:
  cast-web-api:
    plugin: nodejs
    source: git@github.com:greghesp/assistant-relay.git

apps:
  assistant-relay:
    command: npm run start
    daemon: simple
    plugs: [network, network-bind]

To configure this app I need to edit the /snap/assistant-relay/x1/lib/node_modules/assistant-relay/server/configurations/config.json which is read-only. How do I solve this? I will also need to save my credentials to server\configurations\secrets.

You could try doing this with layout support. You need to declare base: core to indicate to snapcraft that you’re using modern support, and then add a layout block:

grade: stable
confinement: strict
base: core # or core18

layout:
  $SNAP/lib/node_modules/assistant-relay/server/configurations/config.json:
    bind-file: $SNAP_DATA/config.json
  $SNAP/lib/node_modules/assistant-relay/server/configurations/secrets:
    bind: $SNAP_DATA/secrets # use bind-file if this is a file not a directory

Once you install the snap with these set you will be able to write your config.json and secrets to /var/snap/assistant-relay/current/config.json and .../secrets. One thing to note, however, is that on first installation these files/directories will be blank so you might need to have a wrapper script that ensures they’re populated with sane defaults the first time your snap is executed:

parts:
  wrapper-script:
    plugin: dump
    source: .
    override-pull: |
      echo <<EOF > exec-wrapper
      #!/bin/bash
      if [ ! -f "$SNAP_DATA/config.json" ]; then
          cp $SNAP/default-config.json $SNAP_DATA/config.json
      fi
      exec "$@"
      EOF
      chmod +x exec-wrapper

  # the other parts go here
apps:
  assistant-relay:
    command: exec-wrapper npm run start

Alternatively to a wrapper, you can add an install hook.

Thanks @lucyllewy . This is my yaml

name: assistant-relay
version: '0.0.1'
summary: Send commands to the Google Assistant.
description: >
  Assistant Relay is a Node.js server. It's exposed with an Express Web Server that allows for commands to be sent to the Google Assistant.
    
grade: stable
confinement: strict
base: core18

layout:
  $SNAP/lib/node_modules/assistant-relay/server/configurations/config.json:
    bind-file: $SNAP_DATA/config.json
  $SNAP/lib/node_modules/assistant-relay/server/configurations/secrets:
    bind: $SNAP_DATA/secrets 

parts:
  cast-web-api:
    plugin: nodejs
    source: git@github.com:greghesp/assistant-relay.git

apps:
  assistant-relay:
    command: exec-wrapper npm run start

and these are the errors that I’m getting. What am I missing?

Thanks!

The nodejs plugin is using yarn as the package manager. You need to tell it to use NPM:

parts:
  cast-web-api:
    nodejs-package-manager: npm
    ...

I guess i’m moving in the right direction. This is the yaml

name: assistant-relay
version: '0.0.1'
summary: Send commands to the Google Assistant.
description: >
  Assistant Relay is a Node.js server. It's exposed with an Express Web Server that allows for commands to be sent to the Google Assistant.
    
grade: stable
confinement: strict
base: core18

layout:
  $SNAP/lib/node_modules/assistant-relay/server/configurations/config.json:
    bind-file: $SNAP_DATA/config.json
  $SNAP/lib/node_modules/assistant-relay/server/configurations/secrets:
    bind: $SNAP_DATA/secrets 

parts:
  assistant-relay:
    nodejs-package-manager: npm
    plugin: nodejs
    source: git@github.com:greghesp/assistant-relay.git

apps:
  assistant-relay:
    command: npm run start

and this is the new error:

ignacio@xps:~/assistant-relay$ snapcraft 
Skipping pull assistant-relay (already ran)
Skipping build assistant-relay (already ran)
Skipping stage assistant-relay (already ran)
Skipping prime assistant-relay (already ran)
Failed to generate snap metadata: The specified command 'npm' defined in the app 'assistant-relay' does not exist or is not executable.
Ensure that 'npm' is relative to the prime directory.

Thanks for the help!