From 24e3a2b57a53329e1d7648add5e0332ca87277e6 Mon Sep 17 00:00:00 2001 From: Ben Francis Date: Tue, 4 Jun 2024 17:35:49 +0100 Subject: [PATCH 1/5] Basic snapcraft.yaml --- .gitignore | 3 +++ snap/snapcraft.yaml | 13 +++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 snap/snapcraft.yaml diff --git a/.gitignore b/.gitignore index 15aea4110..ec63d24ae 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,6 @@ npm-debug.log # Test artifacts /coverage/ + +# Snap packages +*.snap diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml new file mode 100644 index 000000000..f14d51b64 --- /dev/null +++ b/snap/snapcraft.yaml @@ -0,0 +1,13 @@ +name: webthings-gateway +base: core22 +version: '2.0' +summary: WebThings Gateway +description: | + A self-hosted web application for monitoring and controlling a building over + the web. +grade: devel +confinement: devmode + +parts: + webthings-gateway: + plugin: nil From 5873b6b507b8e7eb665683cde10519693d8d1206 Mon Sep 17 00:00:00 2001 From: Ben Francis Date: Wed, 5 Jun 2024 18:01:05 +0100 Subject: [PATCH 2/5] WIP dependencies installation --- snap/snapcraft.yaml | 101 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 99 insertions(+), 2 deletions(-) diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index f14d51b64..2405c0134 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -1,6 +1,6 @@ name: webthings-gateway base: core22 -version: '2.0' +version: 2.0.0 summary: WebThings Gateway description: | A self-hosted web application for monitoring and controlling a building over @@ -8,6 +8,103 @@ description: | grade: devel confinement: devmode +apps: + webthings-gateway: + command: node build/gateway.js + parts: webthings-gateway: - plugin: nil + plugin: npm + npm-include-node: true + npm-node-version: 10.24.1 + source: . + build-packages: + - autoconf + - build-essential + - curl + - git + - libbluetooth-dev + - libboost-python-dev + - libboost-thread-dev + - libffi-dev + - libglib2.0-dev + - libpng-dev + - libudev-dev + - libusb-1.0-0-dev + - pkg-config + - python-six + - python3-pip + #- autoconf + #- automake + #- build-essential + #- git + #- libtool + #- pkg-config + #- python + #- python3 + #- python3-pip + #- python3-setuptools + stage-packages: + - arping + - ffmpeg + - iputils-ping + - libcap2-bin + - lsb-release + - mosquitto + - net-tools + #- python + - python-six + - python3 + override-build: | + # Install nvm to install node and npm + curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash + # Re-initialise terminal session + . ~/.bashrc + # Install the version of node from .nvmrc + nvm install + nvm use + + # Add the locally installed npm to our path. + # export makes it also propagate into the sub-shell. + # export PATH=$PATH:$(pwd)/../npm/bin + + # Allow npm to run as root properly + # https://docs.npmjs.com/misc/config#unsafe-perm + npm config -g set unsafe-perm true + + # Install node-gyp, as it didn't seem to get installed by `npm install` + # for some reason + npm install -g node-gyp + + # Start a sub-shell so that the SUDO_* bits aren't propagated to the rest + # of the process unnecessarily. + ( + # Make the subshell exit if one of the commands fails + set -e + + # Unset the sudo environment variables to make git happy + # https://github.com/snapcore/snapcraft/commit/93fd2825733ea8725502d2ab62124be5179c6407 + unset SUDO_UID + unset SUDO_GID + + # Install all of the necessary node modules + CPPFLAGS="-DPNG_ARM_NEON_OPT=0" npm ci + + # Run the webpack process now, rather than at each launch + ./node_modules/.bin/webpack + + # Clean up a couple things + rm -rf ./node_modules/gifsicle + rm -rf ./node_modules/mozjpeg + + # Remove all but production dependencies + npm prune --production + ) + + # Install Python library + pip3 install --system --install-option="--prefix=" --no-binary=":all:" -r ./requirements.txt + + # Install things into the snap + mkdir -p $SNAPCRAFT_PART_INSTALL/opt + cp -r . $SNAPCRAFT_PART_INSTALL/opt/webthings-gateway + rm -rf $SNAPCRAFT_PART_INSTALL/opt/webthings-gateway/.git \ No newline at end of file From a3472532d9ec6036abc9d1d7b30eceea3369700c Mon Sep 17 00:00:00 2001 From: Ben Francis Date: Fri, 14 Jun 2024 17:55:19 +0100 Subject: [PATCH 3/5] Second attempt at snapcraft.html --- snap/snapcraft.yaml | 88 ++++++++++++++------------------------------- 1 file changed, 26 insertions(+), 62 deletions(-) diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 2405c0134..4647dbbb3 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -14,9 +14,7 @@ apps: parts: webthings-gateway: - plugin: npm - npm-include-node: true - npm-node-version: 10.24.1 + plugin: nil source: . build-packages: - autoconf @@ -34,77 +32,43 @@ parts: - pkg-config - python-six - python3-pip - #- autoconf - #- automake - #- build-essential - #- git - #- libtool - #- pkg-config - #- python + #stage-packages: + #- arping + #- ffmpeg + #- iputils-ping + #- libcap2-bin + #- lsb-release + #- mosquitto + #- net-tools + #- python-six #- python3 - #- python3-pip - #- python3-setuptools - stage-packages: - - arping - - ffmpeg - - iputils-ping - - libcap2-bin - - lsb-release - - mosquitto - - net-tools - #- python - - python-six - - python3 override-build: | - # Install nvm to install node and npm + # Install nvm, node and npm curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash - # Re-initialise terminal session - . ~/.bashrc - # Install the version of node from .nvmrc - nvm install - nvm use - - # Add the locally installed npm to our path. - # export makes it also propagate into the sub-shell. - # export PATH=$PATH:$(pwd)/../npm/bin + export NVM_DIR="$HOME/.nvm" + . "$NVM_DIR/nvm.sh" + . "$NVM_DIR/bash_completion" - # Allow npm to run as root properly - # https://docs.npmjs.com/misc/config#unsafe-perm + # Allow npm to run as root npm config -g set unsafe-perm true - # Install node-gyp, as it didn't seem to get installed by `npm install` - # for some reason - npm install -g node-gyp - - # Start a sub-shell so that the SUDO_* bits aren't propagated to the rest - # of the process unnecessarily. - ( - # Make the subshell exit if one of the commands fails - set -e - - # Unset the sudo environment variables to make git happy - # https://github.com/snapcore/snapcraft/commit/93fd2825733ea8725502d2ab62124be5179c6407 - unset SUDO_UID - unset SUDO_GID - - # Install all of the necessary node modules - CPPFLAGS="-DPNG_ARM_NEON_OPT=0" npm ci + # Install all of the necessary node modules + CPPFLAGS="-DPNG_ARM_NEON_OPT=0" npm ci - # Run the webpack process now, rather than at each launch - ./node_modules/.bin/webpack + # Build + npm run build - # Clean up a couple things - rm -rf ./node_modules/gifsicle - rm -rf ./node_modules/mozjpeg + # Clean up some dependencies + rm -rf ./node_modules/gifsicle + rm -rf ./node_modules/mozjpeg - # Remove all but production dependencies - npm prune --production - ) + # Remove all but production dependencies + npm prune --production # Install Python library - pip3 install --system --install-option="--prefix=" --no-binary=":all:" -r ./requirements.txt + pip3 install -r /home/node/webthings/gateway/requirements.txt # Install things into the snap mkdir -p $SNAPCRAFT_PART_INSTALL/opt cp -r . $SNAPCRAFT_PART_INSTALL/opt/webthings-gateway - rm -rf $SNAPCRAFT_PART_INSTALL/opt/webthings-gateway/.git \ No newline at end of file + rm -rf $SNAPCRAFT_PART_INSTALL/opt/webthings-gateway/.git From aa83bbf7250902eac47e9368aa5292a79e69e8aa Mon Sep 17 00:00:00 2001 From: Ben Francis Date: Mon, 17 Jun 2024 22:15:40 +0100 Subject: [PATCH 4/5] Use wget instead of curl and install nvm in working directory --- snap/snapcraft.yaml | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 4647dbbb3..697f386de 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -19,7 +19,6 @@ parts: build-packages: - autoconf - build-essential - - curl - git - libbluetooth-dev - libboost-python-dev @@ -32,6 +31,7 @@ parts: - pkg-config - python-six - python3-pip + - wget #stage-packages: #- arping #- ffmpeg @@ -43,11 +43,14 @@ parts: #- python-six #- python3 override-build: | - # Install nvm, node and npm - curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash - export NVM_DIR="$HOME/.nvm" - . "$NVM_DIR/nvm.sh" - . "$NVM_DIR/bash_completion" + # Install node and npm + # Install node using nvm rather than the npm plugin so that override-build can be used + # Install nvm in the working directory rather than ~/.nvm due to permissions + mkdir -p nvm + # Use wget instead of curl because of https://github.com/nvm-sh/nvm/issues/2507 + wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | NVM_DIR=`pwd`/nvm bash + # Run nvm.sh with --install because of https://github.com/nvm-sh/nvm/issues/1985 + . nvm/nvm.sh --install # Allow npm to run as root npm config -g set unsafe-perm true @@ -66,7 +69,7 @@ parts: npm prune --production # Install Python library - pip3 install -r /home/node/webthings/gateway/requirements.txt + pip3 install -r requirements.txt # Install things into the snap mkdir -p $SNAPCRAFT_PART_INSTALL/opt From d2a25e109f323a63b840d84c5cb8e7bf6a18e240 Mon Sep 17 00:00:00 2001 From: Ben Francis Date: Tue, 23 Jul 2024 16:04:00 +0100 Subject: [PATCH 5/5] Third pass at snapcraft.yaml thanks to @ogra1 - closes #2147 --- snap/snapcraft.yaml | 81 +++++++++++++++------------------------------ 1 file changed, 27 insertions(+), 54 deletions(-) diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 697f386de..e0d705bba 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -1,25 +1,40 @@ name: webthings-gateway base: core22 -version: 2.0.0 +version: '2.0.0' summary: WebThings Gateway description: | A self-hosted web application for monitoring and controlling a building over the web. -grade: devel -confinement: devmode + +grade: stable +confinement: strict apps: webthings-gateway: - command: node build/gateway.js + command: bin/npm --prefix $SNAP/lib/node_modules/webthings-gateway run run-only + daemon: simple + plugs: + - network + - network-bind parts: + python-deps: + plugin: python + source: https://github.com/WebThingsIO/gateway.git + python-requirements: + - requirements.txt webthings-gateway: - plugin: nil - source: . + plugin: npm + source: https://github.com/WebThingsIO/gateway.git + after: [ python-deps ] + npm-include-node: true + npm-node-version: 10.24.1 + build-environment: + - npm_config_unsafe_perm: true + - NODE_ENV: dev + - CPPFLAGS: "$CPPFLAGS -DPNG_ARM_NEON_OPT=0" build-packages: - - autoconf - build-essential - - git - libbluetooth-dev - libboost-python-dev - libboost-thread-dev @@ -28,50 +43,8 @@ parts: - libpng-dev - libudev-dev - libusb-1.0-0-dev - - pkg-config - - python-six - - python3-pip - - wget - #stage-packages: - #- arping - #- ffmpeg - #- iputils-ping - #- libcap2-bin - #- lsb-release - #- mosquitto - #- net-tools - #- python-six - #- python3 override-build: | - # Install node and npm - # Install node using nvm rather than the npm plugin so that override-build can be used - # Install nvm in the working directory rather than ~/.nvm due to permissions - mkdir -p nvm - # Use wget instead of curl because of https://github.com/nvm-sh/nvm/issues/2507 - wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | NVM_DIR=`pwd`/nvm bash - # Run nvm.sh with --install because of https://github.com/nvm-sh/nvm/issues/1985 - . nvm/nvm.sh --install - - # Allow npm to run as root - npm config -g set unsafe-perm true - - # Install all of the necessary node modules - CPPFLAGS="-DPNG_ARM_NEON_OPT=0" npm ci - - # Build - npm run build - - # Clean up some dependencies - rm -rf ./node_modules/gifsicle - rm -rf ./node_modules/mozjpeg - - # Remove all but production dependencies - npm prune --production - - # Install Python library - pip3 install -r requirements.txt - - # Install things into the snap - mkdir -p $SNAPCRAFT_PART_INSTALL/opt - cp -r . $SNAPCRAFT_PART_INSTALL/opt/webthings-gateway - rm -rf $SNAPCRAFT_PART_INSTALL/opt/webthings-gateway/.git + craftctl default + npm install --only-dev + npm run-script build + cp -av build $CRAFT_PART_INSTALL/lib/node_modules/webthings-gateway/