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

Added the Dockerfile #156

Merged
merged 6 commits into from
Oct 10, 2024
Merged
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
39 changes: 39 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

FROM node:18 AS frontend-build

WORKDIR /app/frontend
COPY frontend/package*.json ./

RUN npm install

COPY frontend/ ./

FROM node:18 AS backend-build

WORKDIR /app/backend
COPY backend/package*.json ./

RUN npm install

COPY backend/ ./

FROM node:18

WORKDIR /app

COPY --from=backend-build /app/backend ./backend
COPY --from=frontend-build /app/frontend ./frontend

COPY frontend/package*.json ./frontend/
COPY backend/package*.json ./backend/
RUN npm install --prefix frontend && npm install --prefix backend


COPY start.sh ./

RUN chmod +x start.sh

EXPOSE 5173 3000


CMD ["sh", "start.sh"]
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,22 @@ Make sure you follow our contributing guidlines:- [here](https://github.com/Ram
npm run dev
4. Open your browser at `http://localhost:3000` to see the project running! 🌟

Set-up using Dockerfile:-

1. **Build Docker Image**:
```bash
docker build -t playcafe .
2. **Run Docker Image**
```bash
docker run -p 5173:5173 -p 3000:3000 playcafe
3. Open your browser at `http://localhost:5173` to see the project running! 🌟

Set-up using docker-compose :-

1. **Build Docker Image and Run the Application**:
```bash
docker compose up --build

## 🤝 Contributing
We love contributions! 💙 Whether you're a participant in **GSSoC** or an open-source enthusiast, we welcome your input. Here's how you can contribute:

Expand Down
5 changes: 5 additions & 0 deletions backend/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
npm-debug.log
.git
.gitignore
README.md
47 changes: 47 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
version: '3.8'

services:
frontend:
build:
context: .
dockerfile: Dockerfile
target: frontend-build # Reference the frontend build stage
working_dir: /app/frontend
volumes:
- ./frontend:/app/frontend # Bind-mount the frontend code to support hot-reloading
ports:
- "5173:5173"
command: ["npm", "run", "dev"]
environment:
- NODE_ENV=development

backend:
build:
context: .
dockerfile: Dockerfile
target: backend-build # Reference the backend build stage
working_dir: /app/backend
volumes:
- ./backend:/app/backend # Bind-mount the backend code to support hot-reloading
ports:
- "3000:3000"
command: ["npm", "run", "dev"]
environment:
- NODE_ENV=development

full-app:
build:
context: .
dockerfile: Dockerfile
depends_on:
- frontend
- backend
ports:
- "5173:5173"
- "3000:3000"
command: ["sh", "./start.sh"]
environment:
- NODE_ENV=production
volumes:
- ./frontend:/app/frontend
- ./backend:/app/backend
Comment on lines +32 to +47
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

Inconsistent Configuration for full-app Service

The full-app service has conflicting settings that are not suitable for a production environment:

  1. Development Scripts in Production Mode:

    • The start.sh script runs npm run dev for both frontend and backend, which starts the services in development mode.
    • However, the environment variable NODE_ENV is set to production, leading to conflicting behaviors.
  2. Use of Bind Mounts:

    • Bind mounts (volumes) are utilized to sync the frontend and backend directories.
    • This setup is typical for development but poses security risks and stability issues in production.
  3. Combined Frontend and Backend Services:

    • Running both frontend and backend within the same service can hinder scalability and complicate maintenance tasks.

Recommendations:

  • Separate Services: Consider splitting the frontend and backend into distinct services to allow independent scaling and management.
  • Adjust Environment Settings: Ensure that the startup scripts correspond with the NODE_ENV. For production, use scripts that build and serve optimized versions of the applications.
  • Review Volume Usage: Remove bind mounts in the production environment to enhance security and performance.
🔗 Analysis chain

Clarify the purpose and configuration of the full-app service.

The full-app service configuration raises a few concerns:

  1. It uses bind mounts (volumes) in what appears to be a production environment (NODE_ENV=production). This is unusual and potentially risky for production deployments.
  2. The service depends on both frontend and backend services, which are configured for development. This mixing of development and production configurations in the same compose file could lead to confusion.
  3. The start.sh script is referenced but not provided in the context. Its contents and purpose are unclear.

Could you please clarify:

  1. Is this service intended for production use? If so, consider removing the volume bindings.
  2. What is the purpose of the start.sh script? Can you provide its contents?
  3. How do you intend to use this full-app service alongside the development-configured frontend and backend services?

You can check the contents of the start.sh script with:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Display the contents of start.sh if it exists
if [ -f "./start.sh" ]; then
    echo "Contents of start.sh:"
    cat ./start.sh
else
    echo "start.sh file is missing."
fi

Length of output: 150

🧰 Tools
🪛 yamllint

[error] 40-40: trailing spaces

(trailing-spaces)


[error] 41-41: trailing spaces

(trailing-spaces)

5 changes: 5 additions & 0 deletions frontend/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
npm-debug.log
.git
.gitignore
README.md
3 changes: 3 additions & 0 deletions start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

cd frontend && npm run dev &
cd backend && npm run dev
RamakrushnaBiswal marked this conversation as resolved.
Show resolved Hide resolved
Loading