Compare commits
2 Commits
a40a2c022d
...
68a02d1e5f
Author | SHA1 | Date | |
---|---|---|---|
68a02d1e5f | |||
7c45a3b1d9 |
365
DOCKER_DEPLOYMENT.md
Normal file
365
DOCKER_DEPLOYMENT.md
Normal file
@ -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 <your-repo-url>
|
||||
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! 🚀**
|
180
README_DEPLOYMENT.md
Normal file
180
README_DEPLOYMENT.md
Normal file
@ -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.
|
156
docker-compose.prod.yml
Normal file
156
docker-compose.prod.yml
Normal file
@ -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
|
52
env.production
Normal file
52
env.production
Normal file
@ -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
|
129
nginx/conf.d/scriptshare.conf
Normal file
129
nginx/conf.d/scriptshare.conf
Normal file
@ -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;
|
||||
# }
|
47
nginx/nginx.conf
Normal file
47
nginx/nginx.conf
Normal file
@ -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;
|
||||
}
|
53
scripts/backup.sh
Normal file
53
scripts/backup.sh
Normal file
@ -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!"
|
92
scripts/deploy.sh
Normal file
92
scripts/deploy.sh
Normal file
@ -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"
|
47
scripts/init-db.sql
Normal file
47
scripts/init-db.sql
Normal file
@ -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;
|
142
scripts/manage.ps1
Normal file
142
scripts/manage.ps1
Normal file
@ -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
|
||||
}
|
||||
}
|
130
scripts/manage.sh
Normal file
130
scripts/manage.sh
Normal file
@ -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 <backup-file>"
|
||||
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
|
Reference in New Issue
Block a user