Skip to content

Commit 5e3fbc3

Browse files
committed
add docker file
1 parent 8c25670 commit 5e3fbc3

File tree

10 files changed

+128
-20
lines changed

10 files changed

+128
-20
lines changed

.dockerignore

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Add any directories, files, or patterns you don't want to be tracked by version control
2+
.idea
3+
4+
# ignore vs code project config files
5+
.vscode
6+
.vs
7+
8+
# ignore logs
9+
/logs
10+
*.log
11+
12+
# ignore 3rd party lib
13+
/node_modules
14+
15+
# Ignore built files
16+
build/**/*
17+
18+
# ignore test converage
19+
/coverage
20+
21+
# git
22+
.gitignore
23+
.git
24+
25+
.DS_Store

.env.example

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,20 @@ CORS_URL=*
1212
# Databse
1313
DB_NAME=YOUR_MONGO_DB_NAME
1414
#localhost or IP of the server
15-
DB_HOST=YOUR_MONGO_DB_HOST_NAME
15+
# If using the docker installation then use 'mongo' for host name else localhost or ip or db server
16+
DB_HOST=YOUR_MONGO_DB_HOST_NAME
1617
DB_PORT=27017
1718
DB_USER=YOUR_MONGO_DB_USER_NAME
18-
DB_PWD=YOUR_MONGO_DB_USER_PWD
19+
DB_USER_PWD=YOUR_MONGO_DB_USER_PWD
1920

20-
#Log
21-
#Example '/Users/janisharali/logs'
22-
#DEFAUlT is this project's directory
23-
LOG_DIR=YOUR_DIRECTORY_PATH_FOR_LOG_FILES
21+
# Admin when using Docker
22+
DB_ADMIN=admin
23+
DB_ADMIN_PWD=changeit
24+
25+
# Log
26+
# Example '/home/node/logs'
27+
# DEFAUlT is this project's directory
28+
# LOG_DIR=YOUR_DIRECTORY_PATH_FOR_LOG_FILES
2429

2530
# Token Info
2631
ACCESS_TOKEN_VALIDITY_DAYS=30

.gitignore

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@
1212
# ignore 3rd party lib
1313
/node_modules
1414

15-
# ignore vs code project config files
16-
/config.js
17-
/config.json
18-
1915
# ignore key
2016
*.pem
2117

Dockerfile

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Here we are getting our node as Base image
2+
FROM node:latest
3+
4+
# create user in the docker image
5+
USER node
6+
7+
# Creating a new directory for app files and setting path in the container
8+
RUN mkdir -p /home/node/app && chown -R node:node /home/node/app
9+
10+
# setting working directory in the container
11+
WORKDIR /home/node/app
12+
13+
# grant permission of node project directory to node user
14+
COPY --chown=node:node . .
15+
16+
# installing the dependencies into the container
17+
RUN npm install
18+
19+
# container exposed network port number
20+
EXPOSE 3000
21+
22+
# command to run within the container
23+
CMD [ "npm", "start" ]

