From ea46224bdc6824f9a2d70870f07a6da01e15fb8a Mon Sep 17 00:00:00 2001 From: default Date: Wed, 31 Jan 2024 18:06:44 +0100 Subject: [PATCH] new:[n8n] add charm --- n8n/README.org | 30 ++++++++++++++++++++ n8n/hooks/init | 31 +++++++++++++++++++++ n8n/hooks/postgres_database-relation-joined | 22 +++++++++++++++ n8n/hooks/smtp_server-relation-joined | 20 +++++++++++++ n8n/metadata.yml | 30 ++++++++++++++++++++ 5 files changed, 133 insertions(+) create mode 100644 n8n/README.org create mode 100755 n8n/hooks/init create mode 100755 n8n/hooks/postgres_database-relation-joined create mode 100755 n8n/hooks/smtp_server-relation-joined create mode 100644 n8n/metadata.yml diff --git a/n8n/README.org b/n8n/README.org new file mode 100644 index 0000000..ff02abd --- /dev/null +++ b/n8n/README.org @@ -0,0 +1,30 @@ +# -*- ispell-local-dictionary: "english" -*- + +* Info + +From: https://docs.n8n.io/hosting/installation/docker/#starting-n8n + + +* Usage + +Config info: https://support.rallly.co/self-hosting/configuration-options + +Requires a =smtp-server= provider to be functional, you can use +=smtp-stub= charm to provide information to externally managed =SMTP=. + +#+begin_src yaml +n8n: + options: + sender-email: #the sender email (beware the conf of your SMTP server) + +smtp-stub: + options: + host: smtp.myhost.com + port: 465 + connection-security: "ssl/tls" + auth-method: password #IMPORTANT: if not present login password doesn’t work + login: myuser + password: myp4ssw0rd +#+end_src + + diff --git a/n8n/hooks/init b/n8n/hooks/init new file mode 100755 index 0000000..2a22346 --- /dev/null +++ b/n8n/hooks/init @@ -0,0 +1,31 @@ +#!/bin/bash + +## Init is run on host +## For now it is run every time the script is launched, but +## it should be launched only once after build. + +## Accessible variables are: +## - SERVICE_NAME Name of current service +## - DOCKER_BASE_IMAGE Base image from which this service might be built if any +## - SERVICE_DATASTORE Location on host of the DATASTORE of this service +## - SERVICE_CONFIGSTORE Location on host of the CONFIGSTORE of this service + + +set -e + +sender=$(options-get sender-email) || exit 1 + +init-config-add " +$SERVICE_NAME: + volumes: + - $SERVICE_DATASTORE/.n8n:/home/node/.n8n + environment: + N8N_SMTP_SENDER: \"$sender\" + GENERIC_TIMEZONE: "Europe/Paris" + TZ: "Europe/Paris" +" + +uid=$(docker_get_uid "$SERVICE_NAME" "node") +mkdir -p "$SERVICE_DATASTORE/.n8n" +chown "$uid" "$SERVICE_DATASTORE/.n8n" + diff --git a/n8n/hooks/postgres_database-relation-joined b/n8n/hooks/postgres_database-relation-joined new file mode 100755 index 0000000..f21d586 --- /dev/null +++ b/n8n/hooks/postgres_database-relation-joined @@ -0,0 +1,22 @@ +#!/bin/bash + +set -e + +PASSWORD="$(relation-get password)" +USER="$(relation-get user)" +DBNAME="$(relation-get dbname)" + + +config-add "\ +services: + $MASTER_BASE_SERVICE_NAME: + environment: + DB_TYPE: postgresdb + DB_POSTGRESDB_HOST: $TARGET_SERVICE_NAME + DB_POSTGRESDB_PORT: 5432 + DB_POSTGRESDB_DATABASE: $DBNAME + DB_POSTGRESDB_USER: $USER + DB_POSTGRESDB_PASSWORD: $PASSWORD +" + +info "Configured $SERVICE_NAME code for $TARGET_SERVICE_NAME access." diff --git a/n8n/hooks/smtp_server-relation-joined b/n8n/hooks/smtp_server-relation-joined new file mode 100755 index 0000000..58406fa --- /dev/null +++ b/n8n/hooks/smtp_server-relation-joined @@ -0,0 +1,20 @@ +#!/bin/bash + +set -e + +host=$(relation-get host) || exit 1 +port=$(relation-get port) || exit 1 +user=$(relation-get login) || exit 1 +password="$(relation-get password)" || exit 1 + + +config-add "\ +services: + $MASTER_BASE_SERVICE_NAME: + environment: + N8N_SMTP_USER: \"$user\" + N8N_SMTP_PASS: \"${password//\$/\$\$}\" + N8N_SMTP_HOST: \"$host\" + N8N_SMTP_PORT: \"$port\" +" + diff --git a/n8n/metadata.yml b/n8n/metadata.yml new file mode 100644 index 0000000..f9f3575 --- /dev/null +++ b/n8n/metadata.yml @@ -0,0 +1,30 @@ +docker-image: docker.n8n.io/n8nio/n8n:1.23.0 + +uses: + postgres-database: + #constraint: required | recommended | optional + #auto: pair | summon | none ## default: pair + constraint: required + auto: summon + solves: + database: "main storage" + smtp-server: + constraint: required + auto: summon + solves: + proxy: "Public access" + web-proxy: + #constraint: required | recommended | optional + #auto: pair | summon | none ## default: pair + constraint: recommended + auto: pair + solves: + proxy: "Public access" + default-options: + target: !var-expand ${MASTER_BASE_SERVICE_NAME}:5678 + backup: + constraint: recommended + auto: pair + solves: + backup: "Automatic regular backup" + default-options: