From 61f37062cbe8592f973d03a8f768755d68a091fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Thu, 15 Jun 2017 10:56:30 -0500 Subject: [PATCH 01/16] Update Dockerfile to be based on the standard NodeJS image --- Dockerfile | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index c2cb68fe..0f759e57 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,8 @@ -FROM centos -RUN curl --silent --location https://rpm.nodesource.com/setup_7.x | bash - -RUN yum install -y git make gcc nodejs ImageMagick && yum clean all +FROM node:8.1 + COPY . /app WORKDIR /app/ -ENV NODE_ENV production +ENV NODE_ENV docker RUN npm install --no-progress --production && npm install --no-progress passport-ldapjs EXPOSE 3000 -CMD ["/usr/bin/node", "index.js"] \ No newline at end of file +CMD ["node", "index.js"] \ No newline at end of file From 82a1aec72a8c356f23089eecea1c87f54dbd0dbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Thu, 15 Jun 2017 11:20:56 -0500 Subject: [PATCH 02/16] Add docker.toml with configs compatible with docker-compose --- config/docker.toml | 186 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 186 insertions(+) create mode 100644 config/docker.toml diff --git a/config/docker.toml b/config/docker.toml new file mode 100644 index 00000000..38a76107 --- /dev/null +++ b/config/docker.toml @@ -0,0 +1,186 @@ +# This file is the default config file for Mailtrain. To use a environment specific +# configuration add new file {ENV}.{ext} (eg. "production.toml") to the same folder. +# {ENV} is defined by NODE_ENV environment variable. +# +# Do not modify this file directly, otherwise you might lose your modifications when upgrading +# +# You should only define the options you want to change in your additional config file. +# For example if the only thing you want to change is the port number for the www server +# then your additional config file should look like this: +# # production.toml +# [www] +# port=80 +# or if you want to use Javascript instead of TOML then the same file could look like this: +# // production.js +# module.exports = { +# www: { +# port: 80 +# } +# }; + +# Process title visible in monitoring logs and process listing +title="mailtrain" + +# Enabled HTML editors +editors=[ + ["summernote", "Summernote"], + ["grapejs", "GrapeJS"], + ["mosaico", "Mosaico"], + ["codeeditor", "Code Editor"] +] + +# Default language to use +language="en" + +# Inject custom styles in layout.hbs +# customstyles=["/custom/hello-world.css"] + +# Inject custom scripts in layout.hbs +# customscripts=["/custom/hello-world.js"] + +# Inject custom scripts in subscription/layout.mjml.hbs +# customsubscriptionscripts=["/custom/hello-world.js"] + +# If you start out as a root user (eg. if you want to use ports lower than 1000) +# then you can downgrade the user once all services are up and running +#user="mailtrain" +#group="mailtrain" + +# If Mailtrain is started as root, "Reports" feature drops the privileges of script generating the report to disallow +# any modifications of Mailtrain code and even prohibits reading the production configuration (which contains the MySQL +# password for read/write operations). The rouser/rogroup determines the user to be used +#rouser="nobody" +#rogroup="nogroup" + +[log] +# silly|verbose|info|http|warn|error|silent +level="verbose" + +[www] +# HTTP port to listen on +port=3000 +# HTTP interface to listen on +host="0.0.0.0" +# Secret for signing the session ID cookie +secret="a cat" +# Session length in seconds when "remember me" is checked +remember=2592000 # 30 days +# logger interface for expressjs morgan +log="dev" +# Is the server behind a proxy? true/false +# Set this to true if you are serving Mailtrain as a virtual domain through Nginx or Apache +proxy=false +# maximum POST body size +postsize="2MB" +# Uncomment to set uploads folder location for temporary data. Defaults to os.tmpdir() +# If the service is started by `npm start` then os.tmpdir() points to CWD +#tmpdir="/tmp" + +[mysql] +host="mysql" +user="mailtrain" +password="mailtrain" +database="mailtrain" +# Some installations, eg. MAMP can use a different port (8889) +# MAMP users should also turn on "Allow network access to MySQL" otherwise MySQL might not be accessible +port=3306 +charset="utf8mb4" +timezone="local" + +[redis] +# enable to use Redis session cache or disable if Redis is not installed +enabled=true +host="redis" +port=6379 +db=5 +# Uncomment if your Redis installation requires a password +#password="" + +[verp] +# Enable to start an MX server that detects bounced messages using VERP +# In most cases you do not want to use it +# Requires root privileges +enabled=false +port=2525 +host="0.0.0.0" +# With DMARC, the Return-Path and From address must match the same domain. +# By default we get around this by using the VERP address in the Sender header, +# with the side effect that some email clients diplay an ugly "on behalf of" message. +# You can safely disable this Sender header if you're not using DMARC or your +# VERP hostname is in the same domain as the From address. +# disablesenderheader=true + +[ldap] +# enable to use ldap user backend +enabled=false +host="localhost" +port=3002 +baseDN="ou=users,dc=company" +filter="(|(username={{username}})(mail={{username}}))" +#Username field in LDAP (uid/cn/username) +uidTag="username" +passwordresetlink="" + +[postfixbounce] +# Enable to allow writing Postfix bounce log to Mailtrain listener +# If enabled, tail mail.log to Mailtrain with the following command: +# tail -f -n +0 /var/log/mail.log | nc localhost 5699 - +enabled=false +port=5699 +# allow connections from localhost only +host="127.0.0.1" + +# extra options for nodemailer +[nodemailer] +#textEncoding="base64" + +[queue] +# How many parallel sender processes to spawn +# You can use more than 1 process only if you have Redis enabled +processes=1 + +[cors] +# Allow subscription widgets to be embedded +# origins=['https://www.example.com'] + +[mosaico] +# Installed templates +templates=[["versafix-1", "Versafix One"]] +# Inject custom scripts +# customscripts=["/mosaico/custom/my-mosaico-plugin.js"] + +[grapejs] +# Installed templates +templates=[ + ["demo", "HTML Template"], + ["aves", "MJML Template"] +] + +[reports] +# The whole reporting functionality can be disabled below if the they are not needed and the DB cannot be +# properly protected. +# Reports rely on custom user defined Javascript snippets defined in the report template. The snippets are run on the +# server when generating a report. As these snippets are stored in the DB, they pose a security risk because they can +# help gaining access to the server if the DB cannot +# be properly protected (e.g. if it is shared with another application with security weaknesses). +# Mailtrain mitigates this problem by running the custom Javascript snippets in a chrooted environment and under a +# DB user that cannot modify the database (see userRO in [mysql] above). However the chrooted environment is available +# only if Mailtrain is started as root. The chrooted environment still does not prevent the custom JS script in +# performing network operations and in generating XSS attacks as part of the report. +# The bottom line is that if people who are creating report templates or have write access to the DB cannot be trusted, +# then it's safer to switch off the reporting functionality below. +enabled=false + +[testserver] +# Starts a vanity server that redirects all mail to /dev/null +# Mostly needed for local development +enabled=false +port=5587 +mailboxserverport=3001 +host="0.0.0.0" +username="testuser" +password="testpass" +logger=false + +[seleniumwebdriver] +browser="phantomjs" From ca096d191fd6982d52dd50bdfbe9bd7a3b93b7da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Thu, 15 Jun 2017 11:21:22 -0500 Subject: [PATCH 03/16] Add base docker-compose and override to build image and set ports --- docker-compose.override.yml | 8 ++++++++ docker-compose.yml | 29 +++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 docker-compose.override.yml create mode 100644 docker-compose.yml diff --git a/docker-compose.override.yml b/docker-compose.override.yml new file mode 100644 index 00000000..19ac21da --- /dev/null +++ b/docker-compose.override.yml @@ -0,0 +1,8 @@ +version: '2' +services: + mailtrain: + build: ./ + # volumes: + # - ./:/app + ports: + - "3000:3000" \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..2c57a566 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,29 @@ +version: '2' +services: + mysql: + image: mysql:5.7 + environment: + - MYSQL_ROOT_PASSWORD=mailtrain + - MYSQL_DATABASE=mailtrain + - MYSQL_USER=mailtrain + - MYSQL_PASSWORD=mailtrain + volumes: + - mailtrain-mysq-data:/var/lib/mysql + redis: + image: redis:3.0 + volumes: + - mailtrain-redis-data:/data + mailtrain: + image: mailtrain:1.24 + depends_on: + - mysql + - redis + volumes: + - mailtrain-node-config:/app/config + - mailtrain-node-data:/app/public/grapejs/uploads + - mailtrain-node-data:/app/public/mosaico/uploads +volumes: + mailtrain-mysq-data: {} + mailtrain-redis-data: {} + mailtrain-node-data: {} + mailtrain-node-config: {} From 2cf2cc71ffef65594e82513ca0c5699a07f62a2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Thu, 15 Jun 2017 12:59:42 -0500 Subject: [PATCH 04/16] Update mailtrain tag name --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 2c57a566..fe82724f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -14,7 +14,7 @@ services: volumes: - mailtrain-redis-data:/data mailtrain: - image: mailtrain:1.24 + image: mailtrain:latest depends_on: - mysql - redis From 274c706f02f592428aeb6c13109cf46b41560e76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Thu, 15 Jun 2017 13:00:00 -0500 Subject: [PATCH 05/16] Add restart: always to docker-compose.override.yml --- docker-compose.override.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/docker-compose.override.yml b/docker-compose.override.yml index 19ac21da..24b48ec6 100644 --- a/docker-compose.override.yml +++ b/docker-compose.override.yml @@ -1,8 +1,14 @@ version: '2' services: + mysql: + restart: always + redis: + restart: always mailtrain: build: ./ # volumes: # - ./:/app ports: - - "3000:3000" \ No newline at end of file + - "3000:3000" + restart: always + \ No newline at end of file From 5e5e5c70bf227a9559acecfa5d3f179b8c5c811b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Thu, 15 Jun 2017 13:00:17 -0500 Subject: [PATCH 06/16] Update README to include new docker-compose instructions --- README.md | 80 ++++++++----------------------------------------------- 1 file changed, 11 insertions(+), 69 deletions(-) diff --git a/README.md b/README.md index 87fd2aea..7018101c 100644 --- a/README.md +++ b/README.md @@ -121,76 +121,18 @@ With proper SPF, DKIM and PTR records (DMARC wouldn't hurt either) I got perfect ### Simple Install (Docker) ##### Requirements: - * Docker - * docker-compose + * [Docker](https://www.docker.com/) + * [Docker Compose](https://docs.docker.com/compose/) - 1. Download Mailtrain files using git: `git clone git://github.com/Mailtrain-org/mailtrain.git` (or download [zipped repo](https://github.com/Mailtrain-org/mailtrain/archive/master.zip)) and open Mailtrain folder `cd mailtrain` - 2. Run `sudo docker build -t mailtrain-node:latest .` - 3. Copy default.toml to production.toml. Run `sudo mkdir -p /etc/mailtrain && sudo cp config/default.toml /etc/mailtrain/production.toml` - 4. Create `/etc/docker-compose.yml`. Example (dont forget change MYSQL_ROOT_PASS and MYSQL_USER_PASSWORD to your passwords): - ``` - version: '2' - services: - mailtrain-mysql: - image: mysql:latest - ports: - - "3306:3306" - container_name: "mailtrain-mysql" - restart: always - environment: - MYSQL_ROOT_PASSWORD: "MYSQL_ROOT_PASS" - MYSQL_DATABASE: "mailtrain" - MYSQL_USER: "mailtrain" - MYSQL_PASSWORD: "MYSQL_USER_PASSWORD" - volumes: - - mailtrain-mysq-data:/var/lib/mysql - - mailtrain-redis: - image: redis:3.0 - container_name: "mailtrain-redis" - volumes: - - mailtrain-redis-data:/data - - mailtrain-node: - image: mailtrain-node:latest - container_name: "mailtrain-node" - links: - - "mailtrain-mysql:mailtrain-mysql" - - "mailtrain-redis:mailtrain-redis" - ports: - - "3000:3000" - volumes: - - "/etc/mailtrain/production.toml:/app/config/production.toml" - - "mailtrain-node-data:/app/public/grapejs/uploads" - - "mailtrain-node-data:/app/public/mosaico/uploads" - volumes: - mailtrain-mysq-data: {} - mailtrain-redis-data: {} - mailtrain-node-data: {} - - ``` - 5. Update MySQL and Redis credintial in `/etc/mailtrain/production.toml` like this: - ``` - [mysql] - host="mailtrain-mysql" - user="mailtrain" - password="MYSQL_USER_PASSWORD" - database="mailtrain" - port=3306 - charset="utf8mb4" - timezone="UTC" - - [redis] - enabled=true - host="mailtrain-redis" - port=6379 - db=5 - ``` - 6. Run docker container with command `sudo docker-compose -f /etc/docker-compose.yml up -d` - 7. Open [http://localhost:3000/](http://localhost:3000/) - 8. Authenticate as `admin`:`test` - 9. Navigate to [http://localhost:3000/settings](http://localhost:3000/settings) and update service configuration - 10. Navigate to [http://localhost:3000/users/account](http://localhost:3000/users/account) and update user information and password + * Download Mailtrain files using git: `git clone git://github.com/Mailtrain-org/mailtrain.git` (or download [zipped repo](https://github.com/Mailtrain-org/mailtrain/archive/master.zip)) and open Mailtrain folder `cd mailtrain` + * **Note**: depending on how you have configured your system and Docker you may need to prepend the commands below with `sudo`. + * Bring up the stack with: `docker-compose up -d`, by default it will use the included `docker-compose.yml` file and override some configurations taken from the `docker-compose.override.yml` file. + * You might want to modify the `docker-compose.yml` or `docker-compose.override.yml` file, modify port mappings, change volume paths, etc. + * If you want to use only / copy the `docker-compose.yml` file (for example, if you were deploying with Rancher), you may need to first run `docker-compose build` to make sure your system has a Docker image `mailtrain:latest`. + * Open [http://localhost:3000/](http://localhost:3000/) (change the host name `localhost` to the name of the host where you are deploying the system). + * Authenticate as `admin`:`test` + * Navigate to [http://localhost:3000/settings](http://localhost:3000/settings) and update service configuration. + * Navigate to [http://localhost:3000/users/account](http://localhost:3000/users/account) and update user information and password. ### Manual Install (any OS that supports Node.js) From 1ff46768111e94a61dad24d0f2a7e56ba6234f15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Sat, 24 Jun 2017 18:14:54 -0500 Subject: [PATCH 07/16] Update Docker config template --- config/docker-production.toml.tmpl | 9 ++ config/docker.toml | 186 ----------------------------- 2 files changed, 9 insertions(+), 186 deletions(-) create mode 100644 config/docker-production.toml.tmpl delete mode 100644 config/docker.toml diff --git a/config/docker-production.toml.tmpl b/config/docker-production.toml.tmpl new file mode 100644 index 00000000..ca832181 --- /dev/null +++ b/config/docker-production.toml.tmpl @@ -0,0 +1,9 @@ +[mysql] +host="mysql" + +[redis] +enabled=true +host="redis" + +[reports] +enabled=true \ No newline at end of file diff --git a/config/docker.toml b/config/docker.toml deleted file mode 100644 index 38a76107..00000000 --- a/config/docker.toml +++ /dev/null @@ -1,186 +0,0 @@ -# This file is the default config file for Mailtrain. To use a environment specific -# configuration add new file {ENV}.{ext} (eg. "production.toml") to the same folder. -# {ENV} is defined by NODE_ENV environment variable. -# -# Do not modify this file directly, otherwise you might lose your modifications when upgrading -# -# You should only define the options you want to change in your additional config file. -# For example if the only thing you want to change is the port number for the www server -# then your additional config file should look like this: -# # production.toml -# [www] -# port=80 -# or if you want to use Javascript instead of TOML then the same file could look like this: -# // production.js -# module.exports = { -# www: { -# port: 80 -# } -# }; - -# Process title visible in monitoring logs and process listing -title="mailtrain" - -# Enabled HTML editors -editors=[ - ["summernote", "Summernote"], - ["grapejs", "GrapeJS"], - ["mosaico", "Mosaico"], - ["codeeditor", "Code Editor"] -] - -# Default language to use -language="en" - -# Inject custom styles in layout.hbs -# customstyles=["/custom/hello-world.css"] - -# Inject custom scripts in layout.hbs -# customscripts=["/custom/hello-world.js"] - -# Inject custom scripts in subscription/layout.mjml.hbs -# customsubscriptionscripts=["/custom/hello-world.js"] - -# If you start out as a root user (eg. if you want to use ports lower than 1000) -# then you can downgrade the user once all services are up and running -#user="mailtrain" -#group="mailtrain" - -# If Mailtrain is started as root, "Reports" feature drops the privileges of script generating the report to disallow -# any modifications of Mailtrain code and even prohibits reading the production configuration (which contains the MySQL -# password for read/write operations). The rouser/rogroup determines the user to be used -#rouser="nobody" -#rogroup="nogroup" - -[log] -# silly|verbose|info|http|warn|error|silent -level="verbose" - -[www] -# HTTP port to listen on -port=3000 -# HTTP interface to listen on -host="0.0.0.0" -# Secret for signing the session ID cookie -secret="a cat" -# Session length in seconds when "remember me" is checked -remember=2592000 # 30 days -# logger interface for expressjs morgan -log="dev" -# Is the server behind a proxy? true/false -# Set this to true if you are serving Mailtrain as a virtual domain through Nginx or Apache -proxy=false -# maximum POST body size -postsize="2MB" -# Uncomment to set uploads folder location for temporary data. Defaults to os.tmpdir() -# If the service is started by `npm start` then os.tmpdir() points to CWD -#tmpdir="/tmp" - -[mysql] -host="mysql" -user="mailtrain" -password="mailtrain" -database="mailtrain" -# Some installations, eg. MAMP can use a different port (8889) -# MAMP users should also turn on "Allow network access to MySQL" otherwise MySQL might not be accessible -port=3306 -charset="utf8mb4" -timezone="local" - -[redis] -# enable to use Redis session cache or disable if Redis is not installed -enabled=true -host="redis" -port=6379 -db=5 -# Uncomment if your Redis installation requires a password -#password="" - -[verp] -# Enable to start an MX server that detects bounced messages using VERP -# In most cases you do not want to use it -# Requires root privileges -enabled=false -port=2525 -host="0.0.0.0" -# With DMARC, the Return-Path and From address must match the same domain. -# By default we get around this by using the VERP address in the Sender header, -# with the side effect that some email clients diplay an ugly "on behalf of" message. -# You can safely disable this Sender header if you're not using DMARC or your -# VERP hostname is in the same domain as the From address. -# disablesenderheader=true - -[ldap] -# enable to use ldap user backend -enabled=false -host="localhost" -port=3002 -baseDN="ou=users,dc=company" -filter="(|(username={{username}})(mail={{username}}))" -#Username field in LDAP (uid/cn/username) -uidTag="username" -passwordresetlink="" - -[postfixbounce] -# Enable to allow writing Postfix bounce log to Mailtrain listener -# If enabled, tail mail.log to Mailtrain with the following command: -# tail -f -n +0 /var/log/mail.log | nc localhost 5699 - -enabled=false -port=5699 -# allow connections from localhost only -host="127.0.0.1" - -# extra options for nodemailer -[nodemailer] -#textEncoding="base64" - -[queue] -# How many parallel sender processes to spawn -# You can use more than 1 process only if you have Redis enabled -processes=1 - -[cors] -# Allow subscription widgets to be embedded -# origins=['https://www.example.com'] - -[mosaico] -# Installed templates -templates=[["versafix-1", "Versafix One"]] -# Inject custom scripts -# customscripts=["/mosaico/custom/my-mosaico-plugin.js"] - -[grapejs] -# Installed templates -templates=[ - ["demo", "HTML Template"], - ["aves", "MJML Template"] -] - -[reports] -# The whole reporting functionality can be disabled below if the they are not needed and the DB cannot be -# properly protected. -# Reports rely on custom user defined Javascript snippets defined in the report template. The snippets are run on the -# server when generating a report. As these snippets are stored in the DB, they pose a security risk because they can -# help gaining access to the server if the DB cannot -# be properly protected (e.g. if it is shared with another application with security weaknesses). -# Mailtrain mitigates this problem by running the custom Javascript snippets in a chrooted environment and under a -# DB user that cannot modify the database (see userRO in [mysql] above). However the chrooted environment is available -# only if Mailtrain is started as root. The chrooted environment still does not prevent the custom JS script in -# performing network operations and in generating XSS attacks as part of the report. -# The bottom line is that if people who are creating report templates or have write access to the DB cannot be trusted, -# then it's safer to switch off the reporting functionality below. -enabled=false - -[testserver] -# Starts a vanity server that redirects all mail to /dev/null -# Mostly needed for local development -enabled=false -port=5587 -mailboxserverport=3001 -host="0.0.0.0" -username="testuser" -password="testpass" -logger=false - -[seleniumwebdriver] -browser="phantomjs" From f142175917fcc0954de100838f9dd44eecf984f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Sat, 24 Jun 2017 18:15:52 -0500 Subject: [PATCH 08/16] Add entrypoint that copies production configs --- docker-entrypoint.sh | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 docker-entrypoint.sh diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100644 index 00000000..e6df2530 --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,12 @@ +#!/bin/bash +set -e + +if [ ! -f "/app/config/production.toml" ] ; then + echo "No production.toml, copying from docker-production.toml.tmpl" + cp /app/config/docker-production.toml.tmpl /app/config/production.toml +fi +if [ ! -f "/app/workers/reports/config/production.toml" ] ; then + echo "No production.toml for reports, copying from docker-production.toml.tmpl" + cp /app/config/docker-production.toml.tmpl /app/workers/reports/config/production.toml +fi +exec "$@" \ No newline at end of file From 54f65c506e491ca9cd1ef8a29e7b949a84fcf3a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Sat, 24 Jun 2017 18:17:00 -0500 Subject: [PATCH 09/16] Update Dockerfile, order installs, NODE_ENV, add entrypoint --- Dockerfile | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 0f759e57..6d2c3228 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,13 @@ FROM node:8.1 -COPY . /app +# First install dependencies +COPY ./package.json ./app/ WORKDIR /app/ -ENV NODE_ENV docker +ENV NODE_ENV production RUN npm install --no-progress --production && npm install --no-progress passport-ldapjs +# Later, copy the app files. That improves development speed as buiding the Docker image will not have +# to download and install all the NPM dependencies every time there's a change in the source code +COPY . /app EXPOSE 3000 +ENTRYPOINT ["/app/docker-entrypoint.sh"] CMD ["node", "index.js"] \ No newline at end of file From 31565f4cab6c84ad1fc52567cd0588b8873d26fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Sat, 24 Jun 2017 18:17:34 -0500 Subject: [PATCH 10/16] Add node_modules to .dockerignore to avoid unneeded building time / overhead --- .dockerignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..b512c09d --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +node_modules \ No newline at end of file From fb6b98a6184ab9719543fdf9f2e39defc61be0d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Sat, 24 Jun 2017 18:20:15 -0500 Subject: [PATCH 11/16] Make docker-compose.override.yml a template --- docker-compose.override.yml => docker-compose.override.yml.tmpl | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename docker-compose.override.yml => docker-compose.override.yml.tmpl (100%) diff --git a/docker-compose.override.yml b/docker-compose.override.yml.tmpl similarity index 100% rename from docker-compose.override.yml rename to docker-compose.override.yml.tmpl From 5229f6edaf99e974c35ef0f41340b1a324d14240 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Sat, 24 Jun 2017 18:22:38 -0500 Subject: [PATCH 12/16] Add volume for reports --- docker-compose.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docker-compose.yml b/docker-compose.yml index fe82724f..ba00757e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -22,8 +22,10 @@ services: - mailtrain-node-config:/app/config - mailtrain-node-data:/app/public/grapejs/uploads - mailtrain-node-data:/app/public/mosaico/uploads + - mailtrain-node-reports:/app/protected/reports volumes: mailtrain-mysq-data: {} mailtrain-redis-data: {} mailtrain-node-data: {} mailtrain-node-config: {} + mailtrain-node-reports: {} From fb3d37cfc0cf8ed8382ec7e0f8ba1081a5322b14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Sat, 24 Jun 2017 18:31:57 -0500 Subject: [PATCH 13/16] Update README --- README.md | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 7018101c..60726293 100644 --- a/README.md +++ b/README.md @@ -120,20 +120,25 @@ If you are using the bundled ZoneMTA then you should make sure you are using a p With proper SPF, DKIM and PTR records (DMARC wouldn't hurt either) I got perfect 10/10 score out from [MailTester](https://www.mail-tester.com/) when sending a campaign message to a MailTester test address. I did not have VERP turned on, so the sender address matched return path address. ### Simple Install (Docker) -##### Requirements: - * [Docker](https://www.docker.com/) - * [Docker Compose](https://docs.docker.com/compose/) +#### Requirements: - * Download Mailtrain files using git: `git clone git://github.com/Mailtrain-org/mailtrain.git` (or download [zipped repo](https://github.com/Mailtrain-org/mailtrain/archive/master.zip)) and open Mailtrain folder `cd mailtrain` - * **Note**: depending on how you have configured your system and Docker you may need to prepend the commands below with `sudo`. - * Bring up the stack with: `docker-compose up -d`, by default it will use the included `docker-compose.yml` file and override some configurations taken from the `docker-compose.override.yml` file. - * You might want to modify the `docker-compose.yml` or `docker-compose.override.yml` file, modify port mappings, change volume paths, etc. - * If you want to use only / copy the `docker-compose.yml` file (for example, if you were deploying with Rancher), you may need to first run `docker-compose build` to make sure your system has a Docker image `mailtrain:latest`. - * Open [http://localhost:3000/](http://localhost:3000/) (change the host name `localhost` to the name of the host where you are deploying the system). - * Authenticate as `admin`:`test` - * Navigate to [http://localhost:3000/settings](http://localhost:3000/settings) and update service configuration. - * Navigate to [http://localhost:3000/users/account](http://localhost:3000/users/account) and update user information and password. + * [Docker](https://www.docker.com/) + * [Docker Compose](https://docs.docker.com/compose/) +#### Install: + +* Download Mailtrain files using git: `git clone git://github.com/Mailtrain-org/mailtrain.git` (or download [zipped repo](https://github.com/Mailtrain-org/mailtrain/archive/master.zip)) and open Mailtrain folder `cd mailtrain` +* **Note**: depending on how you have configured your system and Docker you may need to prepend the commands below with `sudo`. +* Copy the file `docker-compose.override.yml.tmpl` to `docker-compose.override.yml.tmpl` and modify it if you need to. +* Bring up the stack with: `docker-compose up -d`, by default it will use the included `docker-compose.yml` file and override some configurations taken from the `docker-compose.override.yml` file. +* If you want to use only / copy the `docker-compose.yml` file (for example, if you were deploying with Rancher), you may need to first run `docker-compose build` to make sure your system has a Docker image `mailtrain:latest`. +* Open [http://localhost:3000/](http://localhost:3000/) (change the host name `localhost` to the name of the host where you are deploying the system). +* Authenticate as user `admin` with password `test` +* Navigate to [http://localhost:3000/settings](http://localhost:3000/settings) and update service configuration. +* Navigate to [http://localhost:3000/users/account](http://localhost:3000/users/account) and update user information and password. + +**Note**: If you need to add or modify custom configurations, copy the file `config/docker-production.toml.tmpl` to `config/production.toml` and modify as you need. By default, the Docker image will do just that, automatically, so you can bring up the stack and it will work with default configurations. + ### Manual Install (any OS that supports Node.js) From 58f607ffc4bdfd52b486be09a98b052bcf089ddd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Sat, 24 Jun 2017 18:32:29 -0500 Subject: [PATCH 14/16] Add to .gitignore files that should not be commited --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index 590e00cc..9ab19ae8 100644 --- a/.gitignore +++ b/.gitignore @@ -27,3 +27,7 @@ public/grapejs/uploads/* public/grapejs/templates/* !public/grapejs/templates/demo !public/grapejs/templates/aves + +config/production.toml +workers/reports/config/production.toml +docker-compose.override.yml \ No newline at end of file From 8d56f0763e776074dc6680876386071594c2a90e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Sat, 24 Jun 2017 18:49:35 -0500 Subject: [PATCH 15/16] Use production.toml for reports when it exists in config --- docker-entrypoint.sh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index e6df2530..00101596 100644 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -6,7 +6,13 @@ if [ ! -f "/app/config/production.toml" ] ; then cp /app/config/docker-production.toml.tmpl /app/config/production.toml fi if [ ! -f "/app/workers/reports/config/production.toml" ] ; then - echo "No production.toml for reports, copying from docker-production.toml.tmpl" - cp /app/config/docker-production.toml.tmpl /app/workers/reports/config/production.toml + echo "No production.toml for reports" + if [ -f "/app/config/production.toml" ] ; then + echo "copying config/production.toml to reports config directory" + cp /app/config/production.toml /app/workers/reports/config/production.toml + else + echo "copying config/docker-production.toml.tmpl to reports config directory as production.toml" + cp /app/config/docker-production.toml.tmpl /app/workers/reports/config/production.toml + fi fi exec "$@" \ No newline at end of file From ead3dbbfb353ebb44d7518d1c27c496537344ce4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Sat, 24 Jun 2017 19:40:43 -0500 Subject: [PATCH 16/16] Update Dockerfile to avoid file system permission issues --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 6d2c3228..80ae090c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,5 +9,5 @@ RUN npm install --no-progress --production && npm install --no-progress passport # to download and install all the NPM dependencies every time there's a change in the source code COPY . /app EXPOSE 3000 -ENTRYPOINT ["/app/docker-entrypoint.sh"] +ENTRYPOINT ["bash", "/app/docker-entrypoint.sh"] CMD ["node", "index.js"] \ No newline at end of file