diff --git a/Dockerfile b/Dockerfile index e358f3e..2cb0b21 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,23 +1,9 @@ -FROM node:lts-alpine +FROM n8nio/n8n:latest -# pass N8N_VERSION Argument while building or use default - -ARG N8N_VERSION=1.9.3 - -# Update everything and install needed dependencies -RUN apk add --update graphicsmagick tzdata - -# Set a custom user to not have n8n run as root USER root -# Install n8n and the also temporary all the packages -# it needs to build it correctly. -RUN apk --update add --virtual build-dependencies python3 build-base git && \ - npm_config_user=root npm install --location=global n8n@${N8N_VERSION} && \ - apk del build-dependencies - -# Specifying work directory -WORKDIR /data +WORKDIR /home/node/packages/cli +ENTRYPOINT [] # copy start script to container COPY ./start.sh / diff --git a/README.md b/README.md index 2fb058d..833679c 100644 --- a/README.md +++ b/README.md @@ -6,112 +6,18 @@ #### [ Open Source Contributors feel free to maintain this repository ] -New method, just click, configure and get your n8n running. -Also, now set app stack to container and simply connect this Github repo and deploy, heroku uses default configuration from app.json +A new method, just click, configure, and get your n8n running. +Also, now set the app stack to container and simply connect this Github repo and deploy, Heroku uses default configuration from app.json -default basic auth is user:pass +This deployment supports queue mode with Heroku worker and Redis for scaleability. ### n8n(Nodemation) - Free and Open Workflow Automation Tool -This is a [Heroku](https://heroku.com/) focused container implementation for the [n8n Automation Tool](https://n8n.io/). Just connect your fork to heroku and let it work as a charm! +This is a [Heroku](https://heroku.com/) focused container implementation for the [n8n Automation Tool](https://n8n.io/). Just connect your fork to Heroku and let it work as a charm! ## Requirements * Heroku CLI -## Setup - -this is old setup guide not required now, connect this GitHub repo to heroku to autoconfigure. or click the above button to deploy without GitHub. - -### STEP 1: CHANGE your App Stack to container -you can change your app's stack using heroku cli, make sure you have heroku cli installed. - -#### login into heroku account - heroku login - -#### change app stack - heroku stack:set contaner --app APP_NAME -replace APP_NAME with your heroku app name - -### STEP 2: ADD Config Vars for enabling basic authentication (Optional) -It's recommended that you enable basic authentication when deployingn n8n on web. You need to set the following Environment Variables(Config Vars) in your App settings. - - N8N_BASIC_AUTH_ACTIVE=true - N8N_BASIC_AUTH_USER=SET_USERNAME - N8N_BASIC_AUTH_PASSWORD=SET_PASSWORD - -Using filesystem/sqlite as storage will destroy any workflows on new builds/releases it it recommended to use mongodb or postgreSQL as the drivers are built into the code. - - DB_TYPE=mongodb - DB_MONGODB_CONNECTION_URL=mongodb://MONGODB_USERNAME:MONGODB_PASSWORD@HOST:PORT/MONGODB_DATABASE - -you will get the connection string in the heroku mongodb addon or any service you choose. using heroku addons is recommended as they auto configure ENV Variables for you. just copy MONGODB_URI to DB_MONGODB_CONNECTION_URL. that's it. - -Same process is to be followed for using postgreSQL. - - DB_TYPE=postgresdb - DB_POSTGRESDB_HOST=POSTGRES_HOST - DB_POSTGRESDB_PORT=POSTGRES_PORT - DB_POSTGRESDB_DATABASE=POSTGRES_DB - DB_POSTGRESDB_USER=POSTGRES_USER - DB_POSTGRESDB_PASSWORD=POSTGRES_PASSWORD - -If some of your triggers depend on published app domain you may need to explicitly set url for yours n8n instance - - WEBHOOK_URL=https://your-app.herokuapp.com - - -### STEP 3: DONE! Now CONNECT GitHub repo and Deploy. - -## Using Container Registry - -you can also deploy this project using container registry (requires aditional requirements installed). Just clone/download this repository on your local machine. - -### Additional Requirements (for building on local) -* docker -* docker-compose - -### Steps -cd into your project directory - - cd n8n-heroku/ - -login into heroku account - - heroku login - -create heroku app - - heroku create APP_NAME - -change app stack - - heroku stack:set container --app APP_NAME - -set config vars(optional) - - heroku config:set N8N_BASIC_AUTH_ACTIVE=true - heroku config:set N8N_BASIC_AUTH_USER=SET_USERNAME - heroku config:set N8N_BASIC_AUTH_PASSWORD=SET_PASSWORD - -Login the container - - heroku container:login - -build and push container image to heroku - - heroku container:push web --app APP_NAME - -release new build - - heroku container:release web --app APP_NAME - -
- -Maybe now you can specify which N8N version to install by Setting a Environment Variable N8N_VERSION or with a build time argument of the same. Not tested yet though, create an issue if it does't work. CI is passing so it is working correctly with default values. - -_Update - To set n8n version you can pass a argument when deploying using container registry_ - - heroku container:push web --arg N8N_VERSION=0.60.0 --app APP_NAME ### Sources diff --git a/app.json b/app.json index 3a4a4ba..fa827af 100644 --- a/app.json +++ b/app.json @@ -8,40 +8,32 @@ "success_url": "/", "stack": "container", "env": { - "N8N_BASIC_AUTH_ACTIVE": { - "description": "Protect n8n setup with basic authentication.", - "value": "true" - }, "GENERIC_TIMEZONE": { "description": "Time Zone to use with Heroku. You can find the name of your timezone here: https://momentjs.com/timezone/", "value": "Europe/Berlin" }, - "N8N_BASIC_AUTH_USER": { - "description": "Basic Authentication User for n8n", - "value": "user" - }, - "N8N_BASIC_AUTH_PASSWORD": { - "description": "Basic Authentication Password to secure n8n.", - "value": "pass" - }, "N8N_ENCRYPTION_KEY": { "description": "This is to set the n8n encryption key to a static value, so that heroku doesnt override it, causing AUTH to fail", - "value": "MdRRn2jiZuVeh5tI77A6" + "value": "change-me-to-something-else" }, "PGSSLMODE": { "description": "Heroku made a change so SSL is required to connect to Postgres", - "value": "require" + "value": "no-verify" + }, + "DB_POSTGRESDB_SSL_ENABLED": { + "description": "Introduced since n8n@1.11.1 to connect to Postgres with SSL.", + "value": "true" }, "NODE_TLS_REJECT_UNAUTHORIZED": { - "description": "Because Heroku SSL is self signed, SSL fails if this is not set to 0", - "value": 0 + "description": "Heroku SSL is self signed, SSL fails if this is not set to 0", + "value": "0" }, "WEBHOOK_URL": { "description": "Your app could be published to any domain, without specifying n8n will think that it's hosted on localhost (and it could break some scenarions ", "value": "https://.herokuapp.com" }, "EXECUTIONS_MODE": { - "description": "This is to set the n8n executions mode to queue mode, recommended to be used with Postgres or MySQL", + "description": "Supports: regular, queue. Queue Mode enables Worker Dyno to process events. If you do not plan on using worker dyno, set worker dyno count to 0 and set execution mode it to regular.", "value": "queue" } }, diff --git a/heroku.yml b/heroku.yml index a7f1083..cd8e30f 100644 --- a/heroku.yml +++ b/heroku.yml @@ -5,11 +5,6 @@ setup: - plan: heroku-redis as: REDIS - config: - N8N_BASIC_AUTH_ACTIVE: true - N8N_BASIC_AUTH_USER: user - N8N_BASIC_AUTH_PASSWORD: pass - build: docker: web: Dockerfile diff --git a/start.sh b/start.sh index 3b0ebbf..1c09a76 100644 --- a/start.sh +++ b/start.sh @@ -8,58 +8,19 @@ 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'#") } -# received url as argument -ARG_URL=${1:-""} - -# override if config vars detected -if [ "$DATABASE_URL" ] -then - ARG_URL=$DATABASE_URL - echo $DATABASE_URL; - echo "postgres config detected" - -elif [ "$MONGODB_URI" ] -then - ARG_URL=$MONGODB_URI - echo "mongo config detected" - -else - echo "no config vars found" -fi - -# disable diagnostics -export N8N_DIAGNOSTICS_ENABLED=false - # prefix variables to avoid conflicts and run parse url function on arg url -PREFIX="N8N_DB_" parse_url "$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')" -# DB switch -if [ $N8N_DB_SCHEME == 'postgres' ] -then - echo "indentified DB in use postgreSQL" - 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 - -elif [ $N8N_DB_SCHEME == 'mongodb' ] -then - echo "indentified DB in use mongoDB" - export DB_TYPE=mongodb - export DB_MONGODB_CONNECTION_URL=$ARG_URL - -else - echo "invalid url arg" -fi +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 # parse REDIS_URL if present if [ "$REDIS_URL" ] diff --git a/worker/Dockerfile b/worker/Dockerfile index e358f3e..2cb0b21 100644 --- a/worker/Dockerfile +++ b/worker/Dockerfile @@ -1,23 +1,9 @@ -FROM node:lts-alpine +FROM n8nio/n8n:latest -# pass N8N_VERSION Argument while building or use default - -ARG N8N_VERSION=1.9.3 - -# Update everything and install needed dependencies -RUN apk add --update graphicsmagick tzdata - -# Set a custom user to not have n8n run as root USER root -# Install n8n and the also temporary all the packages -# it needs to build it correctly. -RUN apk --update add --virtual build-dependencies python3 build-base git && \ - npm_config_user=root npm install --location=global n8n@${N8N_VERSION} && \ - apk del build-dependencies - -# Specifying work directory -WORKDIR /data +WORKDIR /home/node/packages/cli +ENTRYPOINT [] # copy start script to container COPY ./start.sh / diff --git a/worker/start.sh b/worker/start.sh index 8b498ca..f691f43 100644 --- a/worker/start.sh +++ b/worker/start.sh @@ -8,55 +8,19 @@ 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'#") } -# received url as argument -ARG_URL=${1:-""} - -# override if config vars detected -if [ "$DATABASE_URL" ] -then - ARG_URL=$DATABASE_URL - echo "postgres config detected" - -elif [ "$MONGODB_URI" ] -then - ARG_URL=$MONGODB_URI - echo "mongo config detected" - -else - echo "no config vars found" -fi - -# disable diagnostics -export N8N_DIAGNOSTICS_ENABLED=false - # prefix variables to avoid conflicts and run parse url function on arg url -PREFIX="N8N_DB_" parse_url "$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')" -# DB switch -if [ $N8N_DB_SCHEME == 'postgres' ] -then - echo "indentified DB in use postgreSQL" - 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 - -elif [ $N8N_DB_SCHEME == 'mongodb' ] -then - echo "indentified DB in use mongoDB" - export DB_TYPE=mongodb - export DB_MONGODB_CONNECTION_URL=$ARG_URL - -else - echo "invalid url arg" -fi +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 # parse REDIS_URL if present if [ "$REDIS_URL" ]