diff --git a/README.md b/README.md index d8f4c51..190aa6d 100644 --- a/README.md +++ b/README.md @@ -99,6 +99,71 @@ MailMERN/ git clone https://github.com/OPCODE-Open-Spring-Fest/MailMERN.git cd MailMERN ``` + +## 🐳 Run with Docker (Recommended for Development & Testing) + +You can now easily run the entire **MailMERN** stack (Frontend + Backend + MongoDB) using **Docker Compose** — no manual setup needed! + +--- + +### 1️⃣ Prerequisites +Make sure you have these installed: +- [Docker](https://docs.docker.com/get-docker/) +- [Docker Compose](https://docs.docker.com/compose/install/) + +--- + +### 2️⃣ Setup Environment Variables +Create a `.env` file inside the `backend/` folder (if not already present): + +```env +PORT=5000 +MONGO_URI=mongodb://mongo:27017/mailmern +EMAIL_USER=your_email@example.com +EMAIL_PASS=your_app_password +OPENAI_API_KEY=your_openai_key + +SMTP_HOST=smtp.gmail.com +SMTP_PORT=587 +SMTP_SECURE=false # true for 465, false for 587 +SMTP_USER=your_email@example.com +SMTP_PASS=your_app_password +EMAIL_FROM="MailMERN no-reply@example.com" +EMAIL_TEST_TO=receiver@example.com +NODE_ENV=development +``` + +### 3️⃣ Start the Containers + +From the project root, run: + +```bash +docker-compose up --build +``` + +This will: + +🧩 Start the MongoDB container + +⚙️ Run the Express backend on port 5000 + +💻 Serve the React frontend on port 5173 + +Once started: + +Frontend: http://localhost:5173 + +Backend API: http://localhost:5000/api + +### 4️⃣ Stopping Containers + +To stop and remove all running containers, use: + +```bash +docker-compose down +``` +--- +## Individual Setup 2️⃣ Backend Setup ```bash cd backend @@ -112,6 +177,7 @@ EMAIL_USER=your_email@example.com EMAIL_PASS=your_app_password OPENAI_API_KEY=your_openai_key ``` + Run the backend: ```bash npm run dev diff --git a/backend/.dockerignore b/backend/.dockerignore new file mode 100644 index 0000000..b0e3907 --- /dev/null +++ b/backend/.dockerignore @@ -0,0 +1,3 @@ +node_modules +npm-debug.log +.DS_Store diff --git a/backend/Dockerfile b/backend/Dockerfile new file mode 100644 index 0000000..580d713 --- /dev/null +++ b/backend/Dockerfile @@ -0,0 +1,12 @@ +FROM node:22-alpine + +WORKDIR /app + +COPY package*.json ./ +RUN npm install + +COPY . . + +EXPOSE 5000 + +CMD ["npm", "run", "dev"] diff --git a/backend/src/server.js b/backend/src/server.js index c38bb8f..fec85e3 100644 --- a/backend/src/server.js +++ b/backend/src/server.js @@ -6,6 +6,7 @@ const userRoutes = require('./routes/userRoutes'); const { errorMiddleware } = require('./middlewares/errorMiddleware'); const chatbotRoutes = require('./routes/chatbotRoutes'); const emailRoutes = require('./routes/emailRoutes'); +const googleRoutes = require('./routes/googleRoute'); const trackRoutes = require('./routes/trackRoutes'); const { configDotenv } = require('dotenv'); const contactRoutes = require('./routes/contactRoutes'); diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..6d0653c --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,40 @@ +services: + mongo: + image: mongo:6 + container_name: mongo + restart: always + ports: + - "27017:27017" + volumes: + - mongo_data:/data/db + + backend: + build: ./backend + container_name: mailmern_backend + ports: + - "5000:5000" + env_file: + - ./backend/.env + depends_on: + - mongo + volumes: + - ./backend:/app + - /app/node_modules + command: npm run dev + + frontend: + build: ./frontend + container_name: mailmern_frontend + ports: + - "5173:5173" + stdin_open: true + tty: true + depends_on: + - backend + volumes: + - ./frontend:/app + - /app/node_modules + command: npm run dev + +volumes: + mongo_data: diff --git a/frontend/.dockerignore b/frontend/.dockerignore new file mode 100644 index 0000000..bd78c49 --- /dev/null +++ b/frontend/.dockerignore @@ -0,0 +1,4 @@ +node_modules +npm-debug.log +.env +.DS_Store diff --git a/frontend/Dockerfile b/frontend/Dockerfile new file mode 100644 index 0000000..afe9867 --- /dev/null +++ b/frontend/Dockerfile @@ -0,0 +1,12 @@ +FROM node:22-alpine + +WORKDIR /app + +COPY package*.json ./ +RUN npm install + +COPY . . + +EXPOSE 5173 + +CMD ["npm", "run", "dev"] diff --git a/frontend/package.json b/frontend/package.json index af33bb9..0500abe 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -4,7 +4,7 @@ "version": "0.0.0", "type": "module", "scripts": { - "dev": "vite", + "dev": "vite --host 0.0.0.0", "build": "vite build", "lint": "eslint .", "preview": "vite preview"