Skip to content

Commit

Permalink
Dockerize the application
Browse files Browse the repository at this point in the history
  • Loading branch information
SalmanAd01 committed Nov 3, 2022
1 parent 25c1248 commit c9efe7e
Show file tree
Hide file tree
Showing 10 changed files with 175 additions and 1 deletion.
1 change: 1 addition & 0 deletions .adminjs/bundle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!function(){"use strict";AdminJS.UserComponents={}}();
23 changes: 23 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
**/.classpath
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/charts
**/docker-compose*
**/compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
README.md
11 changes: 11 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"configurations": [
{
"name": "Docker Node.js Launch",
"type": "docker",
"request": "launch",
"preLaunchTask": "docker-run: debug",
"platform": "node"
}
]
}
39 changes: 39 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"version": "2.0.0",
"tasks": [
{
"type": "docker-build",
"label": "docker-build",
"platform": "node",
"dockerBuild": {
"dockerfile": "${workspaceFolder}/Dockerfile",
"context": "${workspaceFolder}",
"pull": true
}
},
{
"type": "docker-run",
"label": "docker-run: release",
"dependsOn": [
"docker-build"
],
"platform": "node"
},
{
"type": "docker-run",
"label": "docker-run: debug",
"dependsOn": [
"docker-build"
],
"dockerRun": {
"env": {
"DEBUG": "*",
"NODE_ENV": "development"
}
},
"node": {
"enableDebugging": true
}
}
]
}
11 changes: 11 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM node:16-alpine
WORKDIR /app
ARG NODE_ENV
COPY ["package.json", "package-lock.json*", "npm-shrinkwrap.json*", "yarn.lock","./"]
RUN npm i yarn
RUN if ["$NODE_ENV" = "development"]; then yarn install; else yarn install --production; fi
COPY . .
EXPOSE 5000
RUN chown -R node /app
USER node
CMD ["yarn", "start"]
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,22 @@
```
yarn run dev
```


<h4>Commands To Spin Docker Container</h4>

```
docker compose up
```

<h4>For Development</h4>

```
docker compose -f .\docker-compose-dev.yml up
```

<h4>Remove cache and build</h4>

```
docker compose up --build --remove-orphans --force-recreate
```
28 changes: 28 additions & 0 deletions docker-compose-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
version: '3.4'

services:
mongo:
image: mongo:latest
restart: always
ports:
- 27017:27017
volumes:
- mongo-data:/data/db
backend:
build:
context: .
dockerfile: ./Dockerfile
environment:
NODE_ENV: development
env_file:
- .env
ports:
- 5000:5000
depends_on:
- mongo
volumes:
- .:/app
- /app/node_modules
command: yarn run dev
volumes:
mongo-data:
14 changes: 14 additions & 0 deletions docker-compose.debug.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: '3.4'

services:
backend:
image: backend
build:
context: .
dockerfile: ./Dockerfile
environment:
NODE_ENV: development
ports:
- 5000:5000
- 9229:9229
command: ["node", "--inspect=0.0.0.0:9229", "server.js"]
28 changes: 28 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
version: '3.4'

services:
mongo:
image: mongo:latest
restart: always
ports:
- 27017:27017
volumes:
- mongo-data:/data/db
backend:
build:
context: .
dockerfile: ./Dockerfile
environment:
NODE_ENV: production
env_file:
- .env
ports:
- 5000:5000
depends_on:
- mongo
volumes:
- .:/app
- /app/node_modules
command: yarn run start
volumes:
mongo-data:
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"license": "MIT",
"scripts": {
"start": "node server.js",
"dev": "nodemon server.js -e js,html,hbs",
"dev": "nodemon --legacy-watch server.js -e js,html,hbs",
"lint": "eslint --plugin markdown --ext js,md .",
"fix": "eslint --fix --plugin markdown --ext js,md .",
"prepare": "husky install"
Expand Down

0 comments on commit c9efe7e

Please sign in to comment.