Skip to content

Commit

Permalink
refactored nginx and n9n config variables
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrol3001 committed Nov 2, 2023
1 parent fd7bc5f commit 70e1a0f
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 84 deletions.
3 changes: 1 addition & 2 deletions n8n/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ schema:
keyfile: str
db_type: list(sqlite|postgresdb|mysqldb)
db_name: str?
db_host: url?
db_host: str?
db_port: port?
db_user: str?
db_password: str?
public_url: str?
38 changes: 38 additions & 0 deletions n8n/rootfs/etc/n8n/config.gtpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"host": "localhost",
"port": 45678,
"protocol": "http",
"path": "{{ .dummy_path }}",
"database": {
"type": "{{ .db_type }}",
"mysqldb": {
"database": "{{ .db_name }}",
"host": "{{ .db_host }}",
"port": "{{ .db_port }}",
"user": "{{ .db_user }}",
"password": "{{ .db_password }}"
},
"postgresdb": {
"database": "{{ .db_name }}",
"host": "{{ .db_host }}",
"port": "{{ .db_port }}",
"user": "{{ .db_password }}",
"password": "{{ .db_password }}"
}
},
"hiringBanner": {
"enabled": false
},
"diagnostics": {
"enabled": false
},
"versionNotifications": {
"enabled": false
},
"personalization": {
"enabled": false
},
"logs": {
"level": "{{ .log_level }}"
}
}
37 changes: 0 additions & 37 deletions n8n/rootfs/etc/n8n/config.json

This file was deleted.

3 changes: 3 additions & 0 deletions n8n/rootfs/etc/nginx/templates/direct.gtpl
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,8 @@ server {

location / {
proxy_pass http://backend;

sub_filter {{ .dummy_path }} /;
sub_filter_once off;
}
}
5 changes: 4 additions & 1 deletion n8n/rootfs/etc/nginx/templates/ingress.gtpl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
server {
listen {{ .interface }}:{{ .port }} default_server;
listen {{ .port }} default_server;

include /etc/nginx/includes/server_params.conf;
include /etc/nginx/includes/proxy_params.conf;
Expand All @@ -9,5 +9,8 @@ server {
deny all;

proxy_pass http://backend;

sub_filter {{ .dummy_path }} {{ .entry }}/;
sub_filter_once off;
}
}
52 changes: 13 additions & 39 deletions n8n/rootfs/etc/s6-overlay/s6-rc.d/init-n8n/run
Original file line number Diff line number Diff line change
Expand Up @@ -7,49 +7,23 @@

bashio::log.info "Configuring N8N..."

# Ensure configuration exists
# Ensure configuration data directory exists
if ! bashio::fs.directory_exists '/config/n8n/data'; then
mkdir -p /config/n8n/data || bashio::exit.nok "Failed to create n8n configuration directory"
fi

# Copy in template files
cp /etc/n8n/config.json /config/n8n/

# Database
if bashio::config.exists 'db_type'; then
sed -i "s/%%DB_TYPE%%/$(bashio::config 'db_type')/" "/config/n8n/config.json"
fi

if bashio::config.exists 'db_name'; then
sed -i "s/%%DB_NAME%%/$(bashio::config 'db_name')/" "/config/n8n/config.json"
fi

if bashio::config.exists 'db_host'; then
sed -i "s/%%DB_HOST%%/$(bashio::config 'db_host')/" "/config/n8n/config.json"
fi

if bashio::config.exists 'db_port'; then
sed -i "s/%%DB_PORT%%/$(bashio::config 'db_port')/" "/config/n8n/config.json"
fi

if bashio::config.exists 'db_user'; then
sed -i "s/%%DB_USER%%/$(bashio::config 'db_user')/" "/config/n8n/config.json"
fi

if bashio::config.exists 'db_password'; then
sed -i "s/%%DB_PASSWORD%%/$(bashio::config 'db_password')/" "/config/n8n/config.json"
fi

if bashio::config.exists 'public_url'; then
sed -i "s/%%PUBLIC_URL%%/"$(bashio::config 'public_url')"/" "/config/n8n/config.json"
else
sed -i "s/%%PUBLIC_URL%%/''/" "/config/n8n/config.json"
fi

# Log level
if bashio::config.exists 'log_level'; then
sed -i "s/%%LOG_LEVEL%%/$(bashio::string.lower "$(bashio::config 'log_level')")/" "/config/n8n/config.json"
fi
bashio::var.json \
dummy_path "a79a004-2514-48dc-8f9e-3a92132dab57" \
db_type "$(bashio::config 'db_type')" \
db_name "$(bashio::config 'db_name')" \
db_host "$(bashio::config 'db_host')" \
db_port "^$(bashio::config 'db_port')" \
db_user "$(bashio::config 'db_user')" \
db_password "$(bashio::config 'db_password')" \
log_level "$(bashio::string.lower "$(bashio::config 'log_level')")" \
| tempio \
-template /etc/n8n/config.gtpl \
-out /config/n8n/config.json

if [ "$(bashio::config 'log_level')" == "debug" ]; then
bashio::log.info "$(cat /config/n8n/config.json)"
Expand Down
4 changes: 3 additions & 1 deletion n8n/rootfs/etc/s6-overlay/s6-rc.d/init-nginx/run
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
bashio::log.info "Configuring NGinx..."

bashio::var.json \
interface "$(bashio::addon.ip_address)" \
dummy_path "a79a004-2514-48dc-8f9e-3a92132dab57" \
port "^$(bashio::addon.ingress_port)" \
entry "$(bashio::addon.ingress_entry)" \
| tempio \
-template /etc/nginx/templates/ingress.gtpl \
-out /etc/nginx/servers/ingress.conf
Expand All @@ -20,6 +21,7 @@ admin_port=$(bashio::addon.port 80)
if bashio::var.has_value "${admin_port}"; then
bashio::config.require.ssl
bashio::var.json \
dummy_path "a79a004-2514-48dc-8f9e-3a92132dab57" \
port "^${admin_port}" \
ssl "^$(bashio::config 'ssl')" \
certfile "$(bashio::config 'certfile')" \
Expand Down
4 changes: 0 additions & 4 deletions n8n/rootfs/etc/s6-overlay/s6-rc.d/n8n/run
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@

bashio::log.info "Starting N8N..."

admin_port=$(bashio::addon.port 80)

export N8N_PATH="locahost:$(admin_port)/"
export VUE_APP_URL_BASE_API="locahost:$(admin_port)/"
export N8N_USER_FOLDER="/config/n8n/data"
export N8N_CONFIG_FILES=/config/n8n/config.json

Expand Down

0 comments on commit 70e1a0f

Please sign in to comment.