Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
9 changes: 9 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
backend
node_modules
dist
build
.gitignore
.git
.env.*
.github
yarn.lock
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Node modules
node_modules/
package-lock.json
*/yarn.lock
yarn.lock
# Logs
logs
*.log
Expand Down
44 changes: 44 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Stage 1: Build the frontend
FROM node:20-alpine AS build

# Set the working directory
WORKDIR /app

# Copy package.json
COPY package.json .

# Install production dependencies using Yarn
RUN yarn install --production
# Copy the rest of the application files
COPY . .

# Build the frontend using Yarn
RUN yarn run build

# Stage 2: Serve the application with Nginx
FROM nginx:alpine

# Copy the build output from the previous stage to Nginx's serve directory
COPY --from=build /app/dist /usr/share/nginx/html

# Remove the default Nginx configuration file
RUN rm /etc/nginx/conf.d/default.conf

# Create a new Nginx configuration file
RUN echo $'\
server { \n\
listen 3000; \n\
server_name localhost; \n\
root /usr/share/nginx/html; \n\
index index.html; \n\
\n\
location / { \n\
try_files $uri $uri/ /index.html; \n\
} \n\
}' > /etc/nginx/conf.d/default.conf

# Expose port 3000
EXPOSE 3000

# Start Nginx
CMD ["nginx", "-g", "daemon off;"]
21 changes: 21 additions & 0 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Stage 1: Build the frontend
FROM node:20-alpine

# Set the working directory
WORKDIR /app

# Copy package.json

COPY package.json .

# Install all dependencies
RUN yarn install

Comment on lines +6 to +9
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Lock-file omitted – builds will be slow and non-reproducible

Identical to the backend dev image, copy the lock-file and prefer npm ci:

-COPY package.json .
-RUN npm install
+COPY package*.json ./
+RUN npm ci
🤖 Prompt for AI Agents
In Dockerfile.dev around lines 6 to 9, the lock-file (package-lock.json or
yarn.lock) is missing, causing slow and non-reproducible builds. Copy the
lock-file into the image alongside package.json and replace `npm install` with
`npm ci` to ensure faster, consistent, and reproducible installs.

# Copy the rest of the application files
COPY . .

# Expose the port for the application
EXPOSE 3000

# Start Nginx
CMD ["yarn","dev", "--port", "3000","--host"]
5 changes: 5 additions & 0 deletions backend/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
.gitignore
.git
.env.*
yarn.lock
20 changes: 20 additions & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Use a lightweight Node.js Alpine image
FROM node:20-alpine

# Set the working directory
WORKDIR /app

# Copy package.json and yarn.lock files for dependency installation
COPY package.json ./

# Install production dependencies using Yarn
RUN yarn install --production

# Copy the rest of the application files
COPY . .

# Expose the port for the application
EXPOSE 5000

# Start the server in production mode using Yarn
CMD ["yarn", "start"]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change it to 'npm start'

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

20 changes: 20 additions & 0 deletions backend/Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Use a lightweight Node.js Alpine image
FROM node:20-alpine

# Set the working directory
WORKDIR /app

# Copy package.json and yarn.lock files for dependency installation
COPY package.json ./

# Install all dependencies using Yarn
RUN yarn install

Comment on lines +7 to +12
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Copy the lock-file and switch to npm ci for deterministic, cache-friendly installs

package-lock.json is not copied into the image, and npm install is used.
Without the lock-file Docker-layer caching breaks whenever only lock data changes, and builds are no longer reproducible.

-# Copy package.json and yarn.lock files for dependency installation
-COPY package.json ./
-
-# Install all dependencies using Yarn
-RUN npm install
+# Copy manifest + lock-file for proper layer caching
+COPY package*.json ./
+
+# Faster, deterministic install
+RUN npm ci
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# Copy package.json and yarn.lock files for dependency installation
COPY package.json ./
# Install all dependencies using Yarn
RUN npm install
# Copy manifest + lock-file for proper layer caching
COPY package*.json ./
# Faster, deterministic install
RUN npm ci
🤖 Prompt for AI Agents
In backend/Dockerfile.dev around lines 7 to 12, the Dockerfile copies only
package.json but not the package-lock.json, and uses npm install which is less
deterministic. To fix this, copy both package.json and package-lock.json into
the image, then replace npm install with npm ci to ensure deterministic,
cache-friendly installs and better Docker layer caching.

