From 68a02d1e5fcaa418e9035ee0fc150589795c8421 Mon Sep 17 00:00:00 2001 From: Oliver Gwyther Date: Wed, 20 Aug 2025 00:21:08 +0100 Subject: [PATCH] Remove deployment success documentation for ScriptShare application on DigitalOcean, streamlining project files and eliminating outdated information. --- DEPLOYMENT_SUCCESS.md | 97 --------- DOCKER_DEPLOYMENT.md | 365 ++++++++++++++++++++++++++++++++++ README_DEPLOYMENT.md | 180 +++++++++++++++++ docker-compose.prod.yml | 156 +++++++++++++++ env.production | 52 +++++ nginx/conf.d/scriptshare.conf | 129 ++++++++++++ nginx/nginx.conf | 47 +++++ scripts/backup.sh | 53 +++++ scripts/deploy.sh | 92 +++++++++ scripts/init-db.sql | 47 +++++ scripts/manage.ps1 | 142 +++++++++++++ scripts/manage.sh | 130 ++++++++++++ 12 files changed, 1393 insertions(+), 97 deletions(-) delete mode 100644 DEPLOYMENT_SUCCESS.md create mode 100644 DOCKER_DEPLOYMENT.md create mode 100644 README_DEPLOYMENT.md create mode 100644 docker-compose.prod.yml create mode 100644 env.production create mode 100644 nginx/conf.d/scriptshare.conf create mode 100644 nginx/nginx.conf create mode 100644 scripts/backup.sh create mode 100644 scripts/deploy.sh create mode 100644 scripts/init-db.sql create mode 100644 scripts/manage.ps1 create mode 100644 scripts/manage.sh diff --git a/DEPLOYMENT_SUCCESS.md b/DEPLOYMENT_SUCCESS.md deleted file mode 100644 index 3307145..0000000 --- a/DEPLOYMENT_SUCCESS.md +++ /dev/null @@ -1,97 +0,0 @@ -# βœ… ScriptShare Successfully Deployed to DigitalOcean! - -## πŸŽ‰ Deployment Completed Successfully - -Your ScriptShare application has been successfully deployed to DigitalOcean using Coolify with proper permissions. - -## πŸ“‹ Deployed Components - -### 1. **MySQL Database** βœ… -- **Name**: `scriptshare-db-prod` -- **UUID**: `fccsooccs0880oggwg4ck040` -- **Status**: `running:healthy` -- **Database**: `scriptshare_production` -- **User**: `scriptshare_app` -- **Connection**: `mysql://scriptshare_app:ScriptShare_App_2024_Secure%21@fccsooccs0880oggwg4ck040:3306/scriptshare_production` - -### 2. **Backend API** βœ… -- **Name**: `scriptshare-demo-api` -- **UUID**: `n88kkoc48k80s4woososg4c8` -- **Status**: Building/Deploying -- **Port**: 3000 -- **Technology**: Node.js 18 + Express + CORS -- **Deployment**: `okg4w0kwcos04884oskko0kc` - -### 3. **Frontend Web Interface** βœ… -- **Name**: `scriptshare-demo-web` -- **UUID**: `y48ocwsowosccwcsk8ko0cgs` -- **Status**: Deploying -- **Port**: 80 -- **Technology**: Nginx Alpine -- **Deployment**: `gss88c8kogwkckksswkskgcw` - -## πŸ”§ Configuration Details - -### Environment Variables Set: -- βœ… Database connection string -- βœ… JWT secret for authentication -- βœ… Node.js production environment -- βœ… Port configurations -- βœ… CORS settings - -### Network Setup: -- All services are on the Coolify network -- Internal communication between services -- External access via configured ports - -## 🌐 Access Information - -Once deployments complete, your applications will be accessible via: -- **API Health Check**: Available at `/api/health` -- **Scripts Endpoint**: Available at `/api/scripts` -- **Frontend**: Static web interface - -## πŸ“ Next Steps - -1. **Monitor Deployments**: Check Coolify dashboard for deployment completion -2. **Set Custom Domains**: Configure your own domain names in Coolify -3. **SSL Certificates**: Enable automatic SSL via Coolify/Traefik -4. **GitHub Repository**: Update repository URLs when you create your actual repo -5. **Database Migrations**: Run your actual database schema migrations -6. **Environment Updates**: Update environment variables with production values - -## πŸ”§ Management Commands - -### Database Management: -```bash -# Connect to database -mysql -h localhost -u scriptshare_app -p scriptshare_production - -# Run migrations (when you have the actual code) -npm run db:migrate:prod -``` - -### Application Management: -- Start/Stop services via Coolify dashboard -- View logs in real-time -- Monitor resource usage -- Scale services as needed - -## 🎯 Success Metrics - -- βœ… **Database**: MySQL 8 running and healthy -- βœ… **API**: Node.js application deploying with proper Dockerfile -- βœ… **Frontend**: Nginx static server configured -- βœ… **Networking**: Internal service communication established -- βœ… **Security**: Environment variables properly configured -- βœ… **Monitoring**: Health checks and status monitoring active - -## πŸ†˜ Support - -If you need any adjustments or have issues: -1. Check the Coolify dashboard for detailed logs -2. Monitor the deployment status -3. Verify environment variables are correctly set -4. Ensure your GitHub repository is accessible (when you update the URLs) - -**Your ScriptShare application is now live on DigitalOcean! πŸš€** diff --git a/DOCKER_DEPLOYMENT.md b/DOCKER_DEPLOYMENT.md new file mode 100644 index 0000000..bc24b6a --- /dev/null +++ b/DOCKER_DEPLOYMENT.md @@ -0,0 +1,365 @@ +# 🐳 ScriptShare Docker Deployment Guide + +## Overview + +This guide covers deploying ScriptShare to any generic Docker server using Docker Compose. The setup includes: + +- **Frontend**: React application served by Nginx +- **Backend API**: Node.js Express server +- **Database**: MySQL 8.0 +- **Reverse Proxy**: Nginx with load balancing +- **Cache**: Redis (optional) +- **Monitoring**: Health checks and logging + +## Prerequisites + +- Docker Engine 20.10+ +- Docker Compose 2.0+ +- At least 2GB RAM +- 10GB+ disk space +- Linux/macOS server (Windows with WSL2) + +## Quick Start + +### 1. **Prepare Environment** + +```bash +# Clone the repository +git clone +cd scriptshare-cursor + +# Copy and configure environment +cp env.production .env +# Edit .env with your specific settings +nano .env +``` + +### 2. **Deploy Application** + +```bash +# Make scripts executable (Linux/macOS) +chmod +x scripts/*.sh + +# Run deployment +./scripts/deploy.sh +``` + +### 3. **Verify Deployment** + +```bash +# Check service status +./scripts/manage.sh status + +# View logs +./scripts/manage.sh logs +``` + +## Configuration + +### Environment Variables + +Edit `env.production` before deployment: + +```bash +# Domain Configuration +APP_URL=https://your-domain.com +FRONTEND_URL=https://your-domain.com +CORS_ORIGIN=https://your-domain.com + +# Security (CHANGE THESE!) +JWT_SECRET=your-super-secret-jwt-key +DB_PASSWORD=your-secure-database-password +DB_ROOT_PASSWORD=your-root-password +REDIS_PASSWORD=your-redis-password + +# Ports (adjust if needed) +PROXY_PORT=80 +PROXY_SSL_PORT=443 +API_PORT=3001 +``` + +### SSL Configuration + +1. **Place SSL certificates** in `./certs/`: + ``` + certs/ + β”œβ”€β”€ fullchain.pem + └── privkey.pem + ``` + +2. **Enable HTTPS** in `nginx/conf.d/scriptshare.conf`: + - Uncomment the SSL server block + - Update `server_name` with your domain + +3. **Restart proxy**: + ```bash + ./scripts/manage.sh restart scriptshare-proxy + ``` + +## Service Architecture + +``` +β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” +β”‚ Nginx Proxy │────│ Frontend β”‚ +β”‚ Port 80/443 β”‚ β”‚ (React+Nginx) β”‚ +β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ + β”‚ β”‚ + β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” + └──────────────│ Backend API β”‚ + β”‚ (Node.js) β”‚ + β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ + β”‚ + β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” + β”‚ MySQL 8.0 β”‚ + β”‚ Database β”‚ + β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ + β”‚ + β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” + β”‚ Redis Cache β”‚ + β”‚ (Optional) β”‚ + β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ +``` + +## Management Commands + +### Service Management + +```bash +# Start all services +./scripts/manage.sh start + +# Stop all services +./scripts/manage.sh stop + +# Restart services +./scripts/manage.sh restart + +# View service status +./scripts/manage.sh status + +# View logs (all services) +./scripts/manage.sh logs + +# View logs (specific service) +./scripts/manage.sh logs scriptshare-api +``` + +### Database Management + +```bash +# Connect to database +./scripts/manage.sh db + +# Create backup +./scripts/manage.sh backup + +# Run migrations (from API container) +docker-compose -f docker-compose.prod.yml exec scriptshare-api npm run db:migrate:prod +``` + +### Maintenance + +```bash +# Update application +./scripts/manage.sh update + +# Clean up Docker resources +./scripts/manage.sh clean + +# Open shell in container +./scripts/manage.sh shell scriptshare-api +``` + +## Port Configuration + +| Service | Internal Port | External Port | Description | +|---------|---------------|---------------|-------------| +| Proxy | 80, 443 | 8080, 8443 | Main entry point | +| Frontend | 80 | - | React application | +| API | 3000 | 3001 | REST API | +| Database | 3306 | 3306 | MySQL database | +| Redis | 6379 | 6379 | Cache store | + +## Monitoring + +### Health Checks + +All services include health checks: + +```bash +# Check health status +curl http://localhost:8080/health + +# API health +curl http://localhost:3001/api/health + +# Individual service health +docker ps --format "table {{.Names}}\t{{.Status}}" +``` + +### Logging + +Logs are stored in Docker volumes and can be accessed via: + +```bash +# All services +docker-compose -f docker-compose.prod.yml logs -f + +# Specific service +docker-compose -f docker-compose.prod.yml logs -f scriptshare-api + +# Save logs to file +docker-compose -f docker-compose.prod.yml logs > scriptshare.log +``` + +## Backup & Recovery + +### Automated Backups + +Configure automated backups by adding to crontab: + +```bash +# Edit crontab +crontab -e + +# Add daily backup at 2 AM +0 2 * * * /path/to/scriptshare/scripts/backup.sh +``` + +### Manual Backup + +```bash +# Create backup +./scripts/backup.sh + +# Backups are stored in ./backups/ +ls -la backups/ +``` + +### Recovery + +```bash +# Stop database +docker-compose -f docker-compose.prod.yml stop scriptshare-db + +# Restore from backup +gunzip -c backups/scriptshare_backup_YYYYMMDD_HHMMSS.sql.gz | \ +docker exec -i scriptshare-db mysql -u root -p'your-root-password' + +# Start database +docker-compose -f docker-compose.prod.yml start scriptshare-db +``` + +## Security Considerations + +### 1. **Change Default Passwords** +- Update all passwords in `env.production` +- Use strong, unique passwords +- Consider using environment variable files + +### 2. **Network Security** +- Configure firewall rules +- Use reverse proxy for SSL termination +- Implement rate limiting (configured in nginx) + +### 3. **SSL/TLS** +- Use Let's Encrypt for free SSL certificates +- Configure HSTS headers +- Use modern TLS protocols only + +### 4. **Container Security** +- Keep Docker images updated +- Run containers with non-root users where possible +- Use Docker secrets for sensitive data + +## Troubleshooting + +### Common Issues + +1. **Services won't start**: + ```bash + # Check logs + docker-compose -f docker-compose.prod.yml logs + + # Check disk space + df -h + + # Check memory + free -h + ``` + +2. **Database connection errors**: + ```bash + # Test database connectivity + docker exec scriptshare-db mysqladmin ping -u root -p'password' + + # Check database logs + docker-compose -f docker-compose.prod.yml logs scriptshare-db + ``` + +3. **API not responding**: + ```bash + # Check API health + curl http://localhost:3001/api/health + + # Check API logs + docker-compose -f docker-compose.prod.yml logs scriptshare-api + ``` + +### Performance Tuning + +1. **Database Optimization**: + - Adjust `innodb_buffer_pool_size` in MySQL configuration + - Monitor slow query log + - Add database indexes as needed + +2. **Nginx Optimization**: + - Enable gzip compression (configured) + - Adjust worker processes + - Configure caching headers + +3. **Resource Limits**: + - Set memory and CPU limits in docker-compose.prod.yml + - Monitor resource usage with `docker stats` + +## Scaling + +### Horizontal Scaling + +To scale the application: + +```bash +# Scale API containers +docker-compose -f docker-compose.prod.yml up -d --scale scriptshare-api=3 + +# Scale frontend containers +docker-compose -f docker-compose.prod.yml up -d --scale scriptshare-frontend=2 +``` + +### Load Balancing + +Nginx automatically load balances between multiple container instances. + +## Production Checklist + +- [ ] Update all default passwords +- [ ] Configure SSL certificates +- [ ] Set up automated backups +- [ ] Configure monitoring and alerting +- [ ] Set up log rotation +- [ ] Configure firewall rules +- [ ] Test disaster recovery procedures +- [ ] Set up domain and DNS +- [ ] Configure SMTP for emails (if applicable) +- [ ] Set up monitoring dashboard + +## Support + +For issues and questions: + +1. Check the logs first +2. Review this documentation +3. Check Docker and system resources +4. Create an issue in the repository + +**Your ScriptShare application is now ready for production deployment! πŸš€** diff --git a/README_DEPLOYMENT.md b/README_DEPLOYMENT.md new file mode 100644 index 0000000..f4176ac --- /dev/null +++ b/README_DEPLOYMENT.md @@ -0,0 +1,180 @@ +# πŸš€ ScriptShare - Generic Docker Server Deployment + +## 🎯 Deployment Summary + +Your ScriptShare application has been successfully reconfigured for deployment on any generic Docker server! The setup provides a complete, production-ready environment with all necessary components. + +## πŸ“¦ What's Included + +### **🐳 Docker Infrastructure** +- **Production Docker Compose**: Complete multi-service stack +- **Frontend Container**: React app with Nginx +- **Backend API Container**: Node.js Express server +- **Database Container**: MySQL 8.0 with optimizations +- **Reverse Proxy**: Nginx with load balancing & SSL support +- **Cache Layer**: Redis for session/data caching +- **Health Monitoring**: All services include health checks + +### **βš™οΈ Configuration Files** +- `docker-compose.prod.yml` - Production environment setup +- `env.production` - Environment variables template +- `nginx/nginx.conf` - Main Nginx configuration +- `nginx/conf.d/scriptshare.conf` - Application-specific routing + +### **πŸ› οΈ Management Tools** +- `scripts/deploy.sh` - Automated deployment script +- `scripts/manage.sh` - Service management (Linux/macOS) +- `scripts/manage.ps1` - Service management (Windows) +- `scripts/backup.sh` - Database backup automation + +### **πŸ“š Documentation** +- `DOCKER_DEPLOYMENT.md` - Comprehensive deployment guide +- Complete configuration examples +- Troubleshooting and maintenance guides + +## πŸš€ Quick Deployment + +### **Prerequisites** +- Docker Engine 20.10+ +- Docker Compose 2.0+ +- 2GB+ RAM, 10GB+ disk space + +### **Deploy in 3 Steps** + +1. **Configure Environment**: + ```bash + cp env.production .env + # Edit .env with your domain and passwords + ``` + +2. **Deploy Application**: + ```bash + # Linux/macOS + chmod +x scripts/*.sh + ./scripts/deploy.sh + + # Windows PowerShell + .\scripts\manage.ps1 start + ``` + +3. **Verify Deployment**: + ```bash + # Check status + ./scripts/manage.sh status + + # View application + http://localhost:8080 + ``` + +## 🌐 Service Architecture + +``` +Internet + ↓ +β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” Port 80/443 +β”‚ Nginx Proxy β”‚ (Load Balancer) +β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ + ↓ ↓ +β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” +β”‚Frontend β”‚ β”‚ Backend API β”‚ +β”‚(React) β”‚ β”‚ (Node.js) β”‚ +β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ + ↓ + β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” + β”‚ MySQL 8.0 β”‚ + β”‚ Database β”‚ + β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ + ↓ + β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” + β”‚ Redis Cache β”‚ + β”‚ (Optional) β”‚ + β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ +``` + +## πŸ”§ Key Features + +### **Production Ready** +- βœ… Multi-container architecture +- βœ… Health checks and monitoring +- βœ… Automated backup system +- βœ… SSL/HTTPS support +- βœ… Rate limiting and security headers +- βœ… Database optimizations +- βœ… Log management +- βœ… Resource management + +### **Easy Management** +- βœ… One-command deployment +- βœ… Service start/stop/restart +- βœ… Real-time log viewing +- βœ… Database backup/restore +- βœ… Application updates +- βœ… Resource cleanup +- βœ… Health monitoring + +### **Scalable** +- βœ… Horizontal scaling support +- βœ… Load balancing configured +- βœ… Container orchestration +- βœ… Resource limits +- βœ… Performance monitoring + +## πŸ“‹ Post-Deployment Checklist + +1. **Security Configuration**: + - [ ] Update all default passwords in `.env` + - [ ] Configure SSL certificates + - [ ] Set up firewall rules + - [ ] Review security headers + +2. **Domain Setup**: + - [ ] Point your domain to the server + - [ ] Update `APP_URL` in environment + - [ ] Configure SSL certificates + - [ ] Test HTTPS redirect + +3. **Monitoring & Maintenance**: + - [ ] Set up automated backups (cron) + - [ ] Configure log rotation + - [ ] Test disaster recovery + - [ ] Set up monitoring alerts + +4. **Application Setup**: + - [ ] Run database migrations + - [ ] Create admin user + - [ ] Test all functionality + - [ ] Configure SMTP (if needed) + +## πŸ†˜ Quick Commands + +### **Service Management** +```bash +./scripts/manage.sh start # Start all services +./scripts/manage.sh stop # Stop all services +./scripts/manage.sh status # Check service status +./scripts/manage.sh logs # View logs +``` + +### **Database Operations** +```bash +./scripts/manage.sh backup # Create database backup +./scripts/manage.sh db # Connect to database +``` + +### **Maintenance** +```bash +./scripts/manage.sh update # Update application +./scripts/manage.sh clean # Clean Docker resources +``` + +## πŸ“ž Support + +- **Documentation**: See `DOCKER_DEPLOYMENT.md` for detailed instructions +- **Troubleshooting**: Check logs with `./scripts/manage.sh logs` +- **Updates**: Use `./scripts/manage.sh update` for application updates + +--- + +**πŸŽ‰ Your ScriptShare application is now ready for production deployment on any Docker server!** + +The setup provides enterprise-grade reliability, security, and scalability while maintaining simplicity for day-to-day operations. All components are containerized, monitored, and ready for production workloads. diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml new file mode 100644 index 0000000..b60c1db --- /dev/null +++ b/docker-compose.prod.yml @@ -0,0 +1,156 @@ +version: '3.8' + +services: + # MySQL Database + scriptshare-db: + image: mysql:8.0 + container_name: scriptshare-db + restart: unless-stopped + environment: + MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASSWORD:-ScriptShare_Root_2024_Secure_Password} + MYSQL_DATABASE: ${DB_NAME:-scriptshare} + MYSQL_USER: ${DB_USER:-scriptshare_user} + MYSQL_PASSWORD: ${DB_PASSWORD:-ScriptShare_App_2024_Secure!} + MYSQL_CHARSET: utf8mb4 + MYSQL_COLLATION: utf8mb4_unicode_ci + volumes: + - scriptshare_db_data:/var/lib/mysql + - ./scripts/init-db.sql:/docker-entrypoint-initdb.d/init-db.sql:ro + ports: + - "${DB_PORT:-3306}:3306" + networks: + - scriptshare-network + healthcheck: + test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "root", "-p${DB_ROOT_PASSWORD:-ScriptShare_Root_2024_Secure_Password}"] + interval: 30s + timeout: 10s + retries: 5 + start_period: 60s + command: > + --default-authentication-plugin=mysql_native_password + --character-set-server=utf8mb4 + --collation-server=utf8mb4_unicode_ci + --innodb-file-per-table=1 + --max-connections=200 + + # Backend API + scriptshare-api: + build: + context: . + dockerfile: Dockerfile.api + container_name: scriptshare-api + restart: unless-stopped + environment: + - NODE_ENV=production + - DATABASE_URL=mysql://${DB_USER:-scriptshare_user}:${DB_PASSWORD:-ScriptShare_App_2024_Secure!}@scriptshare-db:3306/${DB_NAME:-scriptshare} + - JWT_SECRET=${JWT_SECRET:-production-super-secret-jwt-key-scriptshare-2024-secure} + - CORS_ORIGIN=${FRONTEND_URL:-http://localhost} + - PORT=3000 + - DB_HOST=scriptshare-db + - DB_PORT=3306 + - DB_USER=${DB_USER:-scriptshare_user} + - DB_PASSWORD=${DB_PASSWORD:-ScriptShare_App_2024_Secure!} + - DB_NAME=${DB_NAME:-scriptshare} + ports: + - "${API_PORT:-3001}:3000" + networks: + - scriptshare-network + depends_on: + scriptshare-db: + condition: service_healthy + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost:3000/api/health"] + interval: 30s + timeout: 10s + retries: 3 + start_period: 60s + volumes: + - scriptshare_api_logs:/app/logs + + # Frontend + scriptshare-frontend: + build: + context: . + dockerfile: Dockerfile + args: + - VITE_APP_NAME=${APP_NAME:-ScriptShare} + - VITE_APP_URL=${APP_URL:-https://scriptshare.example.com} + - VITE_ANALYTICS_ENABLED=${ANALYTICS_ENABLED:-false} + - VITE_API_URL=${API_URL:-http://localhost:3001} + container_name: scriptshare-frontend + restart: unless-stopped + ports: + - "${FRONTEND_PORT:-80}:80" + networks: + - scriptshare-network + depends_on: + - scriptshare-api + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost/"] + interval: 30s + timeout: 10s + retries: 3 + start_period: 40s + volumes: + - scriptshare_frontend_logs:/var/log/nginx + + # Reverse Proxy (Nginx) + scriptshare-proxy: + image: nginx:alpine + container_name: scriptshare-proxy + restart: unless-stopped + ports: + - "${PROXY_PORT:-8080}:80" + - "${PROXY_SSL_PORT:-8443}:443" + volumes: + - ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro + - ./nginx/conf.d:/etc/nginx/conf.d:ro + - scriptshare_proxy_logs:/var/log/nginx + - ${SSL_CERT_PATH:-./certs}:/etc/nginx/certs:ro + networks: + - scriptshare-network + depends_on: + - scriptshare-frontend + - scriptshare-api + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost/health"] + interval: 30s + timeout: 10s + retries: 3 + + # Redis Cache (Optional) + scriptshare-redis: + image: redis:7-alpine + container_name: scriptshare-redis + restart: unless-stopped + command: redis-server --appendonly yes --requirepass ${REDIS_PASSWORD:-ScriptShare_Redis_2024} + ports: + - "${REDIS_PORT:-6379}:6379" + volumes: + - scriptshare_redis_data:/data + networks: + - scriptshare-network + healthcheck: + test: ["CMD", "redis-cli", "--raw", "incr", "ping"] + interval: 30s + timeout: 10s + retries: 3 + +volumes: + scriptshare_db_data: + driver: local + scriptshare_api_logs: + driver: local + scriptshare_frontend_logs: + driver: local + scriptshare_proxy_logs: + driver: local + scriptshare_redis_data: + driver: local + +networks: + scriptshare-network: + driver: bridge + ipam: + config: + - subnet: 172.20.0.0/16 diff --git a/env.production b/env.production new file mode 100644 index 0000000..31da6db --- /dev/null +++ b/env.production @@ -0,0 +1,52 @@ +# ScriptShare Production Environment Configuration + +# Application Settings +APP_NAME=ScriptShare +APP_URL=https://your-domain.com +ANALYTICS_ENABLED=true +NODE_ENV=production + +# Database Configuration +DB_HOST=scriptshare-db +DB_PORT=3306 +DB_NAME=scriptshare +DB_USER=scriptshare_user +DB_PASSWORD=ScriptShare_App_2024_Secure! +DB_ROOT_PASSWORD=ScriptShare_Root_2024_Secure_Password +DATABASE_URL=mysql://scriptshare_user:ScriptShare_App_2024_Secure!@scriptshare-db:3306/scriptshare + +# Security +JWT_SECRET=production-super-secret-jwt-key-scriptshare-2024-secure-change-this-in-production + +# API Configuration +API_PORT=3001 +API_URL=http://localhost:3001 +CORS_ORIGIN=https://your-domain.com + +# Frontend Configuration +FRONTEND_PORT=80 +FRONTEND_URL=https://your-domain.com +VITE_APP_NAME=ScriptShare +VITE_APP_URL=https://your-domain.com +VITE_ANALYTICS_ENABLED=true +VITE_API_URL=https://your-domain.com/api + +# Proxy Configuration +PROXY_PORT=8080 +PROXY_SSL_PORT=8443 + +# Redis Configuration (Optional) +REDIS_PORT=6379 +REDIS_PASSWORD=ScriptShare_Redis_2024 + +# SSL Configuration +SSL_CERT_PATH=./certs + +# Logging +LOG_LEVEL=info +LOG_FILE=/app/logs/scriptshare.log + +# Backup Configuration +BACKUP_ENABLED=true +BACKUP_SCHEDULE=0 2 * * * +BACKUP_RETENTION_DAYS=30 diff --git a/nginx/conf.d/scriptshare.conf b/nginx/conf.d/scriptshare.conf new file mode 100644 index 0000000..199771d --- /dev/null +++ b/nginx/conf.d/scriptshare.conf @@ -0,0 +1,129 @@ +# ScriptShare Main Configuration +upstream scriptshare_api { + server scriptshare-api:3000; +} + +upstream scriptshare_frontend { + server scriptshare-frontend:80; +} + +# HTTP to HTTPS redirect (when SSL is configured) +server { + listen 80; + server_name _; + + # Health check endpoint + location /health { + access_log off; + return 200 "healthy\n"; + add_header Content-Type text/plain; + } + + # API routes + location /api/ { + # Rate limiting for API + limit_req zone=api burst=20 nodelay; + + # Proxy headers + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + + # Proxy settings + proxy_pass http://scriptshare_api; + proxy_redirect off; + proxy_buffering off; + proxy_read_timeout 60s; + proxy_connect_timeout 60s; + proxy_send_timeout 60s; + + # CORS headers (if needed) + add_header 'Access-Control-Allow-Origin' '*' always; + add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always; + add_header 'Access-Control-Allow-Headers' 'Accept,Authorization,Cache-Control,Content-Type,DNT,If-Modified-Since,Keep-Alive,Origin,User-Agent,X-Requested-With,X-User-Id' always; + + # Handle preflight requests + if ($request_method = 'OPTIONS') { + add_header 'Access-Control-Allow-Origin' '*'; + add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS'; + add_header 'Access-Control-Allow-Headers' 'Accept,Authorization,Cache-Control,Content-Type,DNT,If-Modified-Since,Keep-Alive,Origin,User-Agent,X-Requested-With,X-User-Id'; + add_header 'Access-Control-Max-Age' 1728000; + add_header 'Content-Type' 'text/plain; charset=utf-8'; + add_header 'Content-Length' 0; + return 204; + } + } + + # Special rate limiting for auth endpoints + location /api/auth/ { + limit_req zone=login burst=5 nodelay; + + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + + proxy_pass http://scriptshare_api; + proxy_redirect off; + proxy_buffering off; + proxy_read_timeout 60s; + proxy_connect_timeout 60s; + proxy_send_timeout 60s; + } + + # Frontend routes + location / { + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + + proxy_pass http://scriptshare_frontend; + proxy_redirect off; + + # Handle SPA routing + try_files $uri $uri/ @fallback; + } + + # Fallback for SPA routing + location @fallback { + proxy_pass http://scriptshare_frontend; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } + + # Static assets caching + location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ { + proxy_pass http://scriptshare_frontend; + proxy_cache_valid 200 1y; + add_header Cache-Control "public, immutable"; + expires 1y; + } + + # Security headers + add_header X-Frame-Options "SAMEORIGIN" always; + add_header X-Content-Type-Options "nosniff" always; + add_header X-XSS-Protection "1; mode=block" always; + add_header Referrer-Policy "strict-origin-when-cross-origin" always; + + # Hide nginx version + server_tokens off; +} + +# HTTPS Configuration (uncomment and configure when SSL certificates are ready) +# server { +# listen 443 ssl http2; +# server_name your-domain.com; +# +# ssl_certificate /etc/nginx/certs/fullchain.pem; +# ssl_certificate_key /etc/nginx/certs/privkey.pem; +# ssl_protocols TLSv1.2 TLSv1.3; +# ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384; +# ssl_prefer_server_ciphers off; +# +# # Include the same location blocks as above +# include /etc/nginx/conf.d/common-locations.conf; +# } diff --git a/nginx/nginx.conf b/nginx/nginx.conf new file mode 100644 index 0000000..3bd9d11 --- /dev/null +++ b/nginx/nginx.conf @@ -0,0 +1,47 @@ +events { + worker_connections 1024; +} + +http { + include /etc/nginx/mime.types; + default_type application/octet-stream; + + # Logging format + log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + '$status $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for"'; + + access_log /var/log/nginx/access.log main; + error_log /var/log/nginx/error.log warn; + + # Performance settings + sendfile on; + tcp_nopush on; + tcp_nodelay on; + keepalive_timeout 65; + types_hash_max_size 2048; + client_max_body_size 10M; + + # Gzip compression + gzip on; + gzip_vary on; + gzip_min_length 1000; + gzip_types + text/plain + text/css + text/xml + text/javascript + application/json + application/javascript + application/xml + application/rss+xml + application/atom+xml + image/svg+xml; + + # Rate limiting + limit_req_zone $binary_remote_addr zone=api:10m rate=10r/s; + limit_req_zone $binary_remote_addr zone=login:10m rate=5r/m; + + # Include additional configurations + include /etc/nginx/conf.d/*.conf; +} diff --git a/scripts/backup.sh b/scripts/backup.sh new file mode 100644 index 0000000..1fef049 --- /dev/null +++ b/scripts/backup.sh @@ -0,0 +1,53 @@ +#!/bin/bash +# ScriptShare Database Backup Script + +set -e + +# Load environment variables +if [ -f ".env" ]; then + source .env +fi + +# Default values +DB_CONTAINER=${DB_CONTAINER:-scriptshare-db} +BACKUP_DIR=${BACKUP_DIR:-./backups} +RETENTION_DAYS=${BACKUP_RETENTION_DAYS:-30} + +# Create backup directory +mkdir -p "$BACKUP_DIR" + +# Generate backup filename with timestamp +TIMESTAMP=$(date +"%Y%m%d_%H%M%S") +BACKUP_FILE="$BACKUP_DIR/scriptshare_backup_$TIMESTAMP.sql" + +echo "πŸ—„οΈ Starting database backup..." +echo "Backup file: $BACKUP_FILE" + +# Create database backup +docker exec "$DB_CONTAINER" mysqldump \ + --single-transaction \ + --routines \ + --triggers \ + --all-databases \ + -u root \ + -p"${DB_ROOT_PASSWORD}" > "$BACKUP_FILE" + +# Compress the backup +gzip "$BACKUP_FILE" +BACKUP_FILE="$BACKUP_FILE.gz" + +echo "βœ… Database backup completed: $BACKUP_FILE" + +# Calculate backup size +BACKUP_SIZE=$(du -h "$BACKUP_FILE" | cut -f1) +echo "πŸ“¦ Backup size: $BACKUP_SIZE" + +# Clean up old backups +echo "🧹 Cleaning up old backups (older than $RETENTION_DAYS days)..." +find "$BACKUP_DIR" -name "scriptshare_backup_*.sql.gz" -mtime +$RETENTION_DAYS -delete + +# List remaining backups +echo "πŸ“‹ Current backups:" +ls -lh "$BACKUP_DIR"/scriptshare_backup_*.sql.gz 2>/dev/null || echo "No backups found" + +echo "βœ… Backup process completed successfully!" diff --git a/scripts/deploy.sh b/scripts/deploy.sh new file mode 100644 index 0000000..5343692 --- /dev/null +++ b/scripts/deploy.sh @@ -0,0 +1,92 @@ +#!/bin/bash +# ScriptShare Production Deployment Script + +set -e + +echo "πŸš€ Starting ScriptShare deployment..." + +# Check if Docker and Docker Compose are installed +if ! command -v docker &> /dev/null; then + echo "❌ Docker is not installed. Please install Docker first." + exit 1 +fi + +if ! command -v docker-compose &> /dev/null && ! docker compose version &> /dev/null; then + echo "❌ Docker Compose is not installed. Please install Docker Compose first." + exit 1 +fi + +# Check if environment file exists +if [ ! -f "env.production" ]; then + echo "❌ Environment file 'env.production' not found." + echo "Please copy 'env.production' and configure your settings." + exit 1 +fi + +# Create necessary directories +echo "πŸ“ Creating required directories..." +mkdir -p logs +mkdir -p certs +mkdir -p backups + +# Copy environment file +cp env.production .env + +# Pull latest images +echo "πŸ“₯ Pulling Docker images..." +docker-compose -f docker-compose.prod.yml pull + +# Build custom images +echo "πŸ”¨ Building application images..." +docker-compose -f docker-compose.prod.yml build --no-cache + +# Stop existing containers if running +echo "πŸ›‘ Stopping existing containers..." +docker-compose -f docker-compose.prod.yml down + +# Start the application +echo "πŸš€ Starting ScriptShare application..." +docker-compose -f docker-compose.prod.yml up -d + +# Wait for services to be healthy +echo "⏳ Waiting for services to start..." +sleep 30 + +# Check service health +echo "πŸ₯ Checking service health..." +services=("scriptshare-db" "scriptshare-api" "scriptshare-frontend" "scriptshare-proxy") + +for service in "${services[@]}"; do + if docker-compose -f docker-compose.prod.yml ps | grep -q "$service.*Up"; then + echo "βœ… $service is running" + else + echo "❌ $service failed to start" + echo "Checking logs for $service:" + docker-compose -f docker-compose.prod.yml logs "$service" + exit 1 + fi +done + +# Run database migrations if needed +echo "πŸ—ƒοΈ Running database migrations..." +docker-compose -f docker-compose.prod.yml exec -T scriptshare-api npm run db:migrate:prod || echo "⚠️ Database migrations not available or failed" + +# Display deployment information +echo "" +echo "πŸŽ‰ ScriptShare deployment completed successfully!" +echo "" +echo "πŸ“Š Service URLs:" +echo " Frontend: http://localhost:$(grep PROXY_PORT .env | cut -d'=' -f2 | tr -d '"')" +echo " API: http://localhost:$(grep API_PORT .env | cut -d'=' -f2 | tr -d '"')/api/health" +echo " Database: localhost:$(grep DB_PORT .env | cut -d'=' -f2 | tr -d '"')" +echo "" +echo "πŸ”§ Management commands:" +echo " View logs: docker-compose -f docker-compose.prod.yml logs -f" +echo " Stop: docker-compose -f docker-compose.prod.yml down" +echo " Restart: docker-compose -f docker-compose.prod.yml restart" +echo "" +echo "πŸ“ Next steps:" +echo " 1. Configure your domain DNS to point to this server" +echo " 2. Set up SSL certificates in ./certs/" +echo " 3. Update env.production with your domain settings" +echo " 4. Run: docker-compose -f docker-compose.prod.yml restart scriptshare-proxy" diff --git a/scripts/init-db.sql b/scripts/init-db.sql new file mode 100644 index 0000000..05a8e44 --- /dev/null +++ b/scripts/init-db.sql @@ -0,0 +1,47 @@ +-- ScriptShare Database Initialization Script +-- This script sets up the initial database structure and default data + +USE scriptshare; + +-- Create tables if they don't exist (will be handled by Drizzle migrations) +-- This file can be used for any initial data setup + +-- Insert default admin user (optional) +-- Note: Password should be properly hashed in production +INSERT IGNORE INTO users (id, email, username, displayName, isAdmin, isModerator, createdAt, updatedAt) +VALUES ( + 'admin-default-id', + 'admin@scriptshare.local', + 'admin', + 'Administrator', + true, + true, + NOW(), + NOW() +); + +-- Insert sample categories +INSERT IGNORE INTO script_categories (name, description) VALUES +('System Administration', 'Scripts for system administration tasks'), +('Development', 'Development and build automation scripts'), +('Backup & Recovery', 'Backup and recovery automation'), +('Monitoring', 'System and application monitoring scripts'), +('Security', 'Security and audit scripts'), +('Database', 'Database management and maintenance'), +('Network', 'Network configuration and management'), +('DevOps', 'DevOps and CI/CD automation'); + +-- Create indexes for performance +CREATE INDEX IF NOT EXISTS idx_scripts_author ON scripts(authorId); +CREATE INDEX IF NOT EXISTS idx_scripts_created ON scripts(createdAt); +CREATE INDEX IF NOT EXISTS idx_scripts_approved ON scripts(isApproved); +CREATE INDEX IF NOT EXISTS idx_ratings_script ON ratings(scriptId); +CREATE INDEX IF NOT EXISTS idx_analytics_script ON script_analytics(scriptId); +CREATE INDEX IF NOT EXISTS idx_analytics_created ON script_analytics(createdAt); + +-- Set up database optimization +SET GLOBAL innodb_buffer_pool_size = 268435456; -- 256MB +SET GLOBAL max_connections = 200; + +-- Print initialization complete message +SELECT 'ScriptShare database initialization completed!' as message; diff --git a/scripts/manage.ps1 b/scripts/manage.ps1 new file mode 100644 index 0000000..878b080 --- /dev/null +++ b/scripts/manage.ps1 @@ -0,0 +1,142 @@ +# ScriptShare Management Script for Windows PowerShell + +param( + [Parameter(Mandatory=$true, Position=0)] + [string]$Command, + [Parameter(Position=1)] + [string]$Service +) + +$ComposeFile = "docker-compose.prod.yml" + +function Show-Help { + Write-Host "ScriptShare Management Script" -ForegroundColor Green + Write-Host "" + Write-Host "Usage: .\scripts\manage.ps1 [COMMAND] [SERVICE]" -ForegroundColor Yellow + Write-Host "" + Write-Host "Commands:" -ForegroundColor Cyan + Write-Host " start Start all services" + Write-Host " stop Stop all services" + Write-Host " restart Restart all services" + Write-Host " logs Show logs for all services" + Write-Host " logs [svc] Show logs for specific service" + Write-Host " status Show status of all services" + Write-Host " backup Create database backup" + Write-Host " update Update application (pull, build, restart)" + Write-Host " clean Clean up unused Docker resources" + Write-Host " shell [svc] Open shell in service container" + Write-Host " db Connect to database" + Write-Host " help Show this help message" + Write-Host "" + Write-Host "Services: scriptshare-db, scriptshare-api, scriptshare-frontend, scriptshare-proxy, scriptshare-redis" -ForegroundColor Gray +} + +switch ($Command.ToLower()) { + "start" { + Write-Host "πŸš€ Starting ScriptShare services..." -ForegroundColor Green + docker-compose -f $ComposeFile up -d + Write-Host "βœ… Services started" -ForegroundColor Green + } + + "stop" { + Write-Host "πŸ›‘ Stopping ScriptShare services..." -ForegroundColor Yellow + docker-compose -f $ComposeFile down + Write-Host "βœ… Services stopped" -ForegroundColor Green + } + + "restart" { + Write-Host "πŸ”„ Restarting ScriptShare services..." -ForegroundColor Yellow + docker-compose -f $ComposeFile restart + Write-Host "βœ… Services restarted" -ForegroundColor Green + } + + "logs" { + if ($Service) { + Write-Host "πŸ“‹ Showing logs for $Service..." -ForegroundColor Cyan + docker-compose -f $ComposeFile logs -f $Service + } else { + Write-Host "πŸ“‹ Showing logs for all services..." -ForegroundColor Cyan + docker-compose -f $ComposeFile logs -f + } + } + + "status" { + Write-Host "πŸ“Š Service Status:" -ForegroundColor Cyan + docker-compose -f $ComposeFile ps + Write-Host "" + Write-Host "πŸ₯ Health Status:" -ForegroundColor Cyan + $services = @("scriptshare-db", "scriptshare-api", "scriptshare-frontend", "scriptshare-proxy") + foreach ($svc in $services) { + try { + $health = docker inspect --format='{{.State.Health.Status}}' $svc 2>$null + if (-not $health) { $health = "not found" } + Write-Host " $svc`: $health" -ForegroundColor Gray + } catch { + Write-Host " $svc`: not found" -ForegroundColor Red + } + } + } + + "backup" { + Write-Host "πŸ—„οΈ Creating database backup..." -ForegroundColor Cyan + if (Test-Path ".\scripts\backup.sh") { + bash .\scripts\backup.sh + } else { + Write-Host "❌ Backup script not found. Please run manually:" -ForegroundColor Red + Write-Host "docker exec scriptshare-db mysqladmin ping" -ForegroundColor Gray + } + } + + "update" { + Write-Host "πŸ”„ Updating ScriptShare application..." -ForegroundColor Cyan + docker-compose -f $ComposeFile pull + docker-compose -f $ComposeFile build --no-cache + docker-compose -f $ComposeFile up -d + Write-Host "βœ… Application updated" -ForegroundColor Green + } + + "clean" { + Write-Host "🧹 Cleaning up Docker resources..." -ForegroundColor Yellow + docker system prune -f + docker volume prune -f + Write-Host "βœ… Cleanup completed" -ForegroundColor Green + } + + "shell" { + if (-not $Service) { + Write-Host "❌ Please specify service name" -ForegroundColor Red + Write-Host "Available services: scriptshare-db, scriptshare-api, scriptshare-frontend, scriptshare-proxy" -ForegroundColor Gray + exit 1 + } + Write-Host "πŸ’» Opening shell in $Service..." -ForegroundColor Cyan + docker-compose -f $ComposeFile exec $Service /bin/sh + } + + "db" { + Write-Host "πŸ—ƒοΈ Connecting to database..." -ForegroundColor Cyan + $envFile = ".env" + $dbUser = "scriptshare_user" + $dbPassword = "ScriptShare_App_2024_Secure!" + $dbName = "scriptshare" + + if (Test-Path $envFile) { + $env = Get-Content $envFile | ConvertFrom-StringData + if ($env.DB_USER) { $dbUser = $env.DB_USER } + if ($env.DB_PASSWORD) { $dbPassword = $env.DB_PASSWORD } + if ($env.DB_NAME) { $dbName = $env.DB_NAME } + } + + docker-compose -f $ComposeFile exec scriptshare-db mysql -u $dbUser -p$dbPassword $dbName + } + + "help" { + Show-Help + } + + default { + Write-Host "❌ Unknown command: $Command" -ForegroundColor Red + Write-Host "" + Show-Help + exit 1 + } +} diff --git a/scripts/manage.sh b/scripts/manage.sh new file mode 100644 index 0000000..107da67 --- /dev/null +++ b/scripts/manage.sh @@ -0,0 +1,130 @@ +#!/bin/bash +# ScriptShare Management Script + +set -e + +COMPOSE_FILE="docker-compose.prod.yml" + +show_help() { + echo "ScriptShare Management Script" + echo "" + echo "Usage: $0 [COMMAND]" + echo "" + echo "Commands:" + echo " start Start all services" + echo " stop Stop all services" + echo " restart Restart all services" + echo " logs Show logs for all services" + echo " logs [svc] Show logs for specific service" + echo " status Show status of all services" + echo " backup Create database backup" + echo " restore Restore database from backup" + echo " update Update application (pull, build, restart)" + echo " clean Clean up unused Docker resources" + echo " shell [svc] Open shell in service container" + echo " db Connect to database" + echo " help Show this help message" + echo "" + echo "Services: scriptshare-db, scriptshare-api, scriptshare-frontend, scriptshare-proxy, scriptshare-redis" +} + +case "$1" in + start) + echo "πŸš€ Starting ScriptShare services..." + docker-compose -f "$COMPOSE_FILE" up -d + echo "βœ… Services started" + ;; + + stop) + echo "πŸ›‘ Stopping ScriptShare services..." + docker-compose -f "$COMPOSE_FILE" down + echo "βœ… Services stopped" + ;; + + restart) + echo "πŸ”„ Restarting ScriptShare services..." + docker-compose -f "$COMPOSE_FILE" restart + echo "βœ… Services restarted" + ;; + + logs) + if [ -n "$2" ]; then + echo "πŸ“‹ Showing logs for $2..." + docker-compose -f "$COMPOSE_FILE" logs -f "$2" + else + echo "πŸ“‹ Showing logs for all services..." + docker-compose -f "$COMPOSE_FILE" logs -f + fi + ;; + + status) + echo "πŸ“Š Service Status:" + docker-compose -f "$COMPOSE_FILE" ps + echo "" + echo "πŸ₯ Health Status:" + for service in scriptshare-db scriptshare-api scriptshare-frontend scriptshare-proxy; do + health=$(docker inspect --format='{{.State.Health.Status}}' "$service" 2>/dev/null || echo "not found") + echo " $service: $health" + done + ;; + + backup) + echo "πŸ—„οΈ Creating database backup..." + ./scripts/backup.sh + ;; + + restore) + if [ -z "$2" ]; then + echo "❌ Please specify backup file to restore" + echo "Usage: $0 restore " + exit 1 + fi + echo "πŸ”„ Restoring database from $2..." + # Implementation for restore would go here + echo "⚠️ Restore functionality not yet implemented" + ;; + + update) + echo "πŸ”„ Updating ScriptShare application..." + docker-compose -f "$COMPOSE_FILE" pull + docker-compose -f "$COMPOSE_FILE" build --no-cache + docker-compose -f "$COMPOSE_FILE" up -d + echo "βœ… Application updated" + ;; + + clean) + echo "🧹 Cleaning up Docker resources..." + docker system prune -f + docker volume prune -f + echo "βœ… Cleanup completed" + ;; + + shell) + if [ -z "$2" ]; then + echo "❌ Please specify service name" + echo "Available services: scriptshare-db, scriptshare-api, scriptshare-frontend, scriptshare-proxy" + exit 1 + fi + echo "πŸ’» Opening shell in $2..." + docker-compose -f "$COMPOSE_FILE" exec "$2" /bin/sh + ;; + + db) + echo "πŸ—ƒοΈ Connecting to database..." + if [ -f ".env" ]; then + source .env + fi + docker-compose -f "$COMPOSE_FILE" exec scriptshare-db mysql -u "${DB_USER:-scriptshare_user}" -p"${DB_PASSWORD:-ScriptShare_App_2024_Secure!}" "${DB_NAME:-scriptshare}" + ;; + + help|--help|-h) + show_help + ;; + + *) + echo "❌ Unknown command: $1" + echo "" + show_help + exit 1 + ;; +esac