diff --git a/README.md b/README.md index e4d5e98..fb68b97 100644 --- a/README.md +++ b/README.md @@ -23,32 +23,28 @@ The app consists of two parts: a web frontend for viewing stored mail and a SMTP 2. Install dependencies: ```sh - docker-compose run --rm --no-deps app npm install + docker-compose run --rm --no-deps pleasenospam-app npm install ``` 3. Start RethinkDB: ```sh - docker-compose up -d db + docker-compose up -d pleasenospam-db ``` 4. Start the mail server: ```sh - docker-compose up -d mail + docker-compose up -d pleasenospam-mail-server ``` 5. Start the frontend and watch for code changes: ```sh - docker-compose run app npm run watch + docker-compose run pleasenospam-app npm run watch ``` ## Deployment -1. Follow the first two development steps. +1. Configure `docker-compose.yml` with Docker options and ports to use -2. Configure `config/docker.json` with any custom setting overrides - -3. Configure `docker-compose.yml` with Docker options and ports to use - -4. Start the frontend, database and mail server: +2. Start the frontend, database and mail server: ```sh - docker-compose up + docker-compose up --build ``` diff --git a/app/Dockerfile b/app/Dockerfile new file mode 100644 index 0000000..f097949 --- /dev/null +++ b/app/Dockerfile @@ -0,0 +1,18 @@ +FROM node:11.6.0-alpine + +WORKDIR /usr/src/app + +COPY package*.json /usr/src/app/ +COPY config /usr/src/app/config/ +COPY lib /usr/src/app/lib/ +COPY controllers /usr/src/app/controllers/ +COPY public /usr/src/app/public/ +COPY models /usr/src/app/models/ +COPY views /usr/src/app/views/ +COPY app.js db.js router.js server.js /usr/src/app/ + +RUN cd /usr/src/app && npm install --only=production + +EXPOSE 80 + +CMD [ "npm", "start" ] diff --git a/config/docker.js b/config/docker.js new file mode 100644 index 0000000..d1921b6 --- /dev/null +++ b/config/docker.js @@ -0,0 +1,24 @@ +var defer = require('config/defer').deferConfig; + +module.exports = { + "app": { + "port": process.env.PLEASE_NO_SPAM_APP_PORT || 80, + "mail": { + "host": process.env.DOCKER_MAIL_HOST_NAME || "pleasenospam-mail-server", + "port": process.env.DOCKER_MAIL_HOST_PORT || 25 + } + }, + "db": { + "host": process.env.PLEASE_NO_SPAM_DOCKER_DB_NAME || "pleasenospam-db", + "port": process.env.PLEASE_NO_SPAM_DOCKER_DB_PORT || 28015 + }, + "mail": { + "hostname": process.env.PLEASE_NO_SPAM_MAIL_HOST_NAME || "pleasenospam-mail-server", + "banner": process.env.PLEASE_NO_SPAM_MAIL_BANNER || "Hi can I have some mail please?", + "domains": defer(function () { + var domains = process.env.NO_SPAM_MAIL_DOMAINS.replace(/^"(.+(?="$))"$/, '$1').split(' '); + console.log(domains); + return domains; + }) + } +} diff --git a/config/docker.json b/config/docker.json deleted file mode 100644 index b2648a4..0000000 --- a/config/docker.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "app": { - "port": 80, - "mail": { - "host": "mail" - } - }, - "db": { - "host": "db" - }, - "mail": { - "hostname": "pleasenospam.email", - "domains": [ - "pleasenospam.email", - "spamlessmail.org" - ] - } -} diff --git a/docker-compose.yml b/docker-compose.yml index db3d998..1c63bdd 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,39 +1,43 @@ -version: '2' +version: '3' services: - app: - image: node:latest - command: "npm start" - working_dir: /app - links: - - mail - - db + pleasenospam-app: + image: joebiellik/pleasenospam:1.0.0-app + restart: always + container_name: pleasenospam-app + build: + context: ./ + dockerfile: ./app/Dockerfile + depends_on: + - pleasenospam-mail-server + - pleasenospam-db environment: - NODE_ENV=docker - volumes: - - .:/app + - NO_SPAM_MAIL_DOMAINS="pleasenospam.email spamlessmail.org" ports: - "3000:80" - mail: - image: node:latest - command: "npm run mail-server" - working_dir: /app - links: - - db + pleasenospam-mail-server: + image: joebiellik/pleasenospam:1.0.0-mail-server + restart: always + container_name: pleasenospam-mail-server + build: + context: ./ + dockerfile: ./mail-server/Dockerfile + depends_on: + - pleasenospam-db environment: - NODE_ENV=docker - volumes: - - .:/app + - PLEASE_NO_SPAM_MAIL_HOST_NAME="pleasenospam.email" + - NO_SPAM_MAIL_DOMAINS="pleasenospam.email spamlessmail.org" expose: - 25 ports: - "2525:25" - db: + pleasenospam-db: image: rethinkdb:latest + restart: always + container_name: pleasenospam-db volumes: - - ./db:/data - expose: - - 28015 - ports: - - "8080:8080" - - "28015:28015" - - "28016:28016" + - pleasenospam-db:/data + +volumes: + pleasenospam-db: diff --git a/mail-server/Dockerfile b/mail-server/Dockerfile new file mode 100644 index 0000000..072f36c --- /dev/null +++ b/mail-server/Dockerfile @@ -0,0 +1,15 @@ +FROM node:11.6.0-alpine + +WORKDIR /usr/src/app + +COPY package*.json /usr/src/app/ +COPY config /usr/src/app/config/ +COPY lib /usr/src/app/lib/ +COPY models /usr/src/app/models/ +COPY mail-server.js db.js /usr/src/app/ + +RUN cd /usr/src/app && npm install --only=production + +EXPOSE 25 + +CMD [ "npm", "run", "mail-server" ]