# Copy the rest of the application files
COPY . .

# Expose the port for the application
EXPOSE 5000

# Start the server in dev mode using Yarn
CMD ["yarn", "dev"]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change it to 'npm run dev'

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

3 changes: 2 additions & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"version": "1.0.0",
"main": "server.js",
"scripts": {
"start": "nodemon server.js",
"dev": "nodemon server.js",
"start": "node server.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
Expand Down
37 changes: 37 additions & 0 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
services:
frontend: # Defines the frontend service
image: frontend # Names the Docker image for the frontend service
container_name: frontend-container # Names the container for the frontend service
build:
context: . # Uses the current directory as the build context
dockerfile: Dockerfile.dev # Specifies the Dockerfile to use for building the image
ports:
- "3000:3000" # Maps port 3000 on the host machine to port 3000 in the container
env_file:
- .env # Loads environment variables from the .env file
volumes:
- .:/app # Mounts the entire project directory into the container for live code updates
- /app/node_modules # Prevents node_modules inside the container from being overwritten
depends_on:
- backend # Ensures the backend service starts before the frontend
networks:
- app-network # Connects the frontend to a custom Docker network

backend: # Defines the backend service
image: backend # Names the Docker image for the backend service
container_name: backend-container # Names the container for the backend service
build:
context: ./backend # Uses the "backend" directory as the build context
dockerfile: Dockerfile.dev # Specifies the Dockerfile to use for building the image
ports:
- "5000:5000" # Maps port 8000 on the host machine to port 8000 in the container
env_file:
- ./backend/.env # Loads environment variables from the .env file
volumes:
- ./backend:/app # Mounts the backend directory into the container for live code updates
- /app/node_modules # Prevents node_modules inside the container from being overwritten
networks:
- app-network # Connects the backend to a custom Docker network

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have one docker compose for dev and prod?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

networks:
app-network: # Defines a shared network so that containers can communicate with each other
31 changes: 31 additions & 0 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
services:
frontend:
image: frontend
container_name: frontend-container
build:
context: .
dockerfile: Dockerfile
ports:
- "3000:3000"
env_file:
- .env
depends_on:
- backend
networks:
- app-network

backend:
image: backend
container_name: backend-container
build:
context: backend
dockerfile: Dockerfile
ports:
- "5000:5000"
env_file:
- backend/.env
networks:
- app-network

networks:
app-network:
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@
"react-dom": "^18.3.1",
"react-hot-toast": "^2.4.1",
"react-icons": "^5.3.0",
"react-router-dom": "^6.28.0"
"react-router-dom": "^6.28.0",
"postcss": "^8.4.47",
"autoprefixer": "^10.4.20",
"tailwindcss": "^3.4.14"
Comment on lines +28 to +30
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Duplicate autoprefixer entry

autoprefixer now appears in both dependencies and devDependencies, causing npm/yarn warnings and a larger prod image.

@@
-    "postcss": "^8.4.47",
-    "autoprefixer": "^10.4.20",
-    "tailwindcss": "^3.4.14"
+    "postcss": "^8.4.47",
+    "tailwindcss": "^3.4.14"
@@
-    "autoprefixer": "^10.4.20",

Move it to one block (usually devDependencies for build-time CSS processing).

Also applies to: 41-41

🤖 Prompt for AI Agents
In package.json around lines 28 to 30 and line 41, the package "autoprefixer" is
listed in both dependencies and devDependencies, causing duplication warnings
and increasing production image size. Remove the "autoprefixer" entry from the
dependencies section and keep it only in devDependencies, as it is typically
used for build-time CSS processing.

},
"devDependencies": {
"@eslint/js": "^9.13.0",
Expand All @@ -30,14 +33,11 @@
"@types/react-dom": "^18.3.1",
"@types/react-redux": "^7.1.34",
"@vitejs/plugin-react-swc": "^3.5.0",
"autoprefixer": "^10.4.20",
"eslint": "^9.13.0",
"eslint-plugin-react": "^7.37.2",
"eslint-plugin-react-hooks": "^5.0.0",
"eslint-plugin-react-refresh": "^0.4.14",
"globals": "^15.11.0",
"postcss": "^8.4.47",
"tailwindcss": "^3.4.14",
"vite": "^5.4.10"
}
}