Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker support added for the Issue #13 #59

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
dev-*/*
.git
postman-collection
30 changes: 30 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
FROM python:3.8-slim-buster@sha256:2ce8031b678a8de21815a760313707f145f69ffc80f8d411b2d5f198f47608bf as base

RUN apt-get update
RUN apt-get install curl nano -y

RUN curl -sL https://deb.nodesource.com/setup_18.x | bash
RUN apt-get install nodejs -y

RUN useradd -ms /bin/bash node
WORKDIR /home/node

EXPOSE 3000
HEALTHCHECK --interval=15s --timeout=10s --retries=2 CMD curl -f http://localhost:3000/ || exit 1

COPY --chown=node:node python-requirements.txt ./
RUN pip3 install -r python-requirements.txt

COPY --chown=node:node package*.json ./

FROM base as production
RUN npm ci --only=production
COPY --chown=node:node ./ ./
USER node
CMD ["node", "server.js"]

FROM base as development
RUN npm i -g nodemon && npm ci
COPY --chown=node:node ./ ./
USER node
CMD ["nodemon", "server.js"]
Empty file added Dotouch
Empty file.
2 changes: 1 addition & 1 deletion controllers/BookController.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { sanitizeBody } = require("express-validator");
const apiResponse = require("../helpers/apiResponse");
const auth = require("../middlewares/jwt");
var mongoose = require("mongoose");
mongoose.set("useFindAndModify", false);
// mongoose.set("useFindAndModify", false);

// Book Schema
function BookData(data) {
Expand Down
31 changes: 31 additions & 0 deletions docker-compose.development.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
version: '3.4'
services:
nodeserver:
container_name: rest-api-nodejs-mongodb
build:
context: ./
target: development
restart: unless-stopped
volumes:
- .:/home/node/
- /home/node/node_modules
ports:
- "3000:3000"
environment:
NODE_ENV: development
MONGODB_URL: mongodb://mongo:27017/rest-api-nodejs-mongodb
DEBUG: nodejs-docker-express:*
depends_on:
- mongo

mongo:
container_name: rest-api-nodejs-db
image: mongo
restart: always
logging:
options:
max-size: 1g
environment:
MONGO_INITDB_DATABASE: rest-api-nodejs-mongodb
ports:
- "27017:27017"
27 changes: 27 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
version: '3.4'
services:
nodeserver:
container_name: rest-api-nodejs-mongodb
build:
context: ./
target: production
restart: unless-stopped
volumes:
- .:/home/node/
- /home/node/node_modules
ports:
- "3000:3000"
environment:
NODE_ENV: production
DEBUG: nodejs-docker-express:*
MONGODB_URL: mongodb://mongo:27017/rest-api-nodejs-mongodb
depends_on:
- mongo

mongo:
image: mongo
restart: always
environment:
MONGO_INITDB_DATABASE: rest-api-nodejs-mongodb
ports:
- "27017:27017"
4 changes: 3 additions & 1 deletion middlewares/jwt.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ const jwt = require("express-jwt");
const secret = process.env.JWT_SECRET;

const authenticate = jwt({
secret: secret
secret: secret,
credentialsRequired: false,
algorithms: ['HS256']
});

module.exports = authenticate;
Loading