docker-compose.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
version: '3'
2+
3+
services:
4+
app:
5+
# This defines the configuration options, including the context and dockerfile,
6+
# that will be applied when Compose builds the application image.
7+
build:
8+
# This defines the build context for the image build — in this case, the current project directory.
9+
context: .
10+
# This specifies the Dockerfile in your current project directory as the file
11+
dockerfile: Dockerfile
12+
image: app
13+
container_name: app
14+
# This defines the restart policy. The default is no,
15+
# but we have set the container to restart unless it is stopped.
16+
restart: unless-stopped
17+
env_file: .env
18+
ports:
19+
# This maps port from .env on the host to same port number on the container.
20+
- "3000:$PORT"
21+
links:
22+
- mongo
23+
volumes:
24+
# This is a bind mount that mounts our application code on the host to the /home/node/app directory on the container.
25+
# Any changes you make to your host code will be populated immediately in the container.
26+
- ./:/home/node/app
27+
28+
29+
mongo:
30+
# To create this service, Compose will pull the mongo
31+
image: mongo:latest
32+
container_name: mongo
33+
restart: unless-stopped
34+
# This tells Compose that we would like to add environment variables
35+
# from a file called .env, located in our build context.
36+
env_file: .env
37+
environment:
38+
# MONGO_INITDB_ROOT_USERNAME and MONGO_INITDB_ROOT_PASSWORD together create
39+
# a root user in the admin authentication database and ensure that authentication is enabled
40+
# when the container starts. We have set MONGO_INITDB_ROOT_USERNAME and MONGO_INITDB_ROOT_PASSWORD
41+
# using the values from our .env file, which we pass to the db service using the env_file option.
42+
- MONGO_INITDB_ROOT_USERNAME=$DB_ADMIN
43+
- MONGO_INITDB_ROOT_PASSWORD=$DB_ADMIN_PWD
44+
ports:
45+
- "27017:27017"
46+
volumes:
47+
# The named volume dbdata will persist the data stored in Mongo’s default data directory, /data/db.
48+
# This will ensure that you don’t lose data in cases where you stop or remove containers.
49+
- dbdata:/data/db
50+
51+
# Our top-level volumes key defines the volumes dbdata.
52+
# When Docker creates volumes, the contents of the volume are stored in a part of the host filesystem, /var/lib/docker/volumes/, that’s managed by Docker.
53+
# The contents of each volume are stored in a directory under /var/lib/docker/volumes/ and get mounted to any container that uses the volume.
54+
# In this way, the data that our users will create will persist in the dbdata volume even if we remove and recreate the db container.
55+
volumes:
56+
dbdata:

package-lock.json

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99
"build": "npm run build-ts",
1010
"watch": "concurrently -k -p \"[{name}]\" -n \"TypeScript,Node\" -c \"yellow.bold,cyan.bold,green.bold\" \"npm run watch-ts\" \"npm run watch-node\"",
1111
"watch-node": "nodemon -r dotenv/config build/server.js",
12-
"build-ts": "tsc",
13-
"watch-ts": "tsc -w",
12+
"build-ts": "npm run tsc",
13+
"watch-ts": "npm run tsc -w",
1414
"tslint": "tslint -c tslint.json -p tsconfig.json",
15-
"test": "jest --forceExit --detectOpenHandles --coverage --verbose"
15+
"test": "jest --forceExit --detectOpenHandles --coverage --verbose",
16+
"tsc": "./node_modules/typescript/bin/tsc"
1617
},
1718
"repository": {
1819
"type": "git",
@@ -31,6 +32,7 @@
3132
"jsonwebtoken": "^8.5.1",
3233
"lodash": "^4.17.15",
3334
"mongoose": "^5.9.5",
35+
"typescript": "^3.8.3",
3436
"winston": "^3.2.1",
3537
"winston-daily-rotate-file": "^4.4.2"
3638
},
@@ -56,7 +58,6 @@
5658
"supertest": "^4.0.2",
5759
"ts-jest": "^25.2.1",
5860
"ts-node": "^8.8.1",
59-
"tslint": "^6.1.0",
60-
"typescript": "^3.8.3"
61+
"tslint": "^6.1.0"
6162
}
6263
}

src/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export const db = {
77
host: process.env.DB_HOST,
88
port: process.env.DB_PORT,
99
user: process.env.DB_USER,
10-
password: process.env.DB_PWD,
10+
password: process.env.DB_USER_PWD,
1111
};
1212

1313
export const corsUrl = process.env.CORS_URL;

src/database/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ const options = {
2222
Logger.debug(dbURI);
2323

2424
// Create the database connection
25-
mongoose.connect(dbURI, options);
25+
mongoose.connect(dbURI, options).catch(e => {
26+
Logger.info('Mongoose connection error');
27+
Logger.error(e);
28+
});
2629

2730
// CONNECTION EVENTS
2831
// When successfully connected

src/routes/v1/access/logout.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import express from 'express';
2-
import KeystoreRepo from '../../../database/Repository/KeystoreRepo';
2+
import KeystoreRepo from '../../../database/repository/KeystoreRepo';
33
import { ProtectedRequest } from 'app-request';
44
import { SuccessMsgResponse } from '../../../core/ApiResponse';
55
import asyncHandler from '../../../helpers/asyncHandler';

0 commit comments

Comments
 (0)