Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
kubicek committed Nov 23, 2024
0 parents commit 27f9dbc
Show file tree
Hide file tree
Showing 9 changed files with 236 additions and 0 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/pi-gen.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Generate RPI Image

on:
push:
tags:
- '*'
workflow_dispatch:

permissions:
contents: write

jobs:
build-rpi-image:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Run pi-gen-action
uses: usimd/[email protected]
id: build
with:
image-name: ezui
hostname: ezui
username: ezui
password: ezui
compression: gz
compression-level: 6
disable-first-boot-user-rename: 1
enable-ssh: 1
keyboard-keymap: us
locale: en_US.UTF-8
pi-gen-version: arm64
release: bookworm
stage-list: stage0 stage1 stage2 ./stage-ezui
timezone: Europe/Prague
verbose-output: true

- name: Release image
uses: softprops/action-gh-release@v2
with:
name: first
files: ${{ steps.build.outputs.image-path }}

21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Jiří Kubíček, KRAXNET s.r.o.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
82 changes: 82 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Raspberry Pi Image Builder with Node-RED and Dashboard

This repository automates the creation of a custom Raspberry Pi image pre-installed with [Node-RED](https://nodered.org/) and its Dashboard. Using GitHub Actions, the image is built with [pi-gen](https://github.com/RPi-Distro/pi-gen) and deployed as downloadable releases.

## Features

- Automated image building and release using [pi-gen-action](https://github.com/usimd/pi-gen-action).
- Pre-installed [Node-RED](https://nodered.org/) and [Node-RED Dashboard](https://flows.nodered.org/node/node-red-dashboard).
- Configured to work out-of-the-box for Raspberry Pi devices.

## Getting Started

### Download the Image

Head to the [Releases](https://github.com/your-username/your-repo-name/releases) section to download the latest Raspberry Pi image. Flash it to your SD card using a tool like [Raspberry Pi Imager](https://www.raspberrypi.com/software/) or [Balena Etcher](https://www.balena.io/etcher/).

### Prerequisites

- A Raspberry Pi (tested on models XYZ, adjust as needed).
- A microSD card (8 GB or larger recommended).
- Optional: Ethernet or Wi-Fi setup if network connectivity is required.

### Flashing the Image

1. Download the `.img` file from the [Releases](https://github.com/your-username/your-repo-name/releases) section.
2. Use [Raspberry Pi Imager](https://www.raspberrypi.com/software/) or [Balena Etcher](https://www.balena.io/etcher/) to flash the image to your microSD card.
3. Insert the microSD card into your Raspberry Pi and power it on.

### Accessing Node-RED

1. Open a web browser and navigate to `http://<your-pi-ip>:1880`.
2. Customize and deploy your flows using the built-in Node-RED editor.
3. Use the Node-RED Dashboard at `http://<your-pi-ip>:1880/ui` to interact with your projects.

## How It Works

### GitHub Actions

This project uses [pi-gen-action](https://github.com/davestephens/pi-gen-action) to automate the build process. Upon every push to the `main` branch or when manually triggered, GitHub Actions:

1. Clones the [pi-gen](https://github.com/RPi-Distro/pi-gen) repository.
2. Applies customizations for Node-RED and the Dashboard.
3. Builds the Raspberry Pi image.
4. Uploads the image as a release artifact.

### Directory Structure

- `stage-custom`: Contains customization scripts and configuration for Node-RED.
- `.github/workflows`: Defines the GitHub Actions workflows.
- `config`: Configuration files for pi-gen.

## Development and Customization

### Modifying Node-RED Configuration

To customize the Node-RED environment:

1. Update the files in the `stage-custom` directory.
2. Push changes to the repository. The new image will be built and released automatically.

### Testing Locally

You can build the image locally using `pi-gen`. Refer to the [pi-gen documentation](https://github.com/RPi-Distro/pi-gen) for setup instructions.

## Contributing

Contributions are welcome! Please open an issue or submit a pull request to suggest changes or enhancements.

## License

This project is licensed under the [MIT License](LICENSE).

## Acknowledgments

- [pi-gen](https://github.com/RPi-Distro/pi-gen) - The official Raspberry Pi image builder.
- [pi-gen-action](https://github.com/davestephens/pi-gen-action) - GitHub Action for pi-gen.
- [Node-RED](https://nodered.org/) - Low-code programming for event-driven applications.

---

Make sure to replace placeholders like `your-username` and `your-repo-name` with the appropriate values from your project. Let me know if you need further adjustments!

8 changes: 8 additions & 0 deletions stage-ezui/01-install-packages/00-packages-nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
vlc
chromium
plymouth
plymouth-themes
xinit
xserver-xorg
nodejs
npm
66 changes: 66 additions & 0 deletions stage-ezui/02-nodered/00-run-chroot.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/bin/bash -e

# based on https://github.com/Tknika/iombian/blob/master/stage9/05-node-red/00-run-chroot.sh

NODERED_VERSION=4.0.5

NODERED_USER=$FIRST_USER_NAME
NODERED_GROUP=$FIRST_USER_NAME
NODERED_HOME=$( getent passwd "$NODERED_USER" | cut -d: -f6 )

# install node-red package
npm i -g --unsafe-perm --no-progress node-red@$NODERED_VERSION

# set local folder
mkdir -p "$NODERED_HOME/.node-red/node_modules"
chown -Rf $NODERED_USER:$NODERED_GROUP $NODERED_HOME/.node-red/
pushd "$NODERED_HOME/.node-red"
npm config set update-notifier false

# create package.json
if [ ! -f "package.json" ]; then
echo '{' > package.json
echo ' "name": "node-red-project",' >> package.json
echo ' "description": "A Node-RED Project",' >> package.json
echo ' "version": "0.0.1",' >> package.json
echo ' "dependencies": {' >> package.json
echo ' }' >> package.json
echo '}' >> package.json
fi

# install bcryptjs library
npm i --unsafe-perm --save --no-progress bcryptjs

# install extra Pi nodes
EXTRANODES="node-red-dashboard"
npm i --unsafe-perm --save --no-progress $EXTRANODES

# reset permissions
popd
mkdir -p "$NODERED_HOME/.npm"
chown -Rf $NODERED_USER:$NODERED_GROUP $NODERED_HOME/.npm
chown -Rf $NODERED_USER:$NODERED_GROUP $NODERED_HOME/.node-red/

# start/stop/log scripts
mkdir -p /usr/bin
curl -sL -o /usr/bin/node-red-start https://raw.githubusercontent.com/node-red/linux-installers/master/resources/node-red-start
curl -sL -o /usr/bin/node-red-stop https://raw.githubusercontent.com/node-red/linux-installers/master/resources/node-red-stop
curl -sL -o /usr/bin/node-red-restart https://raw.githubusercontent.com/node-red/linux-installers/master/resources/node-red-restart
curl -sL -o /usr/bin/node-red-reload https://raw.githubusercontent.com/node-red/linux-installers/master/resources/node-red-reload
curl -sL -o /usr/bin/node-red-log https://raw.githubusercontent.com/node-red/linux-installers/master/resources/node-red-log
curl -sL -o /etc/logrotate.d/nodered https://raw.githubusercontent.com/node-red/linux-installers/master/resources/nodered.rotate
chmod +x /usr/bin/node-red-start
chmod +x /usr/bin/node-red-stop
chmod +x /usr/bin/node-red-restart
chmod +x /usr/bin/node-red-reload
chmod +x /usr/bin/node-red-log

# add systemd script
curl -sL -o /lib/systemd/system/nodered.service https://raw.githubusercontent.com/node-red/linux-installers/master/resources/nodered.service
sed -i 's#^User=pi#User='$NODERED_USER'#;s#^Group=pi#Group='$NODERED_GROUP'#;s#^WorkingDirectory=/home/pi#WorkingDirectory='$NODERED_HOME'#;' /lib/systemd/system/nodered.service

# remove unneeded large sentiment library to save space and load time
rm -f /usr/lib/node_modules/node-red/node_modules/multilang-sentiment/build/output/build-all.json

# enable systemd service
systemctl enable nodered.service
4 changes: 4 additions & 0 deletions stage-ezui/02-nodered/00-run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash -e

mkdir -p ${ROOTFS_DIR}/home/${FIRST_USER_NAME}/.node-red
mkdir -p ${ROOTFS_DIR}/home/${FIRST_USER_NAME}/.npm
7 changes: 7 additions & 0 deletions stage-ezui/03-splash-auto-boot/00-run-chroot.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
raspi-config nonint do_boot_behaviour B2
plymouth-set-default-theme --rebuild-initrd spinfinity

echo "if [[ -z \$SSH_CONNECTION ]]; then
startx /usr/bin/chromium-browser --noerrdialogs --disable-infobars --kiosk http://localhost:1880/ui -- -nocursor > /dev/null 2>&1
fi" >> /home/${FIRST_USER_NAME}/.bashrc

Empty file added stage-ezui/EXPORT_IMAGE
Empty file.
4 changes: 4 additions & 0 deletions stage-ezui/prerun.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash -e
if [ ! -d "${ROOTFS_DIR}" ]; then
copy_previous
fi

0 comments on commit 27f9dbc

Please sign in to comment.