Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Snap package #73

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .github/workflows/build-snap.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: snapbuild

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
platform:
- amd64
steps:
- uses: actions/checkout@v3
with:
path: snap
- uses: docker/setup-qemu-action@v2
with:
platforms: ${{ matrix.platform }}
- uses: diddlesnaps/snapcraft-multiarch-action@v1
id: snapcraft
with:
architecture: ${{ matrix.platform }}
path: snap
28 changes: 27 additions & 1 deletion .github/workflows/release-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,30 @@ jobs:
- run: npm install
- uses: JS-DevTools/npm-publish@v1
with:
token: ${{ secrets.NPM_PUBLISH_TOKEN }}
token: ${{ secrets.NPM_PUBLISH_TOKEN }}
publish-snap:
runs-on: ubuntu-latest
needs: publish
strategy:
matrix:
platform:
- amd64
- arm64
steps:
- uses: actions/checkout@v3
with:
path: snap
- uses: docker/setup-qemu-action@v2
with:
platforms: ${{ matrix.platform }}
- uses: diddlesnaps/snapcraft-multiarch-action@v1
id: snapcraft
with:
architecture: ${{ matrix.platform }}
path: snap
- uses: snapcore/action-publish@v1
env:
SNAPCRAFT_STORE_CREDENTIALS: ${{ secrets.STORE_LOGIN }}
with:
snap: ${{ steps.snapcraft.outputs.snap }}
release: ${{ startsWith(github.ref, 'refs/tags/') && 'candidate' || 'edge'}}
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,6 @@ device, and then copy the modules on to your device.
## Running as a service

An example service file is provided [here](https://github.com/flowforge/flowforge-device-agent/tree/main/service).

## Running as SNAP
[![Get it from the Snap Store](https://snapcraft.io/static/images/badges/en/snap-store-white.svg)](https://snapcraft.io/flowforge-device-agent)
32 changes: 32 additions & 0 deletions snap/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[![Get it from the Snap Store](https://snapcraft.io/static/images/badges/en/snap-store-white.svg)](https://snapcraft.io/flowforge-device-agent)

# FlowForge Device Agent Snap Package

This is the README file for the FlowForge Device Agent Snap package, which allows you to manage Node-RED instances running on remote devices using the FlowForge platform. The snap package includes the device agent and configuration files necessary for connecting to a FlowForge platform instance and receiving updates.

For the complete documentation see the [README file](https://github.com/flowforge/flowforge-device-agent#flowforge-device-agent) of the npm package and the [FlowForge Website](https://flowforge.com/docs/user/devices/)

## Installation

To install the FlowForge Device Agent Snap package, run the following command:

```
sudo snap install flowforge-device-agent
```

## Configuration

1. The agent's configuration is provided in a `device.yml` file. The Snap package ensures that a writable directory exists in `$SNAP_USER_DATA/flowforge-device` or rather `~/snap/flowforge-device-agent/current/flowforge-device`
2. Copy the `device.yml` file provided by the FlowForge platform to the writable directory at `$SNAP_USER_DATA/flowforge-device/device.yml` or modify the template.

## Usage

Start the FlowForge Device Agent with the following command:

```
flowforge-device-agent.device-agent
```

## Documentation

More information on our website [FlowForge Website](https://flowforge.com/docs/user/devices/)
7 changes: 7 additions & 0 deletions snap/local/settings/device.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
deviceId:
token:
credentialSecret:
forgeURL:
brokerURL:
brokerUsername:
brokerPassword:
31 changes: 31 additions & 0 deletions snap/local/settings/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/sh
config_file="device.yml"

# Get the paths to the read-only and writable directories
snap_user_data="$SNAP_USER_DATA/flowforge-device"
read_only_config="$SNAP/config/$config_file"
writable_config="$snap_user_data/$config_file"

# Ensure the writable directory exists
mkdir -p "$snap_user_data"

# Check if the writable configuration file exists
if [ ! -f "$writable_config" ]; then
# If not, copy the read-only configuration file to the writable directory
cp "$read_only_config" "$writable_config"
fi

# Define default values for optional arguments
interval="60"
port="1881"

# Parse optional arguments
while getopts "i:p:m:" opt; do
case $opt in
i) interval="$OPTARG";;
p) port="$OPTARG";;
*) echo "Usage: $0 [-i interval] [-p port]"; exit 1;;
esac
done

"$SNAP"/bin/node "$SNAP"/lib/node_modules/.bin/flowforge-device-agent -d "$snap_user_data" -c "$writable_config" -i "$interval" -p "$port"
71 changes: 71 additions & 0 deletions snap/snapcraft.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: flowforge-device-agent
adopt-info: flowforge-device-agent
summary: An agent to start FlowForge Projects on remote devices
description: The FlowForge platform can be used to manage Node-RED instances running on remote Devices. A Device runs a software agent that connects back to the platform to receive updates.
base: core20
grade: stable
confinement: strict

architectures:
- build-on: amd64
- build-on: arm64

apps:
device-agent:
command: bin/start
plugs:
- network
- network-bind
- home
- removable-media
npm:
command: bin/npm
plugs:
- home
- network

parts:
node: # We dump in a specific version of node/npm from upstream.
plugin: dump
source:
- on amd64: https://nodejs.org/dist/v16.19.0/node-v16.19.0-linux-x64.tar.gz
- on arm64: https://nodejs.org/dist/v16.19.0/node-v16.19.0-linux-arm64.tar.gz
flowforge-device-agent:
after: [node]
plugin: nil # We use the nil plugin so we can fully override the build with whatever we need to do
source: .
build-environment:
# AUDITING CONTROL
- AUDIT_ENABLED: "1" #0|1
- AUDIT_LEVEL: "high" #low|moderate|high|critical

build-packages:
- libatomic1
- build-essential
override-build: |
PATH=$PATH:../npm/bin

# setup npm
npm config set unsafe-perm True

# clean cache
npm cache verify

# install flowforge-device-agent
npm install --no-audit --no-fund --prefix $SNAPCRAFT_PART_INSTALL/lib @flowforge/flowforge-device-agent

# create package.json
cd $SNAPCRAFT_PART_INSTALL/lib
npm init --yes

#set snap version
VER=$(npm show @flowforge/flowforge-device-agent version)
echo "VERSION $(npm show @flowforge/flowforge-device-agent version)"
snapcraftctl set-version $VER

settings:
plugin: dump
source: snap/local/settings
organize:
start.sh: "bin/start"
device.yml: "config/device.yml"