Skip to content

Commit

Permalink
Merge pull request #41 from arnab2001/Dockerize
Browse files Browse the repository at this point in the history
Docker
  • Loading branch information
arnab2001 authored Dec 30, 2023
2 parents 1b20a72 + 71d32a1 commit e509bf1
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ npm-debug.log*
yarn-debug.log*
yarn-error.log*
readme.md

/data
# assets folder
/server/public/assets
1 change: 1 addition & 0 deletions client/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# production
/build

/package-lock.json
# misc
.DS_Store
.env.local
Expand Down
27 changes: 19 additions & 8 deletions client/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
# Use a base image with Nginx pre-installed
FROM nginx:alpine
# Build react client
FROM node:16-alpine

# Copy the built frontend files to the appropriate location in the container
COPY build/ /usr/share/nginx/html
# Working directory be app
WORKDIR /usr/src/app

# Expose the port your frontend application listens on
EXPOSE 80
COPY package*.json ./

# Set the startup command to run the Nginx server
CMD ["nginx", "-g", "daemon off;"]
### Installing dependencies

RUN npm install --silent

# copy local files to app folder
COPY . .

EXPOSE 3000

CMD ["npm","start"]

# docker build -t arnabchat2001/client .
# docker tag arnabchat2001/client arnabchat2001/client:v2
# docker run -p 3000:3000 arnabchat2001/client:v2
32 changes: 22 additions & 10 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
version: "3"
version: '3'

services:
backend:
image: backend-image
client:
build:
context: ./client
dockerfile: Dockerfile
ports:
- "3000:3000"
depends_on:
- server

server:
build:
context: ./server
dockerfile: Dockerfile
ports:
- "3001:3001"
environment:
- MONGO_URL='mongodb+srv://arnab0321:bH1Ttke9EZBmYClg@cluster0.dehf4yw.mongodb.net/?retryWrites=true&w=majority'
# Add any additional configuration or volumes as needed
MONGO_URL: "mongodb+srv://arnab0321:bH1Ttke9EZBmYClg@cluster0.dehf4yw.mongodb.net/?retryWrites=true&w=majority"
depends_on:
- mongo

frontend:
image: frontend-image
build:
context: ./client
mongo:
image: mongo
ports:
- "80:80"
- "27017:27017"
volumes:
- ./data:/data/db # You can adjust the volume mount based on your preferences

4 changes: 3 additions & 1 deletion server/.gitignore
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
node_modules
/node_modules
/.pnp
.pnp.js
**node_modules
# testing
/coverage

package-lock.json
/package-lock.json
# production
/build
/server/public
Expand Down
19 changes: 9 additions & 10 deletions server/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
FROM node:18.3.0-alpine3.14
FROM node:16.13.0

# Set the working directory inside the container
WORKDIR /app
# Create App Directory
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

# Copy package.json and package-lock.json to the container
# Install Dependencies
COPY package*.json ./

# Install dependencies
RUN npm install --f
RUN npm install --silent

# Copy the rest of the backend files to the container
# Copy app source code
COPY . .

# Expose the port your backend server listens on
# Exports
EXPOSE 3001

# Set the startup command to run your backend server
CMD ["npm", "start"]
CMD ["node","index.js"]
14 changes: 8 additions & 6 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
"version": "1.0.0",
"description": "",
"main": "index.js",
"engines": {
"node": "16.x"
},

"type": "module",
"dependencies": {
"bcrypt": "^5.1.0",
Expand All @@ -19,16 +17,20 @@
"mongoose": "^6.7.0",
"morgan": "^1.10.0",
"multer": "^1.4.5-lts.1",

"node": "v16.13.0",
"socket.io": "^4.7.2"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"test": "jest",
"start": "node index.js"
},
"keywords": [],
"author": "",

"proxy": "http://localhost:3001",
"license": "ISC"
"license": "ISC",
"devDependencies": {
"jest": "^29.7.0",
"supertest": "^6.3.3"
}
}

0 comments on commit e509bf1

Please sign in to comment.