first commit, working docker based node-red app instance

master
Kebler Network System Administrator 2022-07-30 07:06:57 -07:00
parent 7b402fec85
commit d930468d07
10 changed files with 123 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*.env

13
apps/example.cfg Normal file
View File

@ -0,0 +1,13 @@
#!/bin/bash
# customer container name, default is <filename>-nodered-app
# Name=containername
# Custom user, default is current user (must be in docker group)
# USER=jim # not needed if current host user is 1000
# TZ=America/Los_Angles # default
Parent_Folder=/data
# "extra-host" set broker and home assistant ips on host inside container
Broker=broker.kebler.net # will lookup ip
HomeAssistant=ha.kebler.net # will look up ip
# https://hub.docker.com/r/nodered/node-red/tags
# Tag=latest-18 # default see
Port=1881 # must be changed to avoid conflict with other node red app containers

21
docker-compose.yml Normal file
View File

@ -0,0 +1,21 @@
version: "3.7"
services:
node-red:
image: nodered/node-red:${Tag}
container_name: ${Name}
user: ${PUID}
environment:
- TZ=${TZ}
ports:
- ${Port}:1880
volumes:
- ${Data}:/data
restart: unless-stopped
extra_hosts:
- "broker:${Broker}"
- "homeassistant:${HomeAssistant}"
# networks:
# default:
# name: ${Name}

3
logs Executable file
View File

@ -0,0 +1,3 @@
#!/bin/bash
[[ ! $1 ]] && echo "no app set, usage term <nodred app>" && exit
docker attach $1-nodered-app

51
make-env-file Executable file
View File

@ -0,0 +1,51 @@
#!/bin/bash
is_p_int() { [ "$1" ] && [ -z "${1//[0-9]/}" ]; }
getip ()
{
dig +short $1 | tail -1
}
declare -A settings
# echo env $1
[[ ! $(getent group docker) ]] && echo no docker group on machine, exiting && exit
[[ ! $1 ]] && echo "no app set, usage make-env-file <app>" && exit
SDIR=$(
cd $(dirname $(readlink -f "$0")) >/dev/null 2>&1
pwd -P
)
ENV_FILE=$SDIR/apps/${1}.cfg
echo processing config file $ENV_FILE
# source any environment for particular site
# shopt -s extglob
# ENV_FILE=$(ls ${FILE}* 2> /dev/null | grep -v '.off$\|.example$\|.tmpl$\|.template$')
[[ -f $ENV_FILE ]] && source $ENV_FILE || echo WARNING no settings file $ENV_FILE, using defaults
PUID=$(id -u $USER 2>/dev/null)
[[ ! $PUID ]] && echo no user $USER, exiting && exit
[[ ! $(getent group docker | grep ${USER}) ]] && echo $USER not in docker group, exiting && exit
__ce_PUID=${PUID:-$([[ ! $(is_p_int PUID) ]] && echo $(id -u))}
__ce_PGID=${PGID:-$(getent group docker | cut -d: -f3)}
ename=${2:-$(basename "${1%.*}")}
__ce_Name=${Name:-$ename-nodered-app}
__ce_Tag=${Tag:-latest-18}
__ce_Broker=$(getip "${Broker}")
__ce_HomeAssistant=$(getip "${HomeAssistant}")
__ce_TZ=${TZ:-"America/Los_Angeles"}
Parent_Folder=${Parent_Folder:-${HOME}/.local/share}
__ce_Data=${Data:-${Parent_Folder}/node-red-apps/$ename}
mkdir -p ${__ce_Data}
# __ce_Config=${Config:-${Parent_Folder}/$ename/config}
# mkdir -p ${__ce_Config}
__ce_Port=${Port:-1880}
echo "$(
set -o posix
set | grep __ce_ | sed 's/__ce_//'
)" >$SDIR/apps/docker.$1.env
echo created $SDIR/apps/docker.$1.env
cat $SDIR/apps/docker.$1.env

5
restart Executable file
View File

@ -0,0 +1,5 @@
#!/bin/bash
[[ ! $1 ]] && echo "no app set, usage restart <nodered app>" && exit
SDIR=$(cd $(dirname $(readlink -f "$0")) >/dev/null 2>&1 ; pwd -P)
source $SDIR/stop $editor
source $SDIR/start $editor

9
start Executable file
View File

@ -0,0 +1,9 @@
#!/bin/bash
[[ ! $1 ]] && echo "no eapp set, usage start <nodred app>" && exit
SDIR=$(cd $(dirname $(readlink -f "$0")) >/dev/null 2>&1 ; pwd -P)
env_file=$SDIR/apps/docker.${1}.env
echo $env_file
[[ ! -f "$env_file" ]] && echo file does not exist && $SDIR/make-env-file $1 && echo making env file from cfg
cat $env_file
# -p for separate container instances
docker-compose -p $1 --env-file $env_file up -d

6
stop Executable file
View File

@ -0,0 +1,6 @@
#!/bin/bash
[[ ! $1 ]] && echo "no app set, usage start <nodered app>" && exit
SDIR=$(cd $(dirname $(readlink -f "$0")) >/dev/null 2>&1 ; pwd -P)
env_file=$SDIR/apps/docker.${1}.env
[[ ! -f $env_file ]] && $($SDIR/make-env-file $1)
docker-compose --env-file $SDIR/apps/docker.${1}.env down

3
term Executable file
View File

@ -0,0 +1,3 @@
#!/bin/bash
[[ ! $1 ]] && echo "no app set, usage term <nodred app>" && exit
docker exec -it $1-nodered-app /bin/bash

11
upgrade Executable file
View File

@ -0,0 +1,11 @@
#!/bin/bash
[[ ! $1 ]] && echo "no app set, usage upgrade <nodered app>" && exit
SDIR=$(cd $(dirname $(readlink -f "$0")) >/dev/null 2>&1 ; pwd -P)
env_file=$SDIR/apps/docker.${1}.env
echo $env_file
[[ ! -f "$env_file" ]] && echo file does not exist && $SDIR/make-env-file $1 && echo making env file from cfg
cat $env_file
# -p for separate container instances
docker-compose -p $1 --env-file $env_file pull
source $SDIR/restart $1