100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps
Java asset-managementbuildingdashboarddataplatformdevice-managementedge-computingenergyenergy-managementenergy-monitorfleet-managementfleet-telematicsiotiot-applicationiot-platformmodbusmqttmqtt-brokerota-updaterules-enginesmartcity
Work on Raspberry Pi 3 platform deployment
Christian Bauer803a43cd6b9e
diff --git a/platform/rpi3/README.md b/platform/rpi3/README.mdnew file mode 100644index 000000000..5cf7a53a9--- /dev/null+++ b/platform/rpi3/README.md@@ -0,0 +1,41 @@+# Installing OpenRemote on Raspberry Pi 3++You need a [Raspberry Pi 3](https://www.raspberrypi.org/products/raspberry-pi-3-model-b/) and and empty SD card. First download [Etcher](https://etcher.io/) to burn SD card images and then download the [HypriotOS SD card image](https://blog.hypriot.com/downloads/) and write it to your card. This is a minimal Linux variant that is optimized for running Docker containers.++## Docker machine setup++The Docker server and your workstation Docker client must be customized so you can connect and deploy OpenRemote containers on the Raspberry Pi.++On your workstation you should have a Docker installation. Execute the following script to generate the necessary configuration files in the `build` directory:++```+DOCKER_MACHINE_NAME=openremote1 \+DOCKER_MACHINE_IP=10.0.0.123 \+WIFI_SSID=MyWifiNetwork \+WIFI_PASSWORD=MyWifiPassword \+SSH_PUBKEY= $HOME/ssh/id_dsa.pub \+ platform/rpi3/machine/openremote-setup.sh+```++Note that `DOCKER_MACHINE_NAME` is used for the name of the Docker Machine configuration on your workstation, as well as the host name of the Raspberry Pi.++The `DOCKER_MACHINE_IP` should be the IP address you expect your Raspberry Pi to have when it connects to your LAN. We recommend you lease a static IP address to the machine in your LAN router's DHCP setup. If you don't use Wifi, edit the file `build/boot/device-init.yaml` after generation.++The provided `SSH_PUBKEY` will be the only authorized key for SSH connections to your Raspberry Pi, password authentication is disabled. You can connect with the user `openremote` on port 22 or simply use `docker-machine ssh openremote1`.++The setup script generates files that should be copied onto the `boot` partition of your SD card, which is visible when you mount the SD card on your workstation. Also copy the Docker Machine client configuration files into the `$HOME/.docker/machine/machines/` directory.++After booting the Raspberry Pi from the SD card, verify the connection with a Docker client from your workstation:++```+eval $(docker-machine env openremote1)+docker version+```++## Customizing Docker authentication++By default a dummy CA and self-signed certificates are generated for the Docker client connection and authentication on the Docker host. The same key is used on the server and client. See the comments in `platform/rpi3/machine/openremote-setup.sh` for customization options.++## Deploying OpenRemote containers++TBC\ No newline at end of filediff --git a/platform/rpi3/machine/.gitignore b/platform/rpi3/machine/.gitignorenew file mode 100644index 000000000..33296d481--- /dev/null+++ b/platform/rpi3/machine/.gitignore@@ -0,0 +1 @@+sdcard/build/\ No newline at end of filediff --git a/platform/rpi3/machine/openremote-setup.sh b/platform/rpi3/machine/openremote-setup.shnew file mode 100755index 000000000..1afbf85ea--- /dev/null+++ b/platform/rpi3/machine/openremote-setup.sh@@ -0,0 +1,122 @@+#!/bin/bash -e++# Generates SSL files for Docker client/server setup++# Prepares a Docker Machine client configuration++# Prepares a Hypriot OS boot partition custom init script with+# Wifi configuration and SSH pubkey-only authentication++: ${DOCKER_MACHINE_NAME?"Please set the name of your configuration"}+: ${DOCKER_MACHINE_IP:?"Please set the IP/hostname of your host"}+: ${SSH_PUBKEY:?"Please set the path to your SSH public key"}+: ${WIFI_SSID:?"Please set the Wifi network SSID"}+: ${WIFI_PASSWORD:?"Please set the Wifi password"}++DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"++# Clean build directory+BUILD_DIR=$DIR/build+if [[ -d $BUILD_DIR ]]; then+ rm -r $BUILD_DIR+fi+MACHINE_BUILD_DIR=$BUILD_DIR/$DOCKER_MACHINE_NAME+mkdir -p $MACHINE_BUILD_DIR+BOOT_BUILD_DIR=$BUILD_DIR/boot+mkdir -p $BOOT_BUILD_DIR++# Configure this to customize generation of SSL certificates, keys, and CA+docker run --rm -v ${MACHINE_BUILD_DIR}:/certs \+ -e CA_EXPIRE=99999 \+ -e SSL_EXPIRE=99999 \+ -e SSL_SUBJECT=$DOCKER_MACHINE_IP \+ -e SSL_IP=$DOCKER_MACHINE_IP \+ -e SSL_DNS=$DOCKER_MACHINE_IP \+ paulczar/omgwtfssl++# Generate Docker Machine client configuration+cat > $MACHINE_BUILD_DIR/config.json << EOF+{+ "ConfigVersion": 3,+ "Driver": {+ "IPAddress": "$DOCKER_MACHINE_IP",+ "URL": "tcp://$DOCKER_MACHINE_IP:2376",+ "MachineName": "$DOCKER_MACHINE_NAME",+ "SSHUser": "openremote",+ "SSHPort": 22,+ "SSHKeyPath": "",+ "StorePath": "$HOME/.docker/machine",+ "SwarmMaster": false,+ "SwarmHost": "",+ "SwarmDiscovery": "",+ "EnginePort": 2376,+ "SSHKey": ""+ },+ "DriverName": "generic",+ "HostOptions": {+ "Driver": "",+ "Memory": 0,+ "Disk": 0,+ "EngineOptions": {+ "ArbitraryFlags": [],+ "Dns": null,+ "GraphDir": "",+ "Env": [],+ "Ipv6": false,+ "InsecureRegistry": [],+ "Labels": [],+ "LogLevel": "",+ "StorageDriver": "",+ "SelinuxEnabled": false,+ "TlsVerify": true,+ "RegistryMirror": [],+ "InstallURL": "https://get.docker.com"+ },+ "SwarmOptions": {+ "IsSwarm": false,+ "Address": "",+ "Discovery": "",+ "Agent": false,+ "Master": false,+ "Host": "tcp://0.0.0.0:3376",+ "Image": "swarm:latest",+ "Strategy": "spread",+ "Heartbeat": 0,+ "Overcommit": 0,+ "ArbitraryFlags": [],+ "ArbitraryJoinFlags": [],+ "Env": null,+ "IsExperimental": false+ },+ "AuthOptions": {+ "StorePath": "$HOME/.docker/machine/machines/$DOCKER_MACHINE_NAME",+ "CertDir": "$HOME/.docker/machine/machines/$DOCKER_MACHINE_NAME",+ "CaCertPath": "$HOME/.docker/machine/machines/$DOCKER_MACHINE_NAME/ca.pem",+ "CaPrivateKeyPath": "$HOME/.docker/machine/machines/$DOCKER_MACHINE_NAME/ca-key.pem",+ "ServerCertPath": "$HOME/.docker/machine/machines/$DOCKER_MACHINE_NAME/cert.pem",+ "ServerKeyPath": "$HOME/.docker/machine/machines/$DOCKER_MACHINE_NAME/key.pem",+ "ClientCertPath": "$HOME/.docker/machine/machines/$DOCKER_MACHINE_NAME/cert.pem",+ "ClientKeyPath": "$HOME/.docker/machine/machines/$DOCKER_MACHINE_NAME/key.pem",+ "CaCertRemotePath": "",+ "ServerCertRemotePath": "",+ "ServerKeyRemotePath": "",+ "ServerCertSANs": []+ }+ },+ "Name": "$DOCKER_MACHINE_NAME"+}+EOF++# Prepare the files for the boot SD card partition+mkdir -p $BOOT_BUILD_DIR/dockerssl+cp $MACHINE_BUILD_DIR/*.pem $BOOT_BUILD_DIR/dockerssl+cp $SSH_PUBKEY $BOOT_BUILD_DIR/openremote-ssh.pub+cp $DIR/src/* $BOOT_BUILD_DIR+sed -i '' "s/MY_HOSTNAME/$DOCKER_MACHINE_NAME/g" $BOOT_BUILD_DIR/device-init.yaml+sed -i '' "s/MY_SSID/$WIFI_SSID/g" $BOOT_BUILD_DIR/device-init.yaml+sed -i '' "s/MY_PASSWORD/$WIFI_PASSWORD/g" $BOOT_BUILD_DIR/device-init.yaml++echo "Setup files generated, next steps:"+echo "1. Download HypriotOS SD image and write it to an SD card (e.g. using Etcher): https://blog.hypriot.com/downloads/"+echo "2. Mount the SD card and copy files to boot partition: $BOOT_BUILD_DIR"+echo "3. Copy Docker Machine configuration from $MACHINE_BUILD_DIR into $HOME/.docker/machine/machines/$DOCKER_MACHINE_NAME"diff --git a/platform/rpi3/machine/src/device-init.yaml b/platform/rpi3/machine/src/device-init.yamlnew file mode 100755index 000000000..83bd68daf--- /dev/null+++ b/platform/rpi3/machine/src/device-init.yaml@@ -0,0 +1,11 @@+hostname: MY_HOSTNAME++# Remove/comment this block if you don't use Wifi+wifi:+ interfaces:+ wlan0:+ ssid: "MY_SSID"+ password: "MY_PASSWORD"++runcmd:+ - "sh /boot/openremote-boot.sh >> /var/log/openremote-boot.log 2>&1"diff --git a/platform/rpi3/machine/src/openremote-boot.sh b/platform/rpi3/machine/src/openremote-boot.shnew file mode 100755index 000000000..34e269dd4--- /dev/null+++ b/platform/rpi3/machine/src/openremote-boot.sh@@ -0,0 +1,45 @@+#!/bin/bash -e++if ! [ $(getent group openremote) ]; then++ echo "Creating default user 'openremote'"+ groupadd openremote+ usermod --move-home --login openremote --home /home/openremote --gid openremote pirate+ groupdel pirate+ rm /home/openremote/.bash_prompt+ rm /etc/sudoers.d/user-pirate+ echo 'openremote ALL=NOPASSWD: ALL' > /etc/sudoers.d/user-openremote++ if [ -f /boot/openremote-ssh.pub ]; then+ echo "Disabling password authentication, using provided SSH public key"+ mkdir /home/openremote/.ssh+ cp /boot/openremote-ssh.pub /home/openremote/.ssh/authorized_keys+ chown openremote:openremote /home/openremote/.ssh/authorized_keys+ sed -i 's/^#PasswordAuthentication.*/PasswordAuthentication no/g' /etc/ssh/sshd_config+ systemctl restart sshd+ rm /boot/openremote-ssh.pub+ fi++ if [ -d /boot/dockerssl ]; then+ echo "Configuring Docker SSL setup and HTTP listening socket"+ sed -i 's#^ExecStart.*#ExecStart=/usr/bin/dockerd#g' /lib/systemd/system/docker.service+ cp /boot/dockerssl/* /etc/docker/+ cat >> /etc/docker/daemon.json << EOF+{+ "hosts": ["fd://", "tcp://0.0.0.0:2376", "unix:///var/run/docker.sock"],+ "max-concurrent-downloads": 10,+ "tls": true,+ "tlscacert": "/etc/docker/ca.pem",+ "tlscert": "/etc/docker/cert.pem",+ "tlskey": "/etc/docker/key.pem",+ "tlsverify": true+}+EOF+ systemctl daemon-reload+ systemctl restart docker+ rm -r /boot/dockerssl+ fi++else+ echo "OpenRemote environment already configured!"+fi