Skip to content

Commit 3401449

Browse files
committed
Add docker support
closes hagopj13#2
1 parent 09308c1 commit 3401449

8 files changed

+85
-1
lines changed

.dockerignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
.git
3+
.gitignore

Dockerfile

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM node:12.13-alpine
2+
3+
RUN mkdir -p /usr/src/node-app
4+
5+
WORKDIR /usr/src/node-app
6+
7+
COPY package.json yarn.lock ./
8+
9+
RUN yarn install --pure-lockfile
10+
11+
COPY . .
12+
13+
EXPOSE 3000

README.md

+14
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ It comes with many built-in features, such as authentication using JWT, request
2626
- **CORS**: Cross-Origin Resource-Sharing enabled using [cors](https://github.com/expressjs/cors)
2727
- **Compression**: gzip compression with [compression](https://github.com/expressjs/compression)
2828
- **CI**: continuous integration with [Travis CI](https://travis-ci.org)
29+
- **Docker support**
2930
- **Code coverage**: using [coveralls](https://coveralls.io)
3031
- **Code quality**: with [Codacy](https://www.codacy.com)
3132
- **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
8485
yarn coverage
8586
```
8687

88+
Docker:
89+
90+
```bash
91+
# run docker container in development mode
92+
yarn docker:dev
93+
94+
# run docker container in production mode
95+
yarn docker:prod
96+
97+
# run all tests in a docker container
98+
yarn docker:test
99+
```
100+
87101
Linting:
88102

89103
```bash

docker-compose.dev.yml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
version: '3'
2+
3+
services:
4+
node-app:
5+
container_name: node-app-dev
6+
command: yarn dev -L

docker-compose.prod.yml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
version: '3'
2+
3+
services:
4+
node-app:
5+
container_name: node-app-prod
6+
command: yarn start

docker-compose.test.yml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
version: '3'
2+
3+
services:
4+
node-app:
5+
container_name: node-app-test
6+
command: yarn test

docker-compose.yml

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
version: '3'
2+
3+
services:
4+
node-app:
5+
build: .
6+
image: node-app
7+
environment:
8+
- MONGODB_URL=mongodb://mongodb:27017/node-boilerplate
9+
ports:
10+
- '3000:3000'
11+
depends_on:
12+
- mongodb
13+
volumes:
14+
- .:/usr/src/node-app
15+
networks:
16+
- node-network
17+
18+
mongodb:
19+
image: mongo:4.2.1-bionic
20+
ports:
21+
- '27017:27017'
22+
volumes:
23+
- dbdata:/data/db
24+
networks:
25+
- node-network
26+
27+
volumes:
28+
dbdata:
29+
30+
networks:
31+
node-network:
32+
driver: bridge

package.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@
1919
"lint": "eslint .",
2020
"lint:fix": "eslint . --fix",
2121
"prettier": "prettier --check **/*.js",
22-
"prettier:fix": "prettier --write **/*.js"
22+
"prettier:fix": "prettier --write **/*.js",
23+
"docker:prod": "docker-compose -f docker-compose.yml -f docker-compose.prod.yml up",
24+
"docker:dev": "docker-compose -f docker-compose.yml -f docker-compose.dev.yml up",
25+
"docker:test": "docker-compose -f docker-compose.yml -f docker-compose.test.yml up"
2326
},
2427
"keywords": [
2528
"node",
@@ -37,6 +40,7 @@
3740
"es9",
3841
"jest",
3942
"travis",
43+
"docker",
4044
"passport",
4145
"joi",
4246
"eslint",

0 commit comments

Comments
 (0)