Last couple of days I found this gem on the web: https://github.com/n8n-io/n8n it's like Zapier, but self hosted and open source. And for most jobs you have its enough.  

Into

Why use a Service like n8n or Zapier? Well, If you're like me and you host many applications on the web you may have the need for web-hooks. Web-hooks are little callbacks, which are nowadays supported by many many applications. WordPress, Ghost Blog, Mattermost and GitLab supports them . You even can create a Webhook for your ESP8266 (with Blynk).

What happens is that Application A sends an JSON with Data from App-A, to an Webhook-URL. For example the Ghost Blog has specific trigger: publish, update and if that event happens, the Ghost Blog sends a JSON to that URL.

Thats it. It's not really complicated.

But if you just send this JSON to Mattermost, the Mattermost Application has no logic how to handle a JSON from the Ghost Blog. In this case you need a middle man.

First I thought well easy, start an Flask-App put out some Api-Endpoints, hack some lines  in Python and you're done.

But maybe you also have some other Applications that want to talk to some other Apps you run into the same problem. And this gap is filled by n8n or Zapier.

In this example you have a Webhook. If this Webhook gets calles it triggers an custom HTTP Request.

With n8n you can define Webhook URLs. Those URL then get called by your Application. You can choose which data from your JSON you want forward to the other "Node". Of course you can change the fields etc. n8n also supports a lot of authentification types, including OAuth2. This way you can talk for example directly with the Google API.

Setting up the NGINX-Proxy

I don't want to go into the details setting up your NGINX Proxy. I really like this project: https://github.com/nginx-proxy/docker-letsencrypt-nginx-proxy-companion

version: '3.1'

services:

  postgres:
    image: postgres:11
    restart: always
    environment:
      - POSTGRES_USER
      - POSTGRES_PASSWORD
      - POSTGRES_DB
      - POSTGRES_NON_ROOT_USER
      - POSTGRES_NON_ROOT_PASSWORD
    volumes:
      - ./init-data.sh:/docker-entrypoint-initdb.d/init-data.sh
    networks:
      - internal-tier

  n8n:
    image: n8nio/n8n
    restart: always
    environment:
      - DB_TYPE=postgresdb
      - DB_POSTGRESDB_HOST=postgres
      - DB_POSTGRESDB_PORT=5432
      - DB_POSTGRESDB_DATABASE=${POSTGRES_DB}
      - DB_POSTGRESDB_USER=${POSTGRES_NON_ROOT_USER}
      - DB_POSTGRESDB_PASSWORD=${POSTGRES_NON_ROOT_PASSWORD}
      - N8N_BASIC_AUTH_ACTIVE=true
      - N8N_BASIC_AUTH_USER
      - N8N_BASIC_AUTH_PASSWORD
      - N8N_PROTOCOL=http
      - N8N_PORT=8080
      - N8N_HOST=${BASE_URL}
      - WEBHOOK_TUNNEL_URL=https://${BASE_URL}/
      - VIRTUAL_HOST=${BASE_URL}
      - VIRTUAL_PORT=8080
      - VIRTUAL_PROTO=http
      - VIRTUAL_NETWORK=nginx-proxy
      - LETSENCRYPT_HOST=${BASE_URL}
      - LETSENCRYPT_EMAIL=${EMAIL}
    links:
      - postgres
    volumes:
      - /srv/docker/docker-compose/n8n:/root/.n8n
    # Wait 5 seconds to start n8n to make sure that PostgreSQL is ready
    # when n8n tries to connect to it
    command: /bin/sh -c "sleep 5; n8n start"
    expose:
      - "8080"
    networks:
      - internal-tier
      - proxy-tier
networks:
 proxy-tier:
 internal-tier:
   external:
     name: nginx-prox

I used this as a base. (https://github.com/n8n-io/n8n/tree/master/docker/compose/withPostgres)

Your .env would look something like that:

POSTGRES_USER=TO_BE_FILLED_OUT
POSTGRES_PASSWORD=TO_BE_FILLED_OUT
POSTGRES_DB=TO_BE_FILLED_OUT

POSTGRES_NON_ROOT_USER=TO_BE_FILLED_OUT
POSTGRES_NON_ROOT_PASSWORD=TO_BE_FILLED_OUT

N8N_BASIC_AUTH_USER=TO_BE_FILLED_OUT
N8N_BASIC_AUTH_PASSWORD=TO_BE_FILLED_OUT

BASE_URL=TO_BE_FILLED_OUT
EMAIL=TO_BE_FILLED_OUT

The important things:

  • don't expose ports outside, just use EXPOSE this way your docker won't open ports on host machine
  • WEBHOOK_TUNNEL is important, because n8n will generate callback urls with this string. If you don't set it: n8n will generate urls like: example.com:8080/foo but you want something like that: example.com/foo

And I didn't make my Postgres SQL persistent yet.

volumes:
  - ./postgres-data:/var/lib/postgresql/data

If you found this in anyway helpful, please like, comment share :)