Files
data-classify-nextjs-sharp-…/README-DEPLOYMENT.md
2026-02-25 12:40:10 +05:30

4.6 KiB

Observation App - Docker Deployment Guide

This guide provides a complete Docker-based deployment solution for the Observation App with automated database import and image handling.

🏗️ Architecture

  • observation_app: Next.js application container
  • observation_db: MongoDB database container
  • observation_net: Private network for container communication

📋 Prerequisites

  • Docker and Docker Compose installed
  • .env file configured
  • public/ directory with required files
  • public/db/ directory with JSON database files (optional)

🚀 Quick Deployment

1. Prepare Environment

Ensure you have:

# .env file with configuration
MONGODB_URI=mongodb://localhost/beanstalk
# ... other environment variables

# public directory structure
public/
├── observations/     # Image files
├── db/              # JSON database files
│   ├── indicators.json
│   ├── learning_areas.json
│   └── observations.json
└── ...              # Other static files

2. Deploy

# Make deployment script executable
chmod +x scripts/deploy.sh

# Run deployment
./scripts/deploy.sh

The deployment script will:

  • Build and start containers
  • Wait for database readiness
  • Import JSON files from public/db/ automatically
  • Copy images to container
  • Perform health checks

3. Access Services

🛠️ Management Commands

Container Management

# View logs
docker-compose logs -f

# Stop services
docker-compose down

# Restart services
docker-compose restart

# Access application container
docker-compose exec observation_app sh

# Access database
docker-compose exec observation_db mongosh

Database Operations

# Import new JSON file
curl -X POST -F "file=@data.json" http://localhost:3000/api/import-json

# Export database
docker-compose exec observation_db mongodump --uri="mongodb://admin:password123@localhost:27017/beanstalk?authSource=admin" --archive > backup.archive

📁 Data Management

Images

  • Place images in public/observations/
  • Automatically copied to container during deployment
  • Accessible via /api/proxy-image endpoint

Database Files

  • Place JSON files in public/db/
  • Filename becomes collection name (e.g., users.jsonusers collection)
  • Automatically imported during deployment
  • Existing collections are dropped before import

🔧 Configuration

Environment Variables

# Database Connection
MONGODB_URI=mongodb://admin:password123@observation_db:27017/beanstalk?authSource=admin

# Application
NODE_ENV=production

Docker Compose Settings

  • MongoDB Version: 6.0
  • Node.js Version: 18 Alpine
  • Ports: App (3000), Database (27017)
  • Volumes: Persistent MongoDB data

🔄 Backup & Restore

Create Backup

chmod +x scripts/backup.sh
./scripts/backup.sh

Creates backup in backups/YYYYMMDD_HHMMSS/ with:

  • MongoDB database archive
  • Image files
  • Configuration files
  • Automated restore script

Restore from Backup

cd backups/YYYYMMDD_HHMMSS/
./restore.sh

🧹 Cleanup

Complete Cleanup

chmod +x scripts/cleanup.sh
./scripts/cleanup.sh

Removes:

  • All containers
  • Application images
  • Unused networks
  • Optionally: Database volumes (with confirmation)

🔍 Troubleshooting

Database Connection Issues

# Check database status
docker-compose exec observation_db mongosh --eval "db.adminCommand('ping')"

# View database logs
docker-compose logs observation_db

Application Issues

# Check application health
curl http://localhost:3000/api/health

# View application logs
docker-compose logs observation_app

Rebuild Containers

# Force rebuild without cache
docker-compose build --no-cache
docker-compose up -d

📊 Monitoring

Health Checks

  • Application: /api/health
  • Database: MongoDB ping command
  • Container status: docker-compose ps

Logs

# All services
docker-compose logs -f

# Specific service
docker-compose logs -f observation_app
docker-compose logs -f observation_db

🔒 Security Notes

  • Default credentials are for development only
  • Change MongoDB passwords in production
  • Use environment variables for sensitive data
  • Consider using Docker secrets for production

🚀 Production Considerations

  1. Security: Update default passwords
  2. SSL: Add HTTPS termination
  3. Backup: Schedule regular backups
  4. Monitoring: Add health monitoring
  5. Scaling: Consider load balancer for multiple app instances