Skip to content
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
40 changes: 40 additions & 0 deletions .docker/mongodb/initdb.d/01-init.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// MongoDB initialization script for Greenstagram
db = db.getSiblingDB('greenstagram');

// Create collections with initial data
db.createCollection('users');
db.createCollection('posts');
db.createCollection('challenges');
db.createCollection('badges');
db.createCollection('ecoquotes');

// Create indexes for better performance
db.users.createIndex({ "username": 1 }, { unique: true });
db.users.createIndex({ "email": 1 }, { unique: true });
db.posts.createIndex({ "createdAt": -1 });
db.posts.createIndex({ "author": 1 });
db.challenges.createIndex({ "startDate": 1, "endDate": 1 });

// Insert sample data for development
db.challenges.insertMany([
{
title: "Plant a Tree",
description: "Plant a tree in your community",
points: 100,
difficulty: "medium",
category: "environment",
startDate: new Date(),
endDate: new Date(Date.now() + 7 * 24 * 60 * 60 * 1000)
},
{
title: "Zero Waste Day",
description: "Go a full day without creating any waste",
points: 75,
difficulty: "hard",
category: "sustainability",
startDate: new Date(),
endDate: new Date(Date.now() + 7 * 24 * 60 * 60 * 1000)
}
]);

print('βœ… MongoDB initialized successfully!');
146 changes: 146 additions & 0 deletions DEVELOPMENT-DOCKER.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
# Greenstagram Development with Docker

This guide explains how to set up a local development environment for Greenstagram using Docker.

## Prerequisites

- Docker Desktop (or Docker Engine) installed
- Docker Compose
- Node.js (for local development without Docker)

## Getting Started

