Skip to content

Commit

Permalink
Merge pull request n8n-io#5 from n8n-io/fix/database-args
Browse files Browse the repository at this point in the history
🔧 Update to use Postgres instance and User Management
  • Loading branch information
StarfallProjects authored Jan 10, 2023
2 parents 9b158b9 + f60748e commit 1af1ffd
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 33 deletions.
8 changes: 1 addition & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ This is a [Heroku](https://heroku.com/)-focused container implementation of [n8n

Use the **Deploy to Heroku** button above to launch n8n on Heroku. When deploying, make sure to check all configuration options and adjust them to your needs. It's especially important to set `N8N_ENCRYPTION_KEY` to a random secure value.

The default credentials for basic authentication is `user:pass`, but you should change this during the initial setup.

Refer to the [Heroku n8n tutorial](https://docs.n8n.io/hosting/server-setups/heroku/) for more information.

If you have questions after trying the tutorials, check out the [forums](https://community.n8n.io/).

## Enabling user management

The default configuration enables basic auth as a fast and simple way to authenticate n8n users. If you prefer the more advanced user management functionality of n8n, add the variables from [this guide](https://docs.n8n.io/hosting/user-management/) to your [Heroku config vars](https://devcenter.heroku.com/articles/config-vars#using-the-heroku-dashboard).
If you have questions after trying the tutorials, check out the [forums](https://community.n8n.io/).
26 changes: 5 additions & 21 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,21 @@
"success_url": "/",
"stack": "container",
"env": {
"N8N_BASIC_AUTH_ACTIVE": {
"description": "Protect n8n setup with basic authentication. Change to `false` if you want to use n8n's user management functionality instead.",
"value": "true"
},
"GENERIC_TIMEZONE": {
"description": "Time Zone to use with Heroku. You can find the name of your timezone for example here: https://momentjs.com/timezone/.",
"value": "Europe/Berlin"
},
"N8N_BASIC_AUTH_USER": {
"description": "Basic Authentication User for n8n. Only required when `N8N_BASIC_AUTH_ACTIVE` is `true`.",
"value": "user"
},
"N8N_BASIC_AUTH_PASSWORD": {
"description": "Basic Authentication Password to secure n8n. Only required when `N8N_BASIC_AUTH_ACTIVE` is `true`.",
"value": "pass"
},
"N8N_ENCRYPTION_KEY": {
"description": "Set the n8n encryption key to a static value to avoid Heroku overriding it (causing authentication to fail).",
"value": "MdRRn2jiZuVeh5tI77A6"
},
"PGSSLMODE": {
"description": "SSL is required to connect to Postgres.",
"value": "require"
},
"NODE_TLS_REJECT_UNAUTHORIZED": {
"description": "Because Heroku's SSL certificate is self signed, SSL connections fail if this is not set to 0.",
"value": "0"
"value": "change-me-to-something-else"
},
"WEBHOOK_URL": {
"description": "Replace <appname> with your Heroku application name. This will ensure the correct webhook URLs are being shown in n8n.",
"value": "https://<appname>.herokuapp.com"
},
"PGSSLMODE": {
"description": "SSL is required to connect to Postgres on Heroku",
"value": "no-verify"
}
},
"formation": {
Expand Down
19 changes: 19 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,24 @@
# check if port variable is set or go with default
if [ -z ${PORT+x} ]; then echo "PORT variable not defined, leaving N8N to default port."; else export N8N_PORT="$PORT"; echo "N8N will start on '$PORT'"; fi

# regex function
parse_url() {
eval $(echo "$1" | sed -e "s#^\(\(.*\)://\)\?\(\([^:@]*\)\(:\(.*\)\)\?@\)\?\([^/?]*\)\(/\(.*\)\)\?#${PREFIX:-URL_}SCHEME='\2' ${PREFIX:-URL_}USER='\4' ${PREFIX:-URL_}PASSWORD='\6' ${PREFIX:-URL_}HOSTPORT='\7' ${PREFIX:-URL_}DATABASE='\9'#")
}

# prefix variables to avoid conflicts and run parse url function on arg url
PREFIX="N8N_DB_" parse_url "$DATABASE_URL"
echo "$N8N_DB_SCHEME://$N8N_DB_USER:$N8N_DB_PASSWORD@$N8N_DB_HOSTPORT/$N8N_DB_DATABASE"
# Separate host and port
N8N_DB_HOST="$(echo $N8N_DB_HOSTPORT | sed -e 's,:.*,,g')"
N8N_DB_PORT="$(echo $N8N_DB_HOSTPORT | sed -e 's,^.*:,:,g' -e 's,.*:\([0-9]*\).*,\1,g' -e 's,[^0-9],,g')"

export DB_TYPE=postgresdb
export DB_POSTGRESDB_HOST=$N8N_DB_HOST
export DB_POSTGRESDB_PORT=$N8N_DB_PORT
export DB_POSTGRESDB_DATABASE=$N8N_DB_DATABASE
export DB_POSTGRESDB_USER=$N8N_DB_USER
export DB_POSTGRESDB_PASSWORD=$N8N_DB_PASSWORD

# kickstart nodemation
n8n
5 changes: 0 additions & 5 deletions heroku.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@ setup:
- plan: heroku-postgresql
as: DATABASE

config:
N8N_BASIC_AUTH_ACTIVE: true
N8N_BASIC_AUTH_USER: user
N8N_BASIC_AUTH_PASSWORD: pass

build:
docker:
web: Dockerfile

0 comments on commit 1af1ffd

Please sign in to comment.