From 53c82c1e9047c62d41a50e042ee1e36b11bf2983 Mon Sep 17 00:00:00 2001 From: Thomas LEVEIL Date: Wed, 21 Aug 2019 21:56:23 +0200 Subject: [PATCH] :books: Add :whale: Docker Compose example for :elephant: PostgresQL --- docker/compose/withPostgres/.env | 6 ++++ docker/compose/withPostgres/README.md | 26 ++++++++++++++ .../compose/withPostgres/docker-compose.yml | 35 +++++++++++++++++++ docker/compose/withPostgres/init-data.sh | 12 +++++++ docker/images/n8n/README.md | 4 ++- 5 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 docker/compose/withPostgres/.env create mode 100644 docker/compose/withPostgres/README.md create mode 100644 docker/compose/withPostgres/docker-compose.yml create mode 100755 docker/compose/withPostgres/init-data.sh diff --git a/docker/compose/withPostgres/.env b/docker/compose/withPostgres/.env new file mode 100644 index 0000000000..f0d73042d4 --- /dev/null +++ b/docker/compose/withPostgres/.env @@ -0,0 +1,6 @@ +POSTGRES_USER=adminuser +POSTGRES_PASSWORD=JvsjjAYg12FJ90sdCBdsh322V +POSTGRES_DB=n8n + +POSTGRES_NON_ROOT_USER=n8nuser +POSTGRES_NON_ROOT_PASSWORD=PLsQ8vHGShwDFdmSssb diff --git a/docker/compose/withPostgres/README.md b/docker/compose/withPostgres/README.md new file mode 100644 index 0000000000..9bf36c06b7 --- /dev/null +++ b/docker/compose/withPostgres/README.md @@ -0,0 +1,26 @@ +# n8n with PostgreSQL + +Starts n8n with PostgreSQL as database. + + +## Start + +To start n8n with PostgreSQL simply start docker-compose by executing the following +command in the current folder. + + +**IMPORTANT:** But before you do that change the default users and passwords in the [`.env`](.env) file! + +``` +docker-compose up -d +``` + +To stop it execute: + +``` +docker-compose stop +``` + +## Configuration + +The default name of the database, user and password for PostgreSQL can be changed in the [`.env`](.env) file in the current directory. diff --git a/docker/compose/withPostgres/docker-compose.yml b/docker/compose/withPostgres/docker-compose.yml new file mode 100644 index 0000000000..debb2f9b52 --- /dev/null +++ b/docker/compose/withPostgres/docker-compose.yml @@ -0,0 +1,35 @@ +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 + + 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} + ports: + - 5678:5678 + links: + - postgres + volumes: + - ~/.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" diff --git a/docker/compose/withPostgres/init-data.sh b/docker/compose/withPostgres/init-data.sh new file mode 100755 index 0000000000..69a8d79e1e --- /dev/null +++ b/docker/compose/withPostgres/init-data.sh @@ -0,0 +1,12 @@ +#!/bin/bash +set -e; + + +if [ -n "${POSTGRES_NON_ROOT_USER:-}" ] && [ -n "${POSTGRES_NON_ROOT_PASSWORD:-}" ]; then + psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL + CREATE USER ${POSTGRES_NON_ROOT_USER} WITH PASSWORD '${POSTGRES_NON_ROOT_PASSWORD}'; + GRANT ALL PRIVILEGES ON DATABASE ${POSTGRES_DB} TO ${POSTGRES_NON_ROOT_USER}; + EOSQL +else + echo "SETUP INFO: No Environment variables given!" +fi diff --git a/docker/images/n8n/README.md b/docker/images/n8n/README.md index fce5936dee..255d876abf 100644 --- a/docker/images/n8n/README.md +++ b/docker/images/n8n/README.md @@ -136,14 +136,16 @@ docker run -it --rm \ -e DB_TYPE=postgresdb \ -e DB_POSTGRESDB_DATABASE= \ -e DB_POSTGRESDB_HOST= \ - -e DB_POSTGRESDB_PASSWORD= \ -e DB_POSTGRESDB_PORT= \ -e DB_POSTGRESDB_USER= \ + -e DB_POSTGRESDB_PASSWORD= \ -v ~/.n8n:/root/.n8n \ n8nio/n8n \ n8n start ``` +A full working setup with docker-compose can be found [here](../../compose/withPostgres/README.md) + ## Passing Senstive Data via File