1. **Clone the repository** (if you haven't already):
```bash
git clone https://github.com/your-username/Greenstagram.git
cd Greenstagram
```

2. **Set up the development environment**:
```bash
./setup-dev.sh
```

3. **Start the development environment**:
```bash
docker-compose up --build
```

## Services

The development environment includes the following services:

- **Frontend**: http://localhost:3000
- **Backend API**: http://localhost:5000
- **MongoDB**: mongodb://localhost:27017
- **Redis**: redis://localhost:6379

## Development Workflow

### Running Services

- Start all services:
```bash
docker-compose up
```

- Start in detached mode:
```bash
docker-compose up -d
```

- View logs:
```bash
docker-compose logs -f
```

### Stopping Services

- Stop all services:
```bash
docker-compose down
```

- Stop and remove volumes:
```bash
docker-compose down -v
```

## Environment Variables

### Backend

Create a `.env` file in the `backend` directory with the following variables:

```env
NODE_ENV=development
PORT=5000
MONGODB_URI=mongodb://greenstagram_admin:greenstagram_password@mongodb:27017/greenstagram?authSource=admin
REDIS_URL=redis://:greenstagram_redis_pass@redis:6379
JWT_SECRET=your-super-secret-jwt-key
FRONTEND_URL=http://localhost:3000
CORS_ORIGIN=http://localhost:3000
```

### Frontend

Create a `.env` file in the `frontend` directory with the following variables:

```env
VITE_API_URL=http://localhost:5000
```

## Database Management

### MongoDB

- **Username**: `greenstagram_admin`
- **Password**: `greenstagram_password`
- **Database**: `greenstagram`

To connect to MongoDB shell:
```bash
docker exec -it greenstagram-mongodb-dev mongosh -u greenstagram_admin -p greenstagram_password --authenticationDatabase admin greenstagram
```

### Redis

- **Password**: `greenstagram_redis_pass`

To connect to Redis CLI:
```bash
docker exec -it greenstagram-redis-dev redis-cli -a greenstagram_redis_pass
```

## Troubleshooting

### Common Issues

1. **Port conflicts**:
- Ensure ports 3000, 5000, 27017, and 6379 are not in use by other services.

2. **Permission issues**:
- On Linux, you might need to run Docker commands with `sudo` or add your user to the `docker` group.

3. **Container not starting**:
- Check logs: `docker-compose logs [service_name]`
- Rebuild containers: `docker-compose up --build`

### Resetting the Environment

To completely reset the development environment:

```bash
docker-compose down -v
rm -rf .docker
./setup-dev.sh
docker-compose up --build
```

## Production Deployment

For production deployment, refer to the main [DEPLOYMENT.md](DEPLOYMENT.md) file.

## License

This project is licensed under the terms of the MIT license. See the [LICENSE](LICENSE) file for details.
120 changes: 120 additions & 0 deletions DOCKER.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
# 🐳 Docker Development Setup for Greenstagram

This document explains how to set up the complete Greenstagram development environment using Docker and Docker Compose.

## Prerequisites

- Docker Desktop installed and running
- Docker Compose (included with Docker Desktop)
- Git

## Quick Start

### Option 1: Automated Setup

Make the startup script executable
chmod +x start-dev.sh
Start the complete development environment
./start-dev.sh

### Option 2: Manual Setup

1. Copy environment files
cp backend/.env.example backend/.env
cp frontend/.env.example frontend/.env # if exists
2. Start all services
docker-compose up --build -d
3. Check service health
docker-compose ps

## Services

| Service | Port | Description |
|---------|------|-------------|
| Frontend | 3000 | React development server |
| Backend | 5000 | Node.js API server |
| MongoDB | 27017 | Database |
| Redis | 6379 | Cache & session storage |

## Default Credentials

### MongoDB
- **URL:** `mongodb://admin:password123@localhost:27017/greenstagram`
- **Username:** `admin`
- **Password:** `password123`
- **Database:** `greenstagram`

### Redis
- **URL:** `redis://:redis123@localhost:6379`
- **Password:** `redis123`

## Useful Commands

View logs for all services
docker-compose logs -f
View logs for specific service
docker-compose logs -f backend
Restart a service
docker-compose restart backend
Stop all services
docker-compose down
Complete cleanup (removes volumes)
docker-compose down -v
Rebuild and restart
docker-compose up --build --force-recreate

## Development Workflow

1. **Start Environment:** `./start-dev.sh` or `docker-compose up -d`
2. **Make Changes:** Edit code in `frontend/` or `backend/` directories
3. **View Changes:** Changes are automatically reflected (hot reload)
4. **Check Logs:** `docker-compose logs -f [service-name]`
5. **Stop Environment:** `docker-compose down`

## Troubleshooting

### Port Conflicts
If you get port conflict errors:

Check what's using the ports
lsof -i :3000
lsof -i :5000
lsof -i :27017
lsof -i :6379
Kill conflicting processes
kill -9 <PID>

### Database Issues

Reset database completely
docker-compose down -v
docker-compose up --build -d

### Permission Issues (macOS/Linux)

Fix file permissions
chmod +x start-dev.sh
sudo chown -R $(whoami) .

## Contributing

When contributing to this project:

1. Ensure Docker environment works: `./start-dev.sh`
2. Test your changes in the containerized environment
3. Update this documentation if you modify Docker configuration
4. Include Docker-related changes in your PR

## Issue Resolution

This Docker setup resolves **Issue #21**: "Containerize backend with Redis and MongoDB for easy development"

### Benefits Achieved:
βœ… Single command startup (`docker-compose up` )
βœ… Consistent development environment
βœ… Eliminates manual MongoDB/Redis setup
βœ… Version consistency across all developers
βœ… Simplified onboarding for new contributors

### Hacktoberfest 2025 Contribution
This containerization setup significantly improves the developer experience and addresses the key pain points mentioned in the issue.
50 changes: 50 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1825,6 +1825,56 @@ Contributors are recognized in our:

---

## 🐳 Docker Development Setup

The easiest way to get started is using Docker. This eliminates the need to manually install MongoDB and Redis.

### Prerequisites
- Docker Desktop installed and running
- Git

### Quick Start

Clone the repository
```bash
git clone https://github.com/CipherYuvraj/Greenstagram.git
cd Greenstagram
```
Start the complete development environment
```bash
chmod +x start-dev.sh
./start-dev.sh
```

The application will be available at:
- Frontend: http://localhost:3000
- Backend API: http://localhost:5000
- MongoDB: localhost:27017
- Redis: localhost:6379

For detailed Docker instructions, see [DOCKER.md](DOCKER.md).

### Manual Development Setup
If you prefer not to use Docker, you can set up services manually:

1. Install and start MongoDB locally
2. Install and start Redis locally
3. Copy `backend/.env.example` to `backend/.env`
4. Start backend: `cd backend && npm run dev`
5. Start frontend: `cd frontend && npm run dev`

## 🎯 Hacktoberfest 2025

This project participates in Hacktoberfest 2025! Check out our [issues labeled with hacktoberfest](https://github.com/CipherYuvraj/Greenstagram/labels/hacktoberfest) to contribute.

### Docker Containerization - Issue #21 βœ…
- Complete Docker Compose setup for development
- MongoDB and Redis containerization
- One-command development environment startup
- Consistent environment across all contributors

---

## πŸ“„ License

This project is licensed under the MIT License - see the [LICENSE-CODE](LICENSE-CODE) file for details.
Expand Down
25 changes: 25 additions & 0 deletions backend/Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# ==========================================
# 🐳 Backend Dockerfile for Development
# ==========================================

FROM node:20-alpine

WORKDIR /app

# Copy package files
COPY package*.json ./

# Install dependencies (skip postinstall scripts for Docker builds)
RUN npm install --ignore-scripts

# Copy source code
COPY . .

# Expose port
EXPOSE 5000

# Install tsx globally for development
RUN npm install -g tsx

# Start development server with hot reload
CMD ["tsx", "--watch", "src/index.ts"]
Loading