From 340144979cf5e84abb047a891a0b908b01af3645 Mon Sep 17 00:00:00 2001 From: Hagop Jamkojian Date: Sat, 23 Nov 2019 00:51:21 +0100 Subject: [PATCH] Add docker support closes #2 --- .dockerignore | 3 +++ Dockerfile | 13 +++++++++++++ README.md | 14 ++++++++++++++ docker-compose.dev.yml | 6 ++++++ docker-compose.prod.yml | 6 ++++++ docker-compose.test.yml | 6 ++++++ docker-compose.yml | 32 ++++++++++++++++++++++++++++++++ package.json | 6 +++++- 8 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 docker-compose.dev.yml create mode 100644 docker-compose.prod.yml create mode 100644 docker-compose.test.yml create mode 100644 docker-compose.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..b99e7de9 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +node_modules +.git +.gitignore diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..bcd780e6 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,13 @@ +FROM node:12.13-alpine + +RUN mkdir -p /usr/src/node-app + +WORKDIR /usr/src/node-app + +COPY package.json yarn.lock ./ + +RUN yarn install --pure-lockfile + +COPY . . + +EXPOSE 3000 diff --git a/README.md b/README.md index 67aa7029..1bbccc5e 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,7 @@ It comes with many built-in features, such as authentication using JWT, request - **CORS**: Cross-Origin Resource-Sharing enabled using [cors](https://github.com/expressjs/cors) - **Compression**: gzip compression with [compression](https://github.com/expressjs/compression) - **CI**: continuous integration with [Travis CI](https://travis-ci.org) +- **Docker support** - **Code coverage**: using [coveralls](https://coveralls.io) - **Code quality**: with [Codacy](https://www.codacy.com) - **Git hooks**: with [husky](https://github.com/typicode/husky) and [lint-staged](https://github.com/okonet/lint-staged) @@ -84,6 +85,19 @@ yarn test:watch yarn coverage ``` +Docker: + +```bash +# run docker container in development mode +yarn docker:dev + +# run docker container in production mode +yarn docker:prod + +# run all tests in a docker container +yarn docker:test +``` + Linting: ```bash diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml new file mode 100644 index 00000000..a14d2875 --- /dev/null +++ b/docker-compose.dev.yml @@ -0,0 +1,6 @@ +version: '3' + +services: + node-app: + container_name: node-app-dev + command: yarn dev -L diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml new file mode 100644 index 00000000..d53fe527 --- /dev/null +++ b/docker-compose.prod.yml @@ -0,0 +1,6 @@ +version: '3' + +services: + node-app: + container_name: node-app-prod + command: yarn start diff --git a/docker-compose.test.yml b/docker-compose.test.yml new file mode 100644 index 00000000..e06adaff --- /dev/null +++ b/docker-compose.test.yml @@ -0,0 +1,6 @@ +version: '3' + +services: + node-app: + container_name: node-app-test + command: yarn test diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..a6ff511b --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,32 @@ +version: '3' + +services: + node-app: + build: . + image: node-app + environment: + - MONGODB_URL=mongodb://mongodb:27017/node-boilerplate + ports: + - '3000:3000' + depends_on: + - mongodb + volumes: + - .:/usr/src/node-app + networks: + - node-network + + mongodb: + image: mongo:4.2.1-bionic + ports: + - '27017:27017' + volumes: + - dbdata:/data/db + networks: + - node-network + +volumes: + dbdata: + +networks: + node-network: + driver: bridge diff --git a/package.json b/package.json index d9aa7742..2968f278 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,10 @@ "lint": "eslint .", "lint:fix": "eslint . --fix", "prettier": "prettier --check **/*.js", - "prettier:fix": "prettier --write **/*.js" + "prettier:fix": "prettier --write **/*.js", + "docker:prod": "docker-compose -f docker-compose.yml -f docker-compose.prod.yml up", + "docker:dev": "docker-compose -f docker-compose.yml -f docker-compose.dev.yml up", + "docker:test": "docker-compose -f docker-compose.yml -f docker-compose.test.yml up" }, "keywords": [ "node", @@ -37,6 +40,7 @@ "es9", "jest", "travis", + "docker", "passport", "joi", "eslint",