Skip to content
Open
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
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,38 @@ npm run dev

---

## Docker Deployment

To run the entire application using Docker Compose:

### Prerequisites
- Docker and Docker Compose installed
- Same environment variables as local development

### Setup
1. Copy and configure environment file:
```bash
cp server/.env.example server/.env
```
Fill in the values as described in step 3 of Local Development.

2. Build and run:
```bash
docker-compose up --build
```

3. Access the app:
- Frontend: http://localhost:3000
- Backend: http://localhost:5000
- MongoDB: localhost:27017

4. Stop the containers:
```bash
docker-compose down
```

---

## Common Issues & Troubleshooting

- CORS error in browser console:
Expand Down
6 changes: 6 additions & 0 deletions client/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node_modules
npm-debug.log
dist
.env
.git
.gitignore
22 changes: 22 additions & 0 deletions client/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Build stage
FROM node:18 AS build

ARG VITE_SOCKET_URL
ENV VITE_SOCKET_URL=$VITE_SOCKET_URL

WORKDIR /app

COPY package*.json ./
RUN npm install

COPY . .
RUN npm run build

# Production stage
FROM nginx:alpine

COPY --from=build /app/dist /usr/share/nginx/html

EXPOSE 80

CMD ["nginx", "-g", "daemon off;"]
2 changes: 1 addition & 1 deletion client/src/socket.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { io } from "socket.io-client";

const socket = io("https://guessync.onrender.com/", {
const socket = io(import.meta.env.VITE_SOCKET_URL || "https://guessync.onrender.com/", {
autoConnect: false,
reconnection: true,
reconnectionAttempts: Infinity,
Expand Down
37 changes: 37 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
version: '3.8'

services:
client:
build:
context: ./client
dockerfile: Dockerfile
args:
- VITE_SOCKET_URL=http://server:5000
ports:
- "3000:80"
depends_on:
- server

server:
build:
context: ./server
dockerfile: Dockerfile
ports:
- "5000:5000"
env_file:
- ./server/.env
environment:
- NODE_ENV=production
- MONGO_URI=mongodb://mongo:27017/guessync
depends_on:
- mongo

mongo:
image: mongo:5.0
ports:
- "27017:27017"
volumes:
- mongo_data:/data/db

volumes:
mongo_data:
5 changes: 5 additions & 0 deletions server/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
npm-debug.log
.env
.git
.gitignore
1 change: 1 addition & 0 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"main": "index.js",
"scripts": {
"dev": "nodemon server.js",
"start": "node server.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
Expand Down