Skip to content

Commit

Permalink
Merge pull request foyzulkarim#73 from foyzulkarim/feature/dockerize-app
Browse files Browse the repository at this point in the history
Dockerize the project and run everything inside of docker
  • Loading branch information
foyzulkarim authored Aug 15, 2023
2 parents 56e0a52 + 74047e2 commit 849c6b8
Show file tree
Hide file tree
Showing 16 changed files with 230 additions and 4,189 deletions.
2 changes: 2 additions & 0 deletions client/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
build
2 changes: 2 additions & 0 deletions client/.env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
REACT_APP_API_SERVER='https://www.google.com'
REACT_APP_VIDEO_SERVER='https://www.amazon.com'
14 changes: 14 additions & 0 deletions client/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Stage 1
FROM node:18-alpine as builder
ARG REACT_APP_API_SERVER
ARG REACT_APP_VIDEO_SERVER
RUN echo "REACT_APP_VIDEO_SERVER is set to $REACT_APP_VIDEO_SERVER"

WORKDIR /app
COPY . .
RUN yarn
ENV REACT_APP_API_SERVER=$REACT_APP_API_SERVER
ENV REACT_APP_VIDEO_SERVER=$REACT_APP_VIDEO_SERVER
RUN yarn build
EXPOSE 3000
CMD [ "npx", "serve", "build" ]
14 changes: 14 additions & 0 deletions client/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: "3"

services:
client:
container_name: client-app
image: docker-mern-video-streaming-client
build:
context: .
dockerfile: Dockerfile
args:
- REACT_APP_API_SERVER=${REACT_APP_API_SERVER}
- REACT_APP_VIDEO_SERVER=${REACT_APP_VIDEO_SERVER}
ports:
- 3000:3000
4 changes: 3 additions & 1 deletion client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
"lint:fix": "eslint --fix --ext .js,.jsx ./src",
"clear-all": "rm -rf build node_modules",
"re-start": "rm -rf build node_modules && yarn install && yarn start",
"re-build": "rm -rf build node_modules && yarn install && yarn build"
"re-build": "rm -rf build node_modules && yarn install && yarn build",
"docker-build": "docker-compose build --build-arg REACT_APP_VIDEO_SERVER=http://localhost:4001 --build-arg REACT_APP_API_SERVER=http://localhost:4000",
"docker": "docker-compose up"
},
"eslintConfig": {
"extends": [
Expand Down
4 changes: 2 additions & 2 deletions client/src/constants.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export const API_SERVER = "http://localhost:4000";
export const VIDEO_SERVER = "http://localhost:4001";
export const API_SERVER = process.env.REACT_APP_API_SERVER || "http://localhost:4000";
export const VIDEO_SERVER = process.env.REACT_APP_VIDEO_SERVER || "http://localhost:4001";
1 change: 1 addition & 0 deletions server/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
8 changes: 8 additions & 0 deletions server/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM node:18-alpine
WORKDIR /app
ADD package*.json ./
RUN npm install
COPY . .
EXPOSE 4000
EXPOSE 4001
CMD [ "npm", "start"]
29 changes: 29 additions & 0 deletions server/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,32 @@ services:
image: redis
ports:
- 6379:6379
networks:
- backend
mongo:
image: mongo
ports:
- 27017:27017
networks:
- backend
api:
image: app
build: .
volumes:
- ./src:/app/src
- ./uploads:/app/uploads
depends_on:
- mongo
- redis
networks:
- backend
ports:
- "4000:4000"
- "4001:4001"
environment:
- MONGODB_URL=mongodb://mongo:27017
- REDIS_SERVER=redis
- SERVER_URL=http://localhost:4000
networks:
backend:
driver: bridge
Loading

0 comments on commit 849c6b8

Please sign in to